write a program that lists European, Middle-Eastern, or Asian Countries and thier capitals. the program retrieves this information from an input file that the user specifies during program execution. The program retrieves this information from an input file that the user specifies during program execution. The data can be stored in a one-dimensional array or a two-dimensional array. the data is displayed in a tabular format at the end if the program execution.
in your project you should show the utilization of the following:
1. using user defined functions
2. using appropriate selection
3. using loops
This should get you going! It reads all data from a text file and adds it to 2 arrays. The data is then displayed in a formatted table. This is as far as I will go. I cannot do all the work for you ;)
Output looks like:
1 2 3 4
France Paris
Cuba Havana
Fiji Suva
Colombia Bogota
#include <iostream>
#include <iomanip>
#include <fstream>
usingnamespace std;
//function prototypes
int buildArrays();
//declare variables
string CountryName[100]; //Array of country names
string CountryCapital[100]; //Array of country capitals
int totalCountries; //Total number of countries
int i=0; //Counter
int main()
{
//the buildArrays function reads all the data from the input file and determines the total number of countries in the file.
totalCountries=buildArrays();
//display all the output
for(i=0;i<=totalCountries;i++)
{
cout<<"\n";
cout<<setw(15) << left << CountryName[i] << setw(5) << right <<CountryCapital[i];
}
return 0;
}
//custom function to read all the data from the file
int buildArrays()
{
//open the text file
ifstream inFile;
inFile.open( "input.txt" );
//if the text file doesn't open display an error
if( inFile.fail() )
{
cout << "The input.txt file failed to open";
exit(-1);
}
//while there is data in the file add it to the arrays
while(inFile)
{
inFile>> CountryName[i];
inFile>> CountryCapital[i];
i++;
}
//return the total number fo countries
return i-2;
}