#include <iostream>#include <string> using namespace std; class Country { public: string name; string capital; int capita; Country(){}; void PrintforCountry() { cout << "The capital is " << capital << "\n"; cout << "The capita income " << capita << "\n\n"; } void PrintforCapital() { cout << "The country is " << name << "\n"; cout << "The capita income " << capita << "\n\n"; } }; int main() { Country Allc[50]; for (int i = 0; i < 50; i++) Allc[i] = Country(); int count; Allc[0].name = "USA"; Allc[0].capital = "Wasington D.C."; Allc[0].capita = 380; Allc[1].name = "Japan"; Allc[1].capital = "Tokyo"; Allc[1].capita = 420; Allc[2].name = "Germany"; Allc[2].capital = "Berlin"; Allc[2].capita = 240; Allc[3].name = "Canada"; Allc[3].capital = "Ottava"; Allc[3].capita = 310; count = 3; // We can add more Countries and information (till 50 countries) but we should change count, when we add. bool b = true; while(b) { bool boo = true; string s; int x; cout << "What do you want to see :\n 1. Capital and per capita income of the country.\n 2. Name of the country and per capita income.\n 3. Exit \n Enter number of choice to choose:"; cin >> x; switch(x) { case 1: cout << "Enter the name of the country:"; cin >> s; for (int j = 0; j <= count; j++) { if (Allc[j].name == s) { Allc[j].PrintforCountry(); boo = false; continue; } } if (boo) cout << "There is no country with such name!\n"; break; case 2: cout << "Enter the capital of the country:"; cin >> s; for (int j = 0; j <= count; j++) { if (Allc[j].capital == s) { Allc[j].PrintforCapital(); boo = false; continue; } } if (boo) cout << "There is no country with that capital!\n"; break; case 3: b = false; break; default: cout << "Please enter 1, 2 or 3 only."; break; } } return 0; }
Comments