Answered step by step
Verified Expert Solution
Question
1 Approved Answer
do this in c++ please thank you This lab includes 14 points in aggregate. The details are given in the following. 1 City and CoastalCity
do this in c++ please thank you
This lab includes 14 points in aggregate. The details are given in the following. 1 City and CoastalCity Include city.h and coastalcity.h header files from the previous lab in main.cpp. The main function does the following step by step: 1. Create two pointers to city objects and nullify them (I points). 2. Create two pointers to Coastalcity objects and nullify them (I points). 3. Create a vector of pointers to City objects (I points). 4. Initialize the first pointer to City object (using new), set the name to Denver, and the population to 750000 (1 points) 5. Initialize the second pointer to City object (using new), set the name to Reno, and the population to 250000 (1 points) 6. Initialize the first pointer to Coastalcity object (using new), set the name to San Diego, the population to 250000, the water name to Pacific Ocean, and number of beaches to 5 (2 points) 7. Initialize the second pointer to Coastalcity object (using new), set the name to Miami, the population to 500000, the water name to Atlantic Ocean, and number of beaches to 8 (2 points) 8. Add all four City and Coastalcity pointers to the already created vector (Step 3) (1 points) 9. Within a loop traverse the vector and print each city's information (by calling print Info()) (2 points). Compile and run. Since the vector is statically defined as the vector of pointers to City objects, due to compile time polymorphism, printInfo() in the base class (City) is invoked for both City and Coastalcity object pointers. The output of the program may look like the following: Name: Denver Population: 750000 Name: Reno Population: 250000 Name: San Diego Population: 1500000 Name: Miami Population: 500000 10. Change city.h in a way that runtime polymorphism is enforced when printInfo() function is invoked. That is, for pointers of city objects City's printInfo() is called, whereas for pointers of Coastalcity objects Coastalcity's print Info() is called (2 points). The output of the program may look like the following: Name: Denver Population: 750000 Name: Reno Population: 250000 Name: San Diego Population: 1500000 Water: Pacific Ocean No. of Beaches: 5 Name: Miami Population: 500000 Water: Atlantic Ocean No. of Beaches: 8 Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started