/*
create a class phone having data member:
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 retain as it is.
c) in third part of structure 1st two digit should be reverse
display all changes phone numbers.
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class phone
{
long int std,ex;
char ph[20];
public:void accept()
{
cout<<"\nenter STD code:-";
cin>>std;
cout<<"\nenter exchange code:-";
cin>>ex;
cout<<"\nenter phone number:-";
cin>>ph;
}
void display()
{
cout<<"\n"<<std<<"\t"<<ex<<"\t\t"<<ph;
}
void change();
};
void phone::change()
{
long int ans=0;
int n;
while(std>0)
{
n=std%10;
std=std/10;
if(std==0)
ans=(ans*10)+(n+1);
else
ans=(ans*10)+n;
}
std=0;
while(ans>0)
{
n=ans%10;
ans=ans/10;
std=(std*10)+n;
}
int c=ph[0];
ph[0]=ph[1];
ph[1]=c;
}
int main()
{
phone p[3];
clrscr();
for(int i=0;i<3;i++)
p[i].accept();
for(i=0;i<3;i++)
p[i].change();
cout<<"\nSTDcode exchangecode phonenumber";
for(i=0;i<3;i++)
p[i].display();
getch();
return 0;
}
/*
enter STD code:-2312
enter exchange code:-6787
enter phone number:-45
enter STD code:-79078
enter exchange code:-456
enter phone number:-67854
enter STD code:-45643
enter exchange code:-222
enter phone number:-456
STDcode exchangecode phonenumber
3312 6787 54
89078 456 76854
55643 222 546
*/
create a class phone having data member:
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 retain as it is.
c) in third part of structure 1st two digit should be reverse
display all changes phone numbers.
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class phone
{
long int std,ex;
char ph[20];
public:void accept()
{
cout<<"\nenter STD code:-";
cin>>std;
cout<<"\nenter exchange code:-";
cin>>ex;
cout<<"\nenter phone number:-";
cin>>ph;
}
void display()
{
cout<<"\n"<<std<<"\t"<<ex<<"\t\t"<<ph;
}
void change();
};
void phone::change()
{
long int ans=0;
int n;
while(std>0)
{
n=std%10;
std=std/10;
if(std==0)
ans=(ans*10)+(n+1);
else
ans=(ans*10)+n;
}
std=0;
while(ans>0)
{
n=ans%10;
ans=ans/10;
std=(std*10)+n;
}
int c=ph[0];
ph[0]=ph[1];
ph[1]=c;
}
int main()
{
phone p[3];
clrscr();
for(int i=0;i<3;i++)
p[i].accept();
for(i=0;i<3;i++)
p[i].change();
cout<<"\nSTDcode exchangecode phonenumber";
for(i=0;i<3;i++)
p[i].display();
getch();
return 0;
}
/*
enter STD code:-2312
enter exchange code:-6787
enter phone number:-45
enter STD code:-79078
enter exchange code:-456
enter phone number:-67854
enter STD code:-45643
enter exchange code:-222
enter phone number:-456
STDcode exchangecode phonenumber
3312 6787 54
89078 456 76854
55643 222 546
*/
No comments:
Post a Comment