A phone number, such as (212) 767-8900, can be thought of as having three parts: the area code (212), the exchange (767) and the number (8900). Write a program that uses a structure to store these three parts of a phone number separately. Call the structure phone. Create two structure variables of type phone. Initialize one, and have the user input a number for the other one. Then display both numbers. The interchange might look like this: 
Enter your area code, exchange, and number: 415 555 1212 
My number is (212) 767-8900 
Your number is (415) 555-1212

Implementation of the above problem:
struct phone
char area[10];
char exchange[10];
char number[10];
int main()
phone ph1={"212","767","8900"};
phone ph2;
cout<<"\nenter your area code,exchange and number:";

cout<<"\nmy number is ("<<ph1.area<<")"<<ph1.exchange<<"-"<<ph1.number;
cout<<"\nyour number is ("<<ph2.area<<")"<<ph2.exchange<<"-"<<ph2.number;
return 0;

Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment: