Phone Number Example
A phone number can be thought of three parts: the area code (051), the exchange (767),
and the number (8977). Write a program that uses a structure to store these three parts of
phone number separately. You have to ask user how many phone numbers he/she wants
to store. Save these phone numbers dynamically.
Then Program should ask user to enter the area code.
Output should be the phone numbers that matches with the given area code in the
A phone number can be thought of three parts: the area code (051), the exchange (767),
and the number (8977). Write a program that uses a structure to store these three parts of
phone number separately. You have to ask user how many phone numbers he/she wants
to store. Save these phone numbers dynamically.
Then Program should ask user to enter the area code.
Output should be the phone numbers that matches with the given area code in the
following format.
(area code) exchange-number
(051) 767-8977
CODE:
#include <iostream>
using namespace std;
struct p_no{
long int area_c;
long int exchange;
long int no;
};
int main(){
cout<<"How many phone number's you want to enter : ";
int ph_no;
cin>>ph_no;
p_no *ptr = new p_no[ph_no];
for (int i=0; i<ph_no ; i++){
cout<<"\nENTER AREA CODE\n";
cin>>ptr[i].area_c;
cout<<"\nENTER EXCHANGE NUMBER\n";
cin>>ptr[i].exchange;
cout<<"\nENTER THE NUMBER\n";
cin>>ptr[i].no;
}
for (int j=0; j<ph_no ; j++){
cout<<"\nEnter the area code\n";
long int area_code;
cin>>area_code;
if (area_code == ptr[j].area_c)
cout<<"\n\n("<<ptr[j].area_c<<")"<<ptr[j].exchange<<"-"<<ptr[j].no<<endl<<endl;
}
return 0;
}
No comments:
Post a Comment