3. Create a class phone having data members: 1. The STD code 2. The Exchange code 3.Phone Number Ex :- 212-766-8901 Write a C++ program to accept details from user (max 10) and change input phone number to new phone number using following criteria: a)Add 1 to 1st digit of STD code. (If digit is 9 it becomes 10) b)The exchange code is retained as it is. c)In 3rd part of structure, 1st two digits should be reversed. Ex: I/P : 212-766-890 => O/P : 312-766-980 Display all changed phone numbers.


#include<iostream.h>
#include<conio.h>
#include<string.h>
class phone
{
char *stdcode,*Ecode;
char *Pno;
int len,i;
public:
phone()
{
stdcode=new char;
Ecode=new char;
Pno=new char;
}
void change_scode();
void change_pno();
void get()
{
cout<<“\nEnter STD code: “;
cin>>stdcode;
cout<<“\nEnter Exchange code: “;
cin>>Ecode;
cout<<“\nEnter Phone number: “;
cin>>Pno;
}
void disp()
{
cout<<“\nPhone number: “;
cout<<stdcode<<“-“<<Ecode<<“-“<<Pno<<endl;
}
};
void phone::change_scode()
{
len=strlen(stdcode);
for(i=0;i<len;i++)
{
stdcode[i];
}
//if(stdcode[0]==57)
//{
//stdcode[0]=stdcode[0]+1;
//}
// else
// {
stdcode[0]= stdcode[0]+1;
// }
}
void phone::change_pno()
{
len=strlen(Pno);
for(i=0;i<len;i++)
{
Pno[i];
}
char t;
t=Pno[0];
Pno[0]=Pno[1];
Pno[1]=t;
}
void main()
{
phone p;
clrscr();
p.get();
p.disp();
p.change_scode();
p.change_pno();
cout<<“\nNEW : “;
p.disp();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s