"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Tuesday, April 6, 2010

A linear array if size 50 stores following informations : name of the country, country's capital and per capita income of the country. Write a complete program in C++ to do the following :

(a) To read a country's name and display capital and per-ca pita income.
(b) To read name of tha capital city and displays country's namr and displays country's name and per capital income.

Display an error message in case of an incorrect input.


#include<iostream.h>
#include<conio.h>
struct country
{
char nm[30];
char capital[30];
float income;
};

void main()
{
country c[50];
for( int i=0; i<50 ; i++)
{
cout << "\n Country's name : ";
cin.getline(c[i].nm, 30);
cout << "\n Country's capital :";
cin.getline(c[i].capital,30);
cout << "\n Per capita income :";
cin >> c[i].income;
}

clrscr();
cout << "\n\n Sl No. \t Country \t Capital \t Per-Ca pita-Income \n :";
for( int i=0; i < 50 ; i++)
{
cout << i+1 << "\t" << c[i].nm << "\t" << c[i].capital << "\t" << c[i].income << "\n" ;
}

cout << "\n *************************************************** \n ";

char ch = 'y';
char cap[30];
int flag = 0;

while(ch == 'y' || ch == 'Y')
{
cout << "\n Enter Capital name : ";
cin.getline(cap, 30);

for(int k =0; k <50 ; k++)
{
flag = 0;
if( strcmp( c[i].capital , cap ) == 0)
{
cout  << c[i].nm << "\t" << c[i].capital << "\t" << c[i].income << "\n" ;
flag = 1;
}

if(flag == 0)
cout << " Match not found !! ";
cout<< "Do you want to continue ?(y/n)";
cin >> ch;
 
}
}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.