(a) To read a country's name and display capital and per-capita income.
(b) To read name of the capital city and displays country's name and displays country's name and per capita income.
Display an error message in case of an incorrect input.
#include<string.h>
struct country{
char country_name[20];
char capital_name[20];
float incm;
};
typedef country C;
void main()
{
C c[50];
for(int i = 0; i<49; i++)
{
cout<<"\n Enter Country's name :";
cin>>c[i].country_name;
cout<<"\n Enter the name of Capital :";
cin>>c[i].capital_name;
cout<<"\n Enter per capita incme:";
cin>>c[i].incm;
}
char cname[20];
char capital[20];
char choice;
int n, flag = 0 ;
do
{
cout<<"\n ***********MENU***********\n\n";
cout<<" 1. Know Capital for a country :";
cout<<"\n 2. Know County for a capital :";
cout<<"\n\n Enter your choice :";
cin>>n;
switch(n)
{
case 1:
cout<<"\n Enter a country name :";
gets(cname);
for(i=0; i<50; i++)
if(strcmp(c[i].country_name, cname)==0)
{
cout<<"The capital of "<< c[i].country_name <<" is " << c[i].capital_name ;
cout<<"\n Per caita income = Rs. "<< c[i].incm;
flag = 1;
break;
}
break;
case 2:cout<< "\n Enter a capital name :";
gets(capital);
for(i=0; i<50; i++)
if(strcmp(c[i].capital_name, capital)==0)
{
cout<<"\nThe capital of "<< c[i].capital_name <<" is " << c[i].country_name ;
flag = 1;
cout<<"\n Per capita income = Rs. "<< c[i].incm;
break;
}
break;
default:
cout<<"\n Wrong Input! ";
}
if(flag == 0)
cout<<"\n No Information .";
cout<<"\n\n Do you want to continue (Y/N) :";
cin>>choice;
}while(choice == 'Y' || choice == 'y');
getch();
}
(b) To read name of the capital city and displays country's name and displays country's name and per capita income.
Display an error message in case of an incorrect input.
#include <iostream.h>
#include <conio.h>
#include<stdio.h>#include<string.h>
struct country{
char country_name[20];
char capital_name[20];
float incm;
};
typedef country C;
void main()
{
C c[50];
for(int i = 0; i<49; i++)
{
cout<<"\n Enter Country's name :";
cin>>c[i].country_name;
cout<<"\n Enter the name of Capital :";
cin>>c[i].capital_name;
cout<<"\n Enter per capita incme:";
cin>>c[i].incm;
}
char cname[20];
char capital[20];
char choice;
int n, flag = 0 ;
do
{
cout<<"\n ***********MENU***********\n\n";
cout<<" 1. Know Capital for a country :";
cout<<"\n 2. Know County for a capital :";
cout<<"\n\n Enter your choice :";
cin>>n;
switch(n)
{
case 1:
cout<<"\n Enter a country name :";
gets(cname);
for(i=0; i<50; i++)
if(strcmp(c[i].country_name, cname)==0)
{
cout<<"The capital of "<< c[i].country_name <<" is " << c[i].capital_name ;
cout<<"\n Per caita income = Rs. "<< c[i].incm;
flag = 1;
break;
}
break;
case 2:cout<< "\n Enter a capital name :";
gets(capital);
for(i=0; i<50; i++)
if(strcmp(c[i].capital_name, capital)==0)
{
cout<<"\nThe capital of "<< c[i].capital_name <<" is " << c[i].country_name ;
flag = 1;
cout<<"\n Per capita income = Rs. "<< c[i].incm;
break;
}
break;
default:
cout<<"\n Wrong Input! ";
}
if(flag == 0)
cout<<"\n No Information .";
cout<<"\n\n Do you want to continue (Y/N) :";
cin>>choice;
}while(choice == 'Y' || choice == 'y');
getch();
}
No comments:
Post a Comment