Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I was having trouble with this program which is part of an assignment question done in C++. If you could help me that would

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

Hi, I was having trouble with this program which is part of an assignment question done in C++. If you could help me that would be really great. Thank you so much!!!!

Part 2 Country Catalogue This class will be the tricky one. This class will keep track of all the countries we have. We will then use this class to manipulate our collection of countries, get information from them, etc ntinent - a dictionary/map (same thing) to hold pairs of countries and continents. The class attributes will be catalogue - an array of countries, or more accurately, a pointer to a dynamic array of pointers to countries. . _maxSize - how big our array called catalogue is currently curSize -how many things are currently in our array called_catalogue * _countryCo o Map? Read these carefully: - http://www.cplusplus.com/reference/map/map/ - https://thispointer.com/stdmap-tutorial-part-1-usage-detail-with- examples,/ - https://stackoverflow.com/questions/26281979/c-loop-through-map The methods this class will have are described below .A default constructor that will just set maxSize to 10, curSize to 0 (nothing in our catalogue yet), and make a dynamic array of size_ maxSize. I provided this for you. .A constructor that will setup our catalogue of countries based on some text files. This constructor will be fairly complex and you may find it to be one of the more challenging parts of this assignment. I have included some comments to help guide what to do. This constructor will receive two strings as parameters that correspond to the names of files that contain the information the class needs to setup the catalogue. Your program must work in general with any possible files, but the ones we'll be using to test your code are provide and are named country cpp.txt and continent cpp.txt. Based on the contents of the continent file, the constructor will populate the o o countryContinent map with country (key) continent (value) pairs. Map? If your memory is that bad, read these carefully again: //thi examples/ st detail stackoverflow.com/questio rou o Based on the contents of the country file, the constructor will populate the_catalogue. You will need to use the countryContinent here to get each country's continent. I also recommend making use of the addCountry method described below that you will implement to easily add the countries to the catalogue The format of the files is this (slight change here from A4 in 161): o Continent: Line 1 contains the country name, then that county's continent on line 2. Then line 3 is a new country name, and line 4 is it's continent, etc Country: Line 1 contains a country name, followed by its population, followed by the area, then line 4 is a new country name, then population, then area, etc. o File I/O? oria .Get reading! -One thing to take special note of is the .eof function. You might find that handy depending on how you want to code it. Also, be sure to close your files! - .We'll not making a copy constructor here. This is probably a bad move long term, but to simplify things a little, we'll skip it for Al .A deconstructor that will delete the contents of the catalogue, and then delete the catalogue itself. Remember, catalogue is a pointer to a group of pointers. We have to delete the inside pointers, then delete the array that held the pointers that is being pointed to by_catalogue. .A private method called expandCapacity that will just make a new array that's bigger if we run out of space in our_catalogue. As a rule, we will always double the size every time. Watch out for memory 1 leaks! addCountry is a method that will take all the information needed to make a country (name, pop, area, continent) as a parameter, make the object, and add it to the catalogue. If we run out of room in our array we might have to expand the capacity (see above). Whenever we add it, we must be sure to increment the counter keeping track of the number of things in our . .RemoveCountry will take a name of a country as a parameter and delete the country with the matching name from the catalogue. If it does not exist, then the method will ultimately have no impact. Watch out for memory leaks and be sure to update the catalogue correctly findCountry will take a country name and return a pointer to the country with the matching name in the catalogue (assuming it exists). If it does not exist, retum nullptr. numCountriesInContinent will take a continent name, and then return how many countries from that continent. .filterCountriesByContinent will take a continent name and the number of countries that exist on that continent and return a pointer to an array containing pointers to the countries on the continent. This one might be a little tricky, but it shouldn't be too bad. Just make a pointer to an array of pointers to countries of the proper size, then add the countries on the continent to the array. Return the pointer to the array in the end. If none exist, return nullptr printCountryCatalogue will just print out the contents of the catalogue. This one should be simple. Print out"name in continent" for each country on a new line. To do this, just have a loop go over the_catalogue and call each country's to string) method and print it out. . setPopulationOfSelectedCountry will take a country name and a new population and then update the corresponding country in the catalogue's population (assuming it exists). . .findCountry WithLargestPop will return a pointer to the country with the largest population within our catalogue. If nothing is in the catalogue, return nullptr. findCountry WithSmallestAreawill return a pointer to the country with the smallest population within out catalogue. If nothing is in the catalogue, return nullptr. findMostPopulousContinent will return the name of the continent with the largest population based on the countries within the catalogue. This one will be a little tricky. saveCountryCatalogue will take the name of a file to create and write to which will save some details about the contents of our catalogue. The function will return the number of lines written to the file. Format the output as follows o NAME CONTINENTIPOPULATION POPULATION DENSITY o China Asia 1339190000 139.5431469965489 Do not be surprised if your output formats the numbers funny. This is fine. See my includecd example output file named saved al_example.txt. o File I/O? o In case you forgot again. http://www.cplusplus.comdoc/tutorial/files! Part 2 Country Catalogue This class will be the tricky one. This class will keep track of all the countries we have. We will then use this class to manipulate our collection of countries, get information from them, etc ntinent - a dictionary/map (same thing) to hold pairs of countries and continents. The class attributes will be catalogue - an array of countries, or more accurately, a pointer to a dynamic array of pointers to countries. . _maxSize - how big our array called catalogue is currently curSize -how many things are currently in our array called_catalogue * _countryCo o Map? Read these carefully: - http://www.cplusplus.com/reference/map/map/ - https://thispointer.com/stdmap-tutorial-part-1-usage-detail-with- examples,/ - https://stackoverflow.com/questions/26281979/c-loop-through-map The methods this class will have are described below .A default constructor that will just set maxSize to 10, curSize to 0 (nothing in our catalogue yet), and make a dynamic array of size_ maxSize. I provided this for you. .A constructor that will setup our catalogue of countries based on some text files. This constructor will be fairly complex and you may find it to be one of the more challenging parts of this assignment. I have included some comments to help guide what to do. This constructor will receive two strings as parameters that correspond to the names of files that contain the information the class needs to setup the catalogue. Your program must work in general with any possible files, but the ones we'll be using to test your code are provide and are named country cpp.txt and continent cpp.txt. Based on the contents of the continent file, the constructor will populate the o o countryContinent map with country (key) continent (value) pairs. Map? If your memory is that bad, read these carefully again: //thi examples/ st detail stackoverflow.com/questio rou o Based on the contents of the country file, the constructor will populate the_catalogue. You will need to use the countryContinent here to get each country's continent. I also recommend making use of the addCountry method described below that you will implement to easily add the countries to the catalogue The format of the files is this (slight change here from A4 in 161): o Continent: Line 1 contains the country name, then that county's continent on line 2. Then line 3 is a new country name, and line 4 is it's continent, etc Country: Line 1 contains a country name, followed by its population, followed by the area, then line 4 is a new country name, then population, then area, etc. o File I/O? oria .Get reading! -One thing to take special note of is the .eof function. You might find that handy depending on how you want to code it. Also, be sure to close your files! - .We'll not making a copy constructor here. This is probably a bad move long term, but to simplify things a little, we'll skip it for Al .A deconstructor that will delete the contents of the catalogue, and then delete the catalogue itself. Remember, catalogue is a pointer to a group of pointers. We have to delete the inside pointers, then delete the array that held the pointers that is being pointed to by_catalogue. .A private method called expandCapacity that will just make a new array that's bigger if we run out of space in our_catalogue. As a rule, we will always double the size every time. Watch out for memory 1 leaks! addCountry is a method that will take all the information needed to make a country (name, pop, area, continent) as a parameter, make the object, and add it to the catalogue. If we run out of room in our array we might have to expand the capacity (see above). Whenever we add it, we must be sure to increment the counter keeping track of the number of things in our . .RemoveCountry will take a name of a country as a parameter and delete the country with the matching name from the catalogue. If it does not exist, then the method will ultimately have no impact. Watch out for memory leaks and be sure to update the catalogue correctly findCountry will take a country name and return a pointer to the country with the matching name in the catalogue (assuming it exists). If it does not exist, retum nullptr. numCountriesInContinent will take a continent name, and then return how many countries from that continent. .filterCountriesByContinent will take a continent name and the number of countries that exist on that continent and return a pointer to an array containing pointers to the countries on the continent. This one might be a little tricky, but it shouldn't be too bad. Just make a pointer to an array of pointers to countries of the proper size, then add the countries on the continent to the array. Return the pointer to the array in the end. If none exist, return nullptr printCountryCatalogue will just print out the contents of the catalogue. This one should be simple. Print out"name in continent" for each country on a new line. To do this, just have a loop go over the_catalogue and call each country's to string) method and print it out. . setPopulationOfSelectedCountry will take a country name and a new population and then update the corresponding country in the catalogue's population (assuming it exists). . .findCountry WithLargestPop will return a pointer to the country with the largest population within our catalogue. If nothing is in the catalogue, return nullptr. findCountry WithSmallestAreawill return a pointer to the country with the smallest population within out catalogue. If nothing is in the catalogue, return nullptr. findMostPopulousContinent will return the name of the continent with the largest population based on the countries within the catalogue. This one will be a little tricky. saveCountryCatalogue will take the name of a file to create and write to which will save some details about the contents of our catalogue. The function will return the number of lines written to the file. Format the output as follows o NAME CONTINENTIPOPULATION POPULATION DENSITY o China Asia 1339190000 139.5431469965489 Do not be surprised if your output formats the numbers funny. This is fine. See my includecd example output file named saved al_example.txt. o File I/O? o In case you forgot again. http://www.cplusplus.comdoc/tutorial/files

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions