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<stdlib.h>
#include<conio.h>
#include<string.h>
class phone
{
int p,c,s,ph[4],code[3],std[3];
public:
void accept();
void disp();
void new_ph();
void convert();
};
void phone::accept()
{
cout<<"Enter STD no.:\t";
cin>>s;
cout<<"Enter Exchange code:\t";
cin>>c;
cout<<"Enter phone number:\t";
cin>>p;
cout<<"\n\nOld Number:\n";
cout<<s<<"-"<<c<<"-"<<p;
}
void phone::disp()
{
cout<<"\n";
for(int i=2;i>=0;i--)
cout<<std[i];
cout<<"-";
for(i=2;i>=0;i--)
cout<<code[i];
cout<<"-";
for(i=2;i>=0;i--)
cout<<ph[i];
}
void phone:: convert()
{
int k=0,i=0;
while(s>0)
{
k=s%10;
std[i]=k;
s=s/10;
i++;
}
i=0,k=0;
while(c>0)
{
k=c%10;
code[i]=k;
c=c/10;
i++;
}
i=0,k=0;
while(p>0)
{
k=p%10;
ph[i]=k;
p=p/10;
i++;
}
}
void phone::new_ph()
{
std[2]=std[2]+1;
int tmp;
tmp=ph[1];
ph[1]=ph[2];
ph[2]=tmp;
}
int main()
{
clrscr();
phone p;
p.accept();
p.convert();
p.new_ph();
cout<<"\n\nNew Number:";
p.disp();
getch();
return 0;
}
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<stdlib.h>
#include<conio.h>
#include<string.h>
class phone
{
int p,c,s,ph[4],code[3],std[3];
public:
void accept();
void disp();
void new_ph();
void convert();
};
void phone::accept()
{
cout<<"Enter STD no.:\t";
cin>>s;
cout<<"Enter Exchange code:\t";
cin>>c;
cout<<"Enter phone number:\t";
cin>>p;
cout<<"\n\nOld Number:\n";
cout<<s<<"-"<<c<<"-"<<p;
}
void phone::disp()
{
cout<<"\n";
for(int i=2;i>=0;i--)
cout<<std[i];
cout<<"-";
for(i=2;i>=0;i--)
cout<<code[i];
cout<<"-";
for(i=2;i>=0;i--)
cout<<ph[i];
}
void phone:: convert()
{
int k=0,i=0;
while(s>0)
{
k=s%10;
std[i]=k;
s=s/10;
i++;
}
i=0,k=0;
while(c>0)
{
k=c%10;
code[i]=k;
c=c/10;
i++;
}
i=0,k=0;
while(p>0)
{
k=p%10;
ph[i]=k;
p=p/10;
i++;
}
}
void phone::new_ph()
{
std[2]=std[2]+1;
int tmp;
tmp=ph[1];
ph[1]=ph[2];
ph[2]=tmp;
}
int main()
{
clrscr();
phone p;
p.accept();
p.convert();
p.new_ph();
cout<<"\n\nNew Number:";
p.disp();
getch();
return 0;
}