Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++, object oriented program that allows the input of 15 animals names a

ID: 3583361 • Letter: W

Question

Write a C++, object oriented program that allows the input of 15 animals names and their corresponding ages. The data should be stored in a max heap, arranged according to their age. The program should then, once the input is complete, create a second heap from the newly created age heap structure using a preorder tree traversal (do not use the original data to do this). This second new max heap should be arranged alphabetically by the animal's name. At this point in the programs execution, both the age heap and name heap should be printed using a breath first search. Finally, once both heaps are complete, a sixth entry, whose age is greater than any previous age (the animals name is your choice), is input, causing both heaps to be heapified. You do not have to be concerned with any deletion from the heaps. Once again output both of the heaps using a breath first search.

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <string>    // needed to use the string class
using namespace std;

int main() {
   string msg1("hello");
   string msg2("HELLO");
   string msg3("hello");

   // Relational Operators (comparing the contents)
   cout << boolalpha;
   cout << (msg1 == msg2) << endl; // false
   cout << (msg1 == msg3) << endl; // true
   cout << (msg1 < msg2) << endl; // false (uppercases before lowercases)

   // Assignment
   string msg4 = msg1;
   cout << msg4 << endl; // hello

   // Concatenation
   cout << (msg1 + " " + msg2) << endl; // hello HELLO
   msg3 += msg2;
   cout << msg3 << endl; // helloHELLO

   // Indexing
   cout << msg1[1] << endl;     // 'e'
   cout << msg1[99] << endl;    // garbage (no index-bound check)
// cout << msg1.at(99) << endl; // out_of_range exception
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote