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...

  • Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array....

    Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...

  • 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...

  • %%%%% c++ assignment %%%%%% ///////// please test your program and check for errors. //////// you should...

    %%%%% c++ assignment %%%%%% ///////// please test your program and check for errors. //////// you should use the file bellow For this assignment you will write a program that creates a tree of "plants". Each plant is the result of an exeperiment. I have provided the main driver program that is responsible for running each of the experiments but you will need to create a tree for storing the results. The objective of this assignment is to learn how to...

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