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

Make a class called PopInfo that has private member variables: the current popul

ID: 3533899 • Letter: M

Question

Make a class called PopInfo that has private member variables: the current population (a long), the annual number of births (an int), the annual number of deaths (an int) and the city name (a string). The class needs at least one constructor; mutator functions, setPopulation(), setBirths(), setDeaths() and setCity(); and accessor functions, getPoPulation(), getBirths, getDeaths() and getCity(). Two additional member functions are getBirthrate() and getDeathrate() which return the birth and death rates (float or double values) calculated by the formulas given below.

birth rate = (number of births)/population_size

death rate = (number of deaths)/population_size

Data validation should be done in the class functions to ensure that population values are not less than 1 and that birth or death values are not less than 0.

The main() function should declare a PopInfo object in a way consistent with your constructor. The data for the object population, number of births, number of deaths, and city name should be read in from standard input. The values will be assigned to the object using the class mutator functions. Then the program should write out the city information, the birth rate and the death rate for each object using the accessor functions, the getBirthrate() and the getDeathrate() functions.

I want a complete program please!

Explanation / Answer

#include #include using namespace std; class popInfo { private: long population_size; int number_of_births; int number_of_deaths; std::string city_name; public: popInfo() { population_size = 0; number_of_births = 0; number_of_deaths = 0; city_name.clear(); } void setPopulation(long size) { population_size = size; } void setBirths(int births) { number_of_births = births; } void setDeaths(int deaths) { number_of_deaths = deaths; } void setCity(std::string name) { city_name = name; } long getPopulation() { return population_size; } int getBirths() { return number_of_births; } int getDeaths() { return number_of_deaths; } std::string getCity() { return city_name; } float getBirthrate() { if(population_size>0) return (1.0*number_of_births/population_size); else return -1; } float getDeathrate() { if(population_size>0) return (1.0*number_of_deaths/population_size); else return -1; } }; int main() { popInfo city; city.setCity("New York"); city.setBirths(1000); city.setDeaths(500); city.setPopulation(100000); cout
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