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
Free points if you name undertale character start with T
wlad13 [49]

Answer:

Toriel.

Explanation:

3 0
3 years ago
Read 2 more answers
What to do when you accidentally delete usb drivers?
amid [387]
Step 1

Save your work and close all programs. You will be restarting your computer during the process.

Step 2

Click “Start” from the task bar and then choose “All Programs.”

Step 3

Click “Accessories” from the program menu. Choose “System Tools” from the side pop-out menu and then select “System Restore.”

Step 4

Click “Restore my computer to an earlier time” from the Welcome screen. Click “Next” at the bottom.

Step 5

Choose a date in bold from the calendar shown on the Restore Point page. The date that you choose should be an earlier one, like a day or two before the deletion occurred. Click “Next” at the bottom of the window.

Step 6

Click “Next” on the next page. The restoration begins, and your computer will restart.

Step 7

Click “OK” from the completion window that appears when your computer loads again.

3 0
3 years ago
Is virtualization self monitoring
NISA [10]

Answer:

No

Explanation:

Virtual and physical metrics have to be collected and analysed to look for allocation problems such as: VM sprawl, too many VMs, or improperly provisioned VMs are occurring.

4 0
3 years ago
The core of ___________ is the implementation of intrusion detection systems and intrusion prevention systems at entry points to
cestrela7 [59]

Answer:

sorry I can't understand what is this is

3 0
2 years ago
3) According to the five-component model of information systems, the ________ component functions as instructions for the people
Ludmilka [50]

Answer:HUMAN RESOURCES AND PROCEDURE COMPONENTS

Explanation: Information systems are known to contain five components, these components help to describe the various aspects and importance of Information systems.

They Include The DATABASE AND DATA WAREHOUSE components(act as the store for all data), The COMPUTER HARDWARE(the physical components of the information systems such as computer harddrive etc)

THE COMPUTER SOFTWARE( the software which includes all the non physical and intangible assets of the information system),

THE HUMAN RESOURCES AND PROCEDURES COMPONENT( which gives instructions to the users).

THE TELECOMMUNICATIONS.

7 0
3 years ago
Other questions:
  • Mass production usually uses an _______________ ____________ or production line technique.
    7·1 answer
  • Sometimes we write similar letters to different people. For example, you might write to your parents to tell them about your cla
    9·1 answer
  • [Java] Using the comparable interface
    13·1 answer
  • Define an I/O port. Which functions are performed by it?
    10·1 answer
  • Complete the following statement: Sustainability is: Choose all that apply.This task contains the radio buttons and checkboxes f
    10·1 answer
  • When a visitor clicks the submit button on a form, the ______ of each form element is sent?
    12·2 answers
  • Percentage-wise, which renewable energy source is used most?
    13·1 answer
  • How do i use a computer (i'm 99999 years old)
    8·2 answers
  • Identify the characteristics of logic problems. Select all that apply.
    11·2 answers
  • Hey! I was recommended a site “9anime” the other day. All’s been going well but I accidentally taped on a new dub settingZ somet
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!