Question: Provide C++ code .donot copy and paste the answer. If you donot know leave it. Donot give wrong answer This is all the question I
Provide C++ code .donot copy and paste the answer. If you donot know leave it. Donot give wrong answer
This is all the question I havent really gotten it. Sorry about all the pictures i wanted to show you the entire thing. i have posted all the files that are there. However; only adjustments needed to be done under the file CountryData.cpp , other files are there to hep i guess. what i have under the file that needs to be coded might be wrong. Please help me out here with the right code, and post a code to copy with it. Thank you!!! 













REVISION NOTE 4/17/2020: Since are covering some material in a different order than originally planned, more of this lab was already done for you. Every file but CountryData.cpp is read-only, so you only need to do the TOD0s in that file. The function ReadCountryData is actually already complete. In this lab, you will implement a very simple class called CountryDat a that stores some population data for a country, and (more importantly) write functions to: - parse a line of text and convert it to a CountryData object - read a file line by line and return a vectorscountryData> containing all the valid data in the file The CountryData class contains three data members: - The name of the country. - The population of the country in 1980 - The population of the country in 2010 This data will be read from a file called population_by_country. csv, each line of which looks like this: Canada ,24.5933,24.9,25.2019,25.4563,25.7018,,32.65668,32.93596,33.2127,33.48721,33.75974 (Fve elided some data to make it fit on one line.) The data consists of fields separated by commas - thus it's referred to as a 'comma-separated values' file. (Spreadsheets can read these directly - try it.) The first field is the name of the country, and the others are the population values in millions from 1980 to 2010. Ive provided a header file containing the declaration of the countryDat a class, all you need to do is to fill in the details. The class itself - Finish the constructor - Implement getName0, which simply returns the country name - Implement calcGrowth0, which calculates the population growth from 1980-2010 Each of these can actually be done in one line, though taking more than one line may help readability. The hard part will be the two functions that actually read the data. The first is parseCountryData(), whose signature is: CountryData parseCountryData(const std::string \& line); The line argument is one line of the file. The function needs to split the data into separate fields (using a split() function that III provide), and then return a CountryData object. The county name is the first field, the 1980 population is the second, and the 2010 population is the last The population data will need to be converted from std: : string to double. I ve provided a function called fieldToDouble() that I recommend you use rather than writing your own. The fieldToDouble() function that I provide will throw an exception for invalid floating-point data. The exception should NOT be caught in parseCountryData(); see below. The second function is readCountryData(), whose signature is: Std: :vector readCountryData(const std: string s filename): This function needs to open the file as an if stream, and use getline() to read the file line by line. It should call parseCountryData() to convert this line of data to a CountryDat a object, and store each valid line in a vectorscountryData>. This vector is the return value of the function. The call to parseCountryData() should be wrapped in a try block. Recall that the syntax is: try I // call parsecountryData () // add this CountryData to the vector catch (std::runtime_error \& e) i // ignore the error; just don't add this one to the vector In case we have not covered exceptions by the time you do this lab, this code is provided for you. Provided functions Ive provided utilities.h and utilities.cpp which declare/define these functions: double fieldToDouble (const std::string s field) ; fieldToDouble() converts the given std : : string to a floating point value, which is returned as a double, It does some basic error checking, and throws an exception if the field cannot be converted. Std: :vector split(const std::string \& s, char sep); split() separates the given std: : string into individual fields based on the given separator character. The fields are returned as a vector. rve also provided Title_ratings.cpp from a different project. You can use that as a guide for writing your parseCountryData() ve also provided Title_ratings. cpp from a different project. You can use that as a guide for writing your parseCountryData() unction. 9.10.1: Line-oriented file input Downloadable files zunyour program as often as you'd like, befc imput values in the first box, then click Run pr File is marked as read only File is marked as read only Current file: utilities.h Run your program as often as youd like, before input values in the first box, then click Run pros second box File is marked as read only Run your program as often as youd like input values in the first box, then click R seoona box: File is marked as read only Current file: utilities.cpp Run your program as often as youd l like input values in the first box, then click R second box File is marked as read only Current file: utilities.cp /f If this put us at the end of the string, If we need to account for the blank field at H the end. if (i==1en) fields.emplace_back(); \} return fields; 3 int fieldToInt(const std: :string \& field) if (f ield. length ()=) throw std: :runtime_error("Cannot convert 0 -iength string"); if (field = "..." (field = " "NA")) throw std:iruntime_error ("No data provided"); return strtol(field. C_str(), NULL, 10); ) double fieldToDouble(const std::string \& field) 42 if (field. length ()=) Run your program as often as youd input values in the first box, then clic second box. File is marked as read only Current file: utilitie File is marked as read only Current file: CountryDataTest.c Runyoui program as often as youd like, be input values in the first box, then click Run second oox: fle is marked as read only Current file: CountryDataTest.cpp is marked as read only REVISION NOTE 4/17/2020: Since are covering some material in a different order than originally planned, more of this lab was already done for you. Every file but CountryData.cpp is read-only, so you only need to do the TOD0s in that file. The function ReadCountryData is actually already complete. In this lab, you will implement a very simple class called CountryDat a that stores some population data for a country, and (more importantly) write functions to: - parse a line of text and convert it to a CountryData object - read a file line by line and return a vectorscountryData> containing all the valid data in the file The CountryData class contains three data members: - The name of the country. - The population of the country in 1980 - The population of the country in 2010 This data will be read from a file called population_by_country. csv, each line of which looks like this: Canada ,24.5933,24.9,25.2019,25.4563,25.7018,,32.65668,32.93596,33.2127,33.48721,33.75974 (Fve elided some data to make it fit on one line.) The data consists of fields separated by commas - thus it's referred to as a 'comma-separated values' file. (Spreadsheets can read these directly - try it.) The first field is the name of the country, and the others are the population values in millions from 1980 to 2010. Ive provided a header file containing the declaration of the countryDat a class, all you need to do is to fill in the details. The class itself - Finish the constructor - Implement getName0, which simply returns the country name - Implement calcGrowth0, which calculates the population growth from 1980-2010 Each of these can actually be done in one line, though taking more than one line may help readability. The hard part will be the two functions that actually read the data. The first is parseCountryData(), whose signature is: CountryData parseCountryData(const std::string \& line); The line argument is one line of the file. The function needs to split the data into separate fields (using a split() function that III provide), and then return a CountryData object. The county name is the first field, the 1980 population is the second, and the 2010 population is the last The population data will need to be converted from std: : string to double. I ve provided a function called fieldToDouble() that I recommend you use rather than writing your own. The fieldToDouble() function that I provide will throw an exception for invalid floating-point data. The exception should NOT be caught in parseCountryData(); see below. The second function is readCountryData(), whose signature is: Std: :vector readCountryData(const std: string s filename): This function needs to open the file as an if stream, and use getline() to read the file line by line. It should call parseCountryData() to convert this line of data to a CountryDat a object, and store each valid line in a vectorscountryData>. This vector is the return value of the function. The call to parseCountryData() should be wrapped in a try block. Recall that the syntax is: try I // call parsecountryData () // add this CountryData to the vector catch (std::runtime_error \& e) i // ignore the error; just don't add this one to the vector In case we have not covered exceptions by the time you do this lab, this code is provided for you. Provided functions Ive provided utilities.h and utilities.cpp which declare/define these functions: double fieldToDouble (const std::string s field) ; fieldToDouble() converts the given std : : string to a floating point value, which is returned as a double, It does some basic error checking, and throws an exception if the field cannot be converted. Std: :vector split(const std::string \& s, char sep); split() separates the given std: : string into individual fields based on the given separator character. The fields are returned as a vector. rve also provided Title_ratings.cpp from a different project. You can use that as a guide for writing your parseCountryData() ve also provided Title_ratings. cpp from a different project. You can use that as a guide for writing your parseCountryData() unction. 9.10.1: Line-oriented file input Downloadable files zunyour program as often as you'd like, befc imput values in the first box, then click Run pr File is marked as read only File is marked as read only Current file: utilities.h Run your program as often as youd like, before input values in the first box, then click Run pros second box File is marked as read only Run your program as often as youd like input values in the first box, then click R seoona box: File is marked as read only Current file: utilities.cpp Run your program as often as youd l like input values in the first box, then click R second box File is marked as read only Current file: utilities.cp /f If this put us at the end of the string, If we need to account for the blank field at H the end. if (i==1en) fields.emplace_back(); \} return fields; 3 int fieldToInt(const std: :string \& field) if (f ield. length ()=) throw std: :runtime_error("Cannot convert 0 -iength string"); if (field = "..." (field = " "NA")) throw std:iruntime_error ("No data provided"); return strtol(field. C_str(), NULL, 10); ) double fieldToDouble(const std::string \& field) 42 if (field. length ()=) Run your program as often as youd input values in the first box, then clic second box. File is marked as read only Current file: utilitie File is marked as read only Current file: CountryDataTest.c Runyoui program as often as youd like, be input values in the first box, then click Run second oox: fle is marked as read only Current file: CountryDataTest.cpp is marked as read only
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
