设计一个电话用户类(Usetele),数据成员为:用户编号id(int),电话号码number(long int,七位,首位不为0和1),用户类型utype(A-公用;B-私用)。成员函数为:构造函数(初始化信息)Usetele(),修改信息modify(),打印信息list(),电话号码的升位处理expand。已有主函数代码如下:
int main(){
Usetele a,b(3,3792345,'A');
Usetele c(b),d(21,4466223,'B'),e(d);
a.list();
a.modify(6,8804455,'A');
a.list();
a.Expand();
d.Expand();
a.list();
d.list();
}
具体要求:
基于输出结果,在类体外实现相应构造函数,并显示构造过程;
在类体外实现成员函数list(),依次输出电话用户信息;
在类体外实现成员函数modify(),依次修改电话用户信息;
在类体外实现成员函数Expand(),实现电话号码升位。升位原则如下:若号码位数大于7位,则不需要进行升位处理;否则,查看号码左边最高位数字:若用户类型为公用电话,且最高位号码位于2-5,则最高位补8;若用户类型为公用电话,且最高位号码位于6-9,则最高位补7;若用户类型为私人电话,且最高位号码位于2-5,则最高位补6;若用户类型为公用电话,且最高位号码位于6-9,则最高位补5.
输入
NULL
输出
Non-parameter constructor called!
Constructor called!
Copy constructor called!
Constructor called!
Copy constructor called!
ID:0
Tele:0
Type:A
6Information modified!
ID:6
Tele:8804455
Type:A
Tele:8804455The new tele is:78804455
Tele:4466223The new tele is:64466223
ID:6
Tele:78804455
Type:A
ID:21
Tele:64466223
Type:B
```c++
#include<bits/stdc++.h>
using namespace std;
class Usetele{
int id;
long int number;
string x;
public:
Usetele();
Usetele(int a,long int b,string c);
Usetele(const Usetele &r);
void list();
void modify(int a,long int b,string c);
void Expand();
};
Usetele::Usetele(){
id=0;
number=0;
x="A";
cout<<"Non-parameter constructor called!"<<endl;
}
Usetele::Usetele(int a,long int b,string c){
id=a;
number=b;
x=c;
cout<<"Constructor called!"<<endl;
}
Usetele::Usetele(const Usetele &r){
id=r.id;
number=r.number;
x=r.x;
cout<<"Copy constructor called!"<<endl;
}
void Usetele::list(){
cout<<"ID:"<<id<<endl;
cout<<"Tele:"<<number<<endl;
cout<<"Type:"<<x<<endl;
}
void Usetele::modify(int a,long int b,string c){
id=a;
number=b;
x=c;
cout<<"6Information modified!"<<endl;
}
void Usetele::Expand(){
cout<<"Tele:"<<number;
int i=0;
int c=number;
do
{
c=c/10;
i++;
}while(c!=0);
int a=number;
for(int j;j<i;j++){
a=a/10;
}
if(i<=7){
if(x=="A"){
if(a>=2,a<=5){
number=number+8*pow(10,i);
}
else if(a>=6,a<=9){
number=number+7*pow(10,i);
}}
if(x=="B"){
if(a>=2,a<=5){
number=number+6*pow(10,i);
}
else if(a>=6,a<=9){
number=number+5*pow(10,i);
}}
cout<<"The new tele is:"<<number<<endl;
}
}
int main(){
Usetele a,b(3,3792345,"A");
Usetele c(b),d(21,4466223,"B"),e(d);
a.list();
a.modify(6,8804455,"A");
a.list();
a.Expand();
d.Expand();
a.list();
d.list();
}
```