a. Describe the concept of a Binary heap and the heap order property. [10 marks]
b. Explain the use of the binary heap as an effective implementation for a priority queue [10 MARKS]
Simulate the fragment of codes below and trace the output.
int *p1, *p2;
p1 = new int;
p2 = new int;
*p1 = 10;
*p2 = 20;
cout << *p1 << “ ” << *p2 << endl;
p1 = p2;
cout << *p1 << “ ” << *p2 << endl;
*p2 = 30;
cout << *p1 << “ ” << *p2 << endl;
Write a program that will prompt the user to input the following:
1. The number of dice to be rolled.
2. How many times the dice should be rolled?
Since the values above will vary, you must use pointer arrays and dynamically allocate memory.
The program will store the total of faces per roll and the values will be later used to plot a graph. The graph should look like the output shown below
3:
4:
5:
6:
7:
8: *
9:
10:
11:
12: *
13:
14:
15:
16:
17:
18:
The asterisk (*) tallies the number of times that total has occurred. 3 and 18 are the minimum and maximum totals, respectively, for rolling 3 dice.
The declaration and implementation sections of the class have been defined for you. Use it to complete your program.
4. Negative Fusion
As I've said before, there are three types of numbers; the positive, the zero, and the negative ones. Today, we shall pay attention only to the negative ones now. Make a loop that will accept random decimal/float numbers. When the user inputs 0, the loop will terminate and then output the sum of all negative numbers inputted in 3 decimal places.
Let's code this.
Input
Multiple lines containing a decimal.
2. 4434
-1.3433
-2.444
6.432
Output
A line containing a decimal with three decimal places.
-3.787
3. The Last 'Zeroes'
How many zeroes are there after the last non-zero digit of a million? A trillion? To easily identify that, let us make a program to count and print the number of zeroes after the last non-zero digit on a number. For example, in 20400, there are 2 zeroes after the last non-zero digit of the number, 4.
Are you up for this challenge?
Input
A line containing an integer.
20400
Output
A line containing an integer.
2
2. Phonics
Did you know that the first letters in the alphabet that a child learns are the vowels? Well, since they're the first letters that we learned as babies, then they must be easy to identify, right? So, let's make a code that will identify all vowels in a string and print out how many they are!
Let's go!
Input
A line containing a string.
CodeChum
Output
A line containing an integer.
3
1. FizzBuzz 2.0
Remember the game of FizzBuzz from the last time? Well, I thought of some changes in the game, and also with the help of loops as well. Firstly, you'll be asking for a random integer and then loop from 1 until that integer. Then, implement these conditions in the game:
• print "Fizz" if the number is divisible by 3.
• print "Buzz" if the number is divisible by 5.
• print "FizzBuzz" if the number is divisible by both 3 and 5.
• print the number itself if none of the above conditions are met.
Input
A line containing an integer.
15
Output
Multiple lines containing a string or an integer.
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
Wap to create One Base class Father data member fname. And Son class derived from Father dada member sname . And GrandSon derived from Son data member gname. Use appropriate function that GrandSon will display all name by it concatenating