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
Which type of communication protocol converts data into standard formats that can be used by applications?
larisa86 [58]
<span>Arrival protocols are the type of data protocols that convert data into standard formats that can be used by applications, such as email, Web browsers and Skype</span>
8 0
3 years ago
____ is a philosophy and a software and system development methodology that focuses on the development, use, and reuse of small,
LiRa [457]

Answer:

d.) Service-Oriented Architecture

Explanation:

Because its definition matches

4 0
3 years ago
Explain online issue management​
Over [174]

Answer:

Online issue tracking system is a computer software solution for managing issues lists. The lists of issues are defined by the organization activity field.The best example of online issue tracking software is a customer support call center. ... A Bug Tracker is also one of possible online issue tracking software

Explanation:

the answer has the explanation needed.

7 0
2 years ago
Many documents use a specific format for a person's name. Write a program whose input is: firstName middleName lastName, and who
never [62]

Answer:

Python Program:

if __name__ == '__main__':

   a = input("Enter Name: ")

   b = a.split()

   print(b[2] + ',' , b[0], b[1][0])

Explanation:

The input function will be used to prompt user to enter the name of the person. The person's name will be stored in variable a.

Let us assume that the user entered a name mentioned in the example, which is Pat Silly Doe, Now variable a = 'Pat Silly Doe'.

The function a.split() is used to split a string into a list. The splitting (by default) is done on the basis of white-space character. Therefore, a.split() will give a list

['Pat', 'Silly', 'Doe']

which will be later on stored in variable b.

We can use the subscript operator [] to access the values in a list. Suppose if we have a list a, then a[i] will give us ith element of a, if i < length of a.

Finally, we print the answer. b[2] will give us the last name of the person. We append a comma using '+' operator. b[0] will give us the first name. b[1] will give us the middle name, but since we only need one character from the middle name, we can use another subscript operator b[1][0] to give us the first character  of the middle name.

Note: Characters of strings can be accessed using subscript operator too.

4 0
3 years ago
Write a statement that declares a prototype for a function printArray, which has two parameters. The first parameter is an array
slamgirl [31]

Answer:

The prototype for the function is written below:-

void printArray(int [],int);

Explanation:

The prototype of the function is written above.Since the function does not return a value so it has to be of type void.Then following is the name of the function.Following that the arguments in the parenthesis.We need not to provide the name of the arguments we just have to define it's type.So for the array we have to just write int [] and for integer variable just int.

8 0
3 years ago
Other questions:
  • What is the importance of using the proper markup language?
    8·2 answers
  • Which magazine can help public determine best technology to buy
    12·1 answer
  • Software that manages and supports the resources of a computer is known as?
    10·1 answer
  • How does this app work?
    11·2 answers
  • If you are logged on to Windows Live Messenger, why would you be unable to engage
    6·1 answer
  • How are IP addresses usually written?
    7·1 answer
  • What are Important points to include about preventing the download of malware?
    14·1 answer
  • Grab the stniop or they will dissapear
    12·1 answer
  • A student can improve performance by decreasing
    14·1 answer
  • How to enhance the video to full screen in filmora
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!