Question

Language C++Instructions Develop a CPP program to test is an array conforms heap ordered binary tree. This program read data from cin (co

0 0
Add a comment Improve this question Transcribed image text
Answer #1


#include <iostream>

using namespace std;

int main()
{
int a[7],i=0;
while(i<7){//repeat for all the 7 numbers(max size of array)
cout<<"Enter a number: ";
cin>>a[i];//read number
if(i==0){
i++;
continue;
}
else if(i==1 or i==2){
if(a[i]<a[0]){//check if it is less than the root
i++;
continue;
}
cout<<a[i]<<" violated the heap. Bye..";break;
}
else if(i==3 or i==4){
if(a[i]<a[1]){//check if it is less than the parent
i++;
continue;}
cout<<a[i]<<" violated the heap. Bye..";break;
}
else if(i==5 or i==6){
if(a[i]<a[2]){//check if it is less than the parent
if(i==6){
cout<<"All good. Bye";
break;
}
i++;
continue;}
cout<<a[i]<<" violated the heap. Bye..";break;
}
else{
cout<<a[i]<<" violated the heap. Bye..";
break;
}
}

return 0;
}

Screenshots:

The screenshots are attached below for reference,

Please follow them for output.

Please upvote my answer .

Thank you.

Enter a number: 100 Enter a number: 95 Enter a number: 76 Enter a number: 58 Enter a number: 66 Enter a number: 58 Enter a nu

Enter a number: -15 Enter a number: -5 -5 violated the heap. Bye.. . Program finished with exit code 0 Press ENTER to exit co

Add a comment
Know the answer?
Add Answer to:
Language C++ Instructions Develop a CPP program to test is an array conforms heap ordered binary...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Instructions Develop a CPP program to test is an array conforms heap ordered binary tree. This...

    Instructions Develop a CPP program to test is an array conforms heap ordered binary tree. This program 7 numbers. Example runs and comments (after // ) are below. Your program does not prin Exp-1: Enter a number: 65 // this is first item (root, [1]) in the heap three. it does not violate a Enter a number: 56 // this is third (3) number, should be less than or equal to its root ([1 Enter a number: 45 // this...

  • C++ Programming By using Binary heap Develop a CPP program to test is an array conforms...

    C++ Programming By using Binary heap 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 // this is...

  • Write a Java program, In this project, you are going to build a max-heap using array...

    Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...

  • The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random...

    The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be...

  • Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D...

    Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

  • c++ O fe/C/Users/Younis/App ft.Microsoftedgc b17%20(1)pdf 1 of 1 CSC 2000 C+t Programming Language Winter Term 2019...

    c++ O fe/C/Users/Younis/App ft.Microsoftedgc b17%20(1)pdf 1 of 1 CSC 2000 C+t Programming Language Winter Term 2019 Lab 17 10 points Due in Lab Write a C++program that inputs 15 real numbers into a three by five two- dimensional array; also write a function that determines the total number of values in these ranges: less than 60, greater than or equal to 60 and less than 70, greater than or equal to 70 and less than 80, greater than or equal...

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • The task involves writing a C++ program that determines the prime numbers between 1 and 100....

    The task involves writing a C++ program that determines the prime numbers between 1 and 100. The steps you should follow to identify the prime numbers are the following. 1. The number 1 is not a prime number, so it should be scratched. 2. Starting from the first prime number, which is 2, you scratch all the numbers that are the multiple of 2. You should not scratch out 2 itself. 3. The next number in the sequence after the...

  • (IN C LANGUAGE) 4.33 (Roman-Numeral Equivalent of Decimal Values) Write a program that prints a table...

    (IN C LANGUAGE) 4.33 (Roman-Numeral Equivalent of Decimal Values) Write a program that prints a table of all the Roman-numeral equivalents of the decimal numbers in the range 1 to 100. Decimal→→Roman↵ -------→→-----↵ 1→→I↵ 2→→II↵ 3→→III↵ 4→→IV↵ 5→→V↵ 6→→VI↵ 7→→VII↵ 8→→VIII↵ 9→→IX↵ 10→→X↵ 11→→XI↵ 12→→XII↵ 13→→XIII↵ 14→→XIV↵ 15→→XV↵ 16→→XVI↵ 17→→XVII↵ 18→→XVIII↵ 19→→XIX↵ 20→→XX↵ 21→→XXI↵ 22→→XXII↵ 23→→XXIII↵ 24→→XXIV↵ 25→→XXV↵ 26→→XXVI↵ 27→→XXVII↵ 28→→XXVIII↵ 29→→XXIX↵ 30→→XXX↵ 31→→XXXI↵ 32→→XXXII↵ 33→→XXXIII↵ 34→→XXXIV↵ 35→→XXXV↵ 36→→XXXVI↵ 37→→XXXVII↵ 38→→XXXVIII↵ 39→→XXXIX↵ 40→→XL↵ 41→→XLI↵ 42→→XLII↵ 43→→XLIII↵ 44→→XLIV↵ 45→→XLV↵ 46→→XLVI↵ 47→→XLVII↵...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT