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

Please help me this is my assignment Read World Population Data File. Store the

ID: 3639847 • Letter: P

Question

Please help me this is my assignment

Read World Population Data File. Store the values in multiple vectors. Sort them by most populated region and output the results
Input Population Data File will be available from the course site.

Please read my code I have my questions there but one of these question is that I cannot read the file can I saved in excel and read it from there? or can I keep the website and my program would read the file?

This is a small piece of what appears in the file

"Major area, region, country or area" Country code 2010
WORLD 900 6895889.02
More developed regions 901 1235899.87
Less developed regions 902 5659989.15
Least developed countries 941 832329.58
"Less developed regions, excluding least developed countries" 934 4827659.58
"Less developed regions, excluding China" 948 4287840.92
Sub-Saharan Africa 947 856327.16
AFRICA 903 1022234.40
Eastern Africa 910 324044.32
Burundi 108 8382.85
Comoros 174 734.75
Djibouti 262 888.72
Eritrea 232 5253.68
Ethiopia 231 82949.54
Kenya 404 40512.68
Madagascar 450 20713.82
Malawi 454 14900.84
Mauritius 480 1299.17
Mayotte 175 204.11
Mozambique 508 23390.77
Réunion 638 846.07


And this what I got so far please help

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <stdio.h>

using namespace std;

int main()

{

//Define vectors to hold the data adquire for file and be able to sort them later
vector<string> countryNames;
vector<int> countryCodes;
vector<double> countryPopulation;

//Open the file and Reading from file Can I create an Excell file and read it from there? if yes how?
string filename= "http://www.csupomona.edu//~hmzaidi//Winter2012//CS128//WorldPopulation2010.txt"
ifstream filename;//open a file variable for input (can it be ifstream fin("filename.txt")
ifstream in_file; //??
infile.open(filename.c_str(), ios::in);//open the file to read it and for input what is ios for?


//Reading from file line by line
//1st Read the header
string header;//how would distinguis is the header?
getline(in_file, header);//Reads the entire line in the file
//declariation of the variable
string line;

while (getline(in_file, line)//Read the whole line
{
cout << line << endl;//prints the line on the console

//declaration of variables
string countryName;
string countryCode;
string countryPopulation;



//Extract the data from the string
int i = 0;
while (!isdigit(line[i])) {i++}//Locate the first digit

int j= i-1
while(isspace(line[j])) {j--}//skip white space

string countryName = line.substr(0, j+1);//extract country Name
string countryPopulation = line.substr(i);//extract country population
string countryCode = line.substr(i, 3);//extract code but I dont think this is right?? Idont know hoe to do this?

largest = countryPopulation;

if (countryPopulation > largest)//Checking for the most populated country
{
largest = countryPopulation;

}

//Print out on the screen I want to print like starting with the mosr populated country

CountryName CountryCode Country Population <- most populated //I want it to appear like this
//but I dont know how please help
//what soting function I can use
//can I use more function on the program and I cannot use Classes




char key;
cin >> key;

return 0;

}

}

Explanation / Answer

#include <iostream> #include <string> #include <vector> #include <fstream> #include <stdio.h> using namespace std; int main() { //Define vectors to hold the data adquire for file and be able to sort them later vector<string> countryNames; vector<int> countryCodes; vector<double> countryPopulation; //Open the file and Reading from file Can I create an Excell file and read it from there? if yes how? //No, it is better to create .txt file and to enter the data inside string filename= "C:\Users\mite\Desktop\1.txt"; //Example, enter your path to the .txt file here //ifstream filename;//open a file variable for input (can it be ifstream fin("filename.txt") ifstream in_file; //?? in_file.open(filename.c_str(), ios::in);//open the file to read it and for input what is ios for? //Reading from file line by line //1st Read the header string header;//how would distinguis is the header? getline(in_file, header);//Reads the entire line in the file //declariation of the variable string line; string largest; string largestCountryCode; string largestCountryName; while (getline(in_file, line))//Read the whole line { cout << line << endl;//prints the line on the console //declaration of variables string countryName; string countryCode; string countryPopulation; //Extract the data from the string int i = 0; while (!isdigit(line[i])) {i++;}//Locate the first digit int j= i-1; while(isspace(line[j])) {j--;}//skip white space /*string*/ countryName = line.substr(0, j+1);//extract country Name /*string*/countryPopulation = line.substr(i);//extract country population /*string*/ countryCode = line.substr(i, 3);//extract code but I dont think this is right?? Idont know hoe to do this? largest = countryPopulation; largestCountryCode = countryCode; largestCountryName = countryName; if (countryPopulation > largest)//Checking for the most populated country { largest = countryPopulation; largestCountryCode = countryCode; largestCountryName = countryName; } } //Print out on the screen I want to print like starting with the mosr populated country //CountryName CountryCode Country Population <- most populated //I want it to appear like this //but I dont know how please help //what soting function I can use //can I use more function on the program and I cannot use Classes cout<<largest<<" "<<largestCountryCode<<" "<<largestCountryName<<endl; char key; cin >> key; return 0; }