Answer to Question #48237 in C++ for Rajat bhargava

Question #48237
write a menu driven program to input name capital and currency of some countries and depending on user's choice,
a.input country name and display its capital and currency.
b.input capital name and display its currency and country.
c.input currency name and display its capital and country.
1
Expert's answer
2014-10-28T01:41:23-0400
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <string>
using namespace std;
char * CURRENCY[] = {"Yuan","RUB", "EUR", "Hryvnia", "USD"};
char * COUNTRIES[] = {"China", "Russia", "Austria", "Ukraine", "USA"};
char * CAPITAL[] = {"Pekin","Moscow", "Vienna", "Kiev", "Washington"};
int SearchByCountry(string country)
{
for (int i = 0; i < 5; i++)
if (COUNTRIES[i] == country) { return i;}
return -1;
}
int SearchByCapital(string capital)
{
for (int i = 0; i < 5; i++)
if (CAPITAL[i] == capital) { return i;}
return -1;
}
int SearchByCurrency(string currency)
{
for (int i = 0; i < 5; i++)
if (CURRENCY[i] == currency) { return i;}
return -1;
}
int main()
{
string temp;
int tmp;
cout<<"Available countries : ";
for (int i = 0; i < 5; i ++)
cout<< COUNTRIES[i]<<" "; cout<<endl<<endl;
cout<<"Available capital : ";
for (int i = 4; i > -1; i--)
cout<< CAPITAL[i]<<" "; cout<<endl<<endl;
cout<<"Available currency : ";
for (int i = 0; i < 5; i ++)
cout<<CURRENCY[i]<<" "; cout<<endl<<endl;

cout<<"1.input country name and display its capital and currency"<<endl;
cout<<"2.input capital name and display its currency and country"<<endl;
cout<<"3.input currency name and display its capital and country"<<endl;
cin>>tmp;
if (tmp == 1)
{
cout<<"Enter country : "; cin>> temp;
if (SearchByCountry(temp) != -1 )
{
cout<<"Capital : "<< CAPITAL[SearchByCountry(temp)]<<endl;
cout<<"Currency : "<< CURRENCY[SearchByCountry(temp)]<<endl;
}
else
{
cout<<"Error. This country is not listed"<<endl;
}
}
if (tmp == 2)
{
cout<<"Enter capitol : "; cin>> temp;
if (SearchByCapital(temp) != -1 )
{
cout<<"Country : "<< COUNTRIES[SearchByCapital(temp)]<<endl;
cout<<"Currency : "<< CURRENCY[SearchByCapital(temp)]<<endl;
}
else
{
cout<<"Error. This capital is not listed"<<endl;
}
}
if (tmp == 3)
{
cout<<"Enter capitol : "; cin>> temp;
if (SearchByCurrency(temp) != -1 )
{
cout<<"Country : "<< COUNTRIES[SearchByCurrency(temp)]<<endl;
cout<<"Capital : "<< CAPITAL[SearchByCurrency(temp)]<<endl;
}
else
{
cout<<"Error. This currency is not listed"<<endl;
}
}
system("pause");
return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS