Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

please do this in c++ thank you city.h from previous lab #ifndef CITY_H #define CITY_H #include #include using namespace std; //City class defnition class City

please do this in c++ thank you

image text in transcribed

image text in transcribed

city.h from previous lab

#ifndef CITY_H

#define CITY_H

#include

#include

using namespace std;

//City class defnition

class City

{

public:

//setter metod for name

void setName(string name)

{

this->name=name;

}

//setter metod for population

void setPopulation(int population)

{

this->population=population;

}

//getter metod for name

string getName() const

{

return this->name;

}

//getter metod for population

unsigned int getPopulation() const

{

return this->population;

}

//printInfo() method to print data members

void printInfo() const

{

cout

cout

}

//making data members protected so that subclasses can access

protected:

//data members declaration

string name;

unsigned int population;

};

#endif

coastalcity.h from previous lab

#ifndef COASTALCITY_H

#define COASTALCITY_H

#include "city.h"

#include

#include

using namespace std;

//CoastalCity class class defnition //CoatalCity class inherits City class CoastalCity:public City

class CoastalCity : public City

{

private:

//data members declaration

string waterName;

unsigned int beachNum;

public:

//default constructor defnition

CoastalCity()

{

//assigning default values

name="N/A";

population=0;

waterName="N/A";

beachNum=0;

}

//setter metod for waterName

void setWaterName(string waterName)

{

this->waterName=waterName;

}

//setter metod for beachNum

void setBeachNum(int beachNum)

{

this->beachNum=beachNum;

}

//getter metod for waterName

string getWaterName() const

{

return this->waterName;

}

//getter metod for beachNum

unsigned int getBeachNum() const

{

return this->beachNum;

}

//printInfo() method to print data members

void printInfo() const

{

//calling printInfo() methode of the base class City::printInfo();

cout

cout

}

};

#endif

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

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students explore these related Databases questions