1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mkey [24]
3 years ago
9

Develop a CPP program to test is an array conforms heap ordered binary tree. This program read data from cin (console) and gives

an error if the last item entered violates the heap condition. Use will enter at most 7 numbers. Example runs and comments (after // ) are below. Your program does not print any comments. An output similar to Exp-3 and Exp-4 is expected.
Exp-1:
Enter a number: 65
Enter a number: 56 // this is first item (root,[1]) in the heap three. it does not violate any other item. So, no // this is third [3] number, should be less than or equal to its root ([1])
Enter a number: 45 // this is fourth number, should be less than or equal to its root ([2])
Enter a number: 61 // this is fifth number, should be less than or equal to its root ([2]). It is not, 61 > 55. The 61 violated the heap.
Exp-2:
Enter a number: 100
Enter a number: 95 1/ 95 < 100, OK
Enter a number: 76 // 76 < 100, OK
Enter a number: 58 // 58 < 95, OK
Enter a number: 66 1/ 66 < 95, OK
Enter a number: 58 // 58 < 76, OK
Enter a number: 66 // 66 < 76, OK
Exp-3:
Enter a number: -15
Enter a number: -5
-5 violated the heap.
Exp-4:
Enter a number: 45
Enter a number: 0
Enter a number: 55
55 violated the heap.
Computers and Technology
1 answer:
mafiozo [28]3 years ago
5 0

Answer:

Following are the code to this question:

#include<iostream>//import header file

using namespace std;

int main()//defining main method

{

int ar[7];//defining 1_D array that stores value      

int i,x=0,l1=1,j; //defining integer variable

for(i=0;i<7;i++)//defining for loop for input value from user ends  

{

cout<<"Enter a Number: ";//print message

cin>>ar[i];//input value in array

if(l1<=2 && i>0)//using if block that checks the array values  

{

x++;//increment the value of x by 1  

}

if(l1>2 && i>0)//using if block that checks the array values  

{

l1=l1-2;//using l1 variable that decrases the l1 value by 2  

}

j=i-x;//using j variable that holds the index of the root of the subtree

if(i>0 && ar[j]>ar[i])// use if block that checks heap condition  

{

l1++; //increment the value of l1 variable

}

if(i>0 && ar[j]<ar[i])// using the if block that violate the heap rule  

{

cout<<ar[i]<<" "<<"Violate the heap";//print message with value

break;//using break keyword  

}

}

return 0;

}

Output:

1)

Enter a Number: -15

Enter a Number: -5

-5 Violate the heap

2)

Enter a Number: 45

Enter a Number: 0

Enter a Number: 55

55 Violate the heap

Explanation:

  • In the above-given C++ language code, an array "ar" and other integer variables " i,x,l1, j" is declared, in which "i" variable used in the loop for input values from the user end.
  • In this loop two, if block is defined, that checks the array values and in the first, if the block it will increment the value of x, and in the second if the block, it will decrease the l1 value by 2.
  • In the next step, j variable is used that is the index of the root of the subtree. In the next step, another if block is used, that checks heap condition, that increment the value of l1 variable. In the, if block it violate the heap rule and print its values.
You might be interested in
You are reluctant to write an extra credit book report because you are afraid that your language and punctuation skills are not
saveliy_v [14]

Answer

Spelling and Grammar checkers

Explanation

A word processor is a  software program  for editing, storing, manipulating, and formatting text entered from a keyboard for the purpose  providing the intended output. t allows users to create, edit, and print documents. It enables you to write text, store it electronically, display it on a screen,

Spelling and Grammar checkers are the inbuilt components of word processors programs for personal computers. They have Salient features that  helps in identifying grammatical errors and misspellings.


3 0
3 years ago
With the ease of the Internet, it is not uncommon for individuals to copy skills from resume templates to make themselves look m
Butoxors [25]

Answer:

Content.

Explanation:

With the convenience of the Web, copying skills of resumes models is not unusual among people that create themselves seem quite appealing to such a recruiter. Understanding this, Ed developed a check to examine whether that person's job skills are about what's on the form.  

He is checking the validity of the content because It relates to that of the extent that the products on such a survey seem to be extremely determinative of the whole domain to be measured by the study.

7 0
3 years ago
Which source would provide the best way to find valid information about climate change
igor_vitrenko [27]
Primary sources would be best
4 0
2 years ago
Over the past year alone, more than _________ have been stolen from Target.
jasenka [17]
40 million (google said so)
6 0
3 years ago
Read 2 more answers
Explain how the number of jobs available to workers has been affected by the use of ICT in commerce and industry, using specific
blondinia [14]

Answer:

The main cause of lack of jobs is due to automation and the ability for computers to do everything faster, more efficiently and effectively.

Explanation:

A specific example - Data entry jobs are redundant from automation programs

- Economic Forum predicted a net increase of 58 million jobs for automation, so this accounts for losses but isn't case specific to data entry

6 0
2 years ago
Other questions:
  • What do you click to create a new presentation in Normal view
    14·1 answer
  • What provides quality education for students
    14·1 answer
  • What are some of the causes for error 1921 when updating?
    11·2 answers
  • Which is slower RAM or the CPU?
    11·2 answers
  • Alison retrieved data from a company database containing personal information on customers. When she looks at the SSN field, she
    14·1 answer
  • Dang was accepted to a biology program with a rigorous schedule and a high tuition, but good professors. What would be a benefit
    10·2 answers
  • Which is an aspect of structural-level design?
    6·2 answers
  • The image below shows an encoding for a black and white pixel image. The first two
    13·1 answer
  • A statement that starts with a # symbol is called
    8·1 answer
  • 1) Coding for Table in Html<br>​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!