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

Monday, January 18, 2010

A phone number such as (011)711 8802 can be thought of as having three parts: the area code(011), the exchange(711), and the number(8802). Write a program that uses a structure to store these three parts of a phone number separately.Call the structure phone. Create an array to store 20 records of its member wherein each record stores the member no., member name and phone number of phone type. Have the user input the information for all records and then display the entire information on the screen.


#include<iostream.h>
#include<conio.h>
#include <stdio.h>

struct phone{
int area_code;
int exchange;
int number;
};

struct member{
int member_id;
char name[30];
phone ph_no;
};

void main()
{
member rec[20];
char ch;
cout<<"\n Enter records of 20 members ";

for(int i = 0; i < 20 ; i++)
{
cout<< "\n Member ID ? ";
cin >> rec[i].member_id;
cout<< "\n Enter Name :";
gets( rec[i].name);
cout<< " \n Enter phone number in the format \'areacode - exchange - number (003 - 2442 - 6523)\' :";
cin >> rec[i].ph_no.area_code >> ch >>  rec[i].ph_no.exchange >> ch >> rec[i].ph_no.number ;
}

clrscr();

cout<< "\n Member ID \t Member Name \t Ph. No. \n ";
cout<< "--------------------------------------------\n\n";
for(int i = 0; i < 20 ; i++)

{
cout<< rec[i].member_id << "\t" << rec[i].name << "\t" << rec[i].ph_no.area_code<< "-" <<  rec[i].ph_no.exchange <<  "-" <<  rec[i].ph_no.number << endl ;
}

getch();

}











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.