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
If you have cable internet service, what protocol is used between the head end connection and the cable company's network
julsineya [31]
The answer would be (DOCSIS). :)

Have a blessed day and hope this helps!
7 0
3 years ago
When making an assembly of design what command is most.commonly used?
Schach [20]
There are two common command lines used in creating design assembly. The 'push' and 'pull' command. Both allows you to get parts from the original predelivered content's source desgian    and recreate the design faster and with less memory.
6 0
2 years ago
How is abstraction used in a GPS system
ipn [44]
The designs on the map of the GPS system Im would think but can you be more specific?
8 0
3 years ago
Read 2 more answers
_______________creates new markets separate to the mainstream; markets that are unknowable at the time of the technology's conce
elena-s [515]

Answer: a)Disruptive innovation

Explanation: Disruptive innovation is the innovation technique indulges in market through new market strategy and value network. This techniques damages the existing market market and its values .The displacement of the current product extincts from the market through this technique.

Other options are incorrect because paradigm shift is influence losing in the market and sustaining innovation is used for the improving the product's marketing and value .Thus, the correct option is option(a).

3 0
3 years ago
What is the process for creating a new merge document for address labels?
Archy [21]

Answer:

In Word, click Mailings > Start Mail Merge > Step-by-Step Mail Merge Wizard to start the mail merge wizard. Choose Labels, and then click Next: Starting document. Choose Label options, select your label vendor and product number, and then click OK. Click Next: Select recipients.

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • In the U.S. highway numbering system, north-south routes have
    9·2 answers
  • You are trying to appreciate how important the principle of locality is in justifying the use of a cache memory, so you experime
    11·1 answer
  • Illustrate the process of using an operating system to manipulate a computer’s desktop, files and disks.
    12·1 answer
  • Which type of graph or chart measures
    15·2 answers
  • How to format the selected range of cells as u.s currency
    6·1 answer
  • Match each proofreading mark to the expected result.
    10·1 answer
  • Estoy haciendo codificación en este momento es tan confuso y no estar en la escuela es más difícil
    11·2 answers
  • State 4 basic operation performed by a computer​
    11·2 answers
  • 100 POINTSSSSSSS!!
    5·1 answer
  • In disc brakes, pads are forced against the of a brake disc​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!