Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

im in an introductory programming class (C++) and i have to create a class called country, a procedure to print this class and a most

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

im in an introductory programming class (C++) and i have to create a class called country, a procedure to print this class and a most dense function which inputs a vector of countries. i was given the main body and instructed not to change anything in it, all the code above it is what i have already typed out. the other stuff i need for this program is stated above. if someone could help me finish this program that would be greatly appreciated. i dont believe i have made any errors in what i have wrote but i possibly could have. im aware this is not a small problem so any help with be granted a thumbs up. it also really helps me when there are comments on the code to explain what is happening, this way i learn for the future. have a great day thanks :)

also none of the functions should cout anything unless stated.

The Country class: ountry.cpp 1. The Country class (note the capital C) three member variables, area (use a double), population (use either an int or an unsigned int) and name (use a string). All member variables should be in the private portion of the class definition. In this problem, will not make the member variable constant. (After all, the populations of countries changes over time.) 2. The class should have one constructor function which inputs three pa- rameters (the population, area, and name). The constructor should use an initializer list as shown in class. It should also use assert to ensure that both population and area are strictly positive. (Zero should cause an error. Don't forget to include cassert.) 3. It should also have three accessor functions called get_area, get name, and get_population which return the area, the name, and the population. Make sure to include const here. For these functions you do not need to use function declarations (i.e. you can write them inside the class, and don't need to write them below the main). 4. It should have three mutator functions, add pop, multiply-pop and change_name. These functions should all do what their name suggests. For example, if the population was 1,000,000 and you call c.add_pop(5) the population should change to 1,000,005, but if you call c.multiply-pop(5) it should change to 5.000.000. For these three functions, you must use function declarations. (See the Rectangle6 example from class.) For add pop, your input should be an int, for multiply-pop it should be a double, and for change name, it should be a string. The print procedure: This procedure should print a Country. In particular, it should cout something in the format shown below: Japan has population 1.234,567 and area 3,234. (Those numbers are made up.) You should decide whether to use pass by value, pass by reference, or pass by reference to a const and must make the appropriate choice in order to get full credit. Ti The most dense function: 1. This function should have one parameter named countries, which is a vector of Countrys (i.e. it is a vector, and every entry of the vector is a Country). 2. It should return the Country with the highest population density. (popu- lation divided by area). 2 3. For this function, you don't have to worry about strange or invalid input. You can assume that countries is a vector of Countrys; that there is at least one country in the vector, and that none of the areas are zero. 4. You don't have to worry about the possibility that there is a tie, i.e. that two different countries have exactly the same density. 5. You should decide whether to use pass by value, pass by reference, or pass by reference to a const and must make the appropriate choice in order to get full credit. (Global Scope) 1 2 #include using namespace std; #include #include #include 4 5 6 7. 8 class Country { public: Country(const double my_area, const int my_population, const string my_name): area (my_area), population(my_population), name(my_name) { assert(my_area >= 0); assert(my_population >= 0); 9 10 11 12 13 14 15 16 17 18 19 double get_area() const; int get population const; string get_name() const; 123456789wangw8894 private: double area; int population; string name; }; 21 22 23 24 25 26 Edouble Country::get area() const { return ares; Bint Country::get population() const { return population; 28 . Elstring Country::get name() const { return; 30 31 32 33 34 35 36 37 38 39 40 41 Country rost danse (Verile here) //your code goes here Izvoid print(variable here) { //your code goes here 43 Fint main() { 45 46 47 48 49 1/Create countries, store in vector Country (100, 10, "JAPAN"); Country u(1000, 1000, "USA"); vector list; list.push_back()); list.push_back(u); 50 1/test most_dense_country function Country most_dense_country = most_dense(list); print(most_dense_country); 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 //test add_pop and get_population cout

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

Step: 3

blur-text-image

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions