选择语句中的函数调用,搞不懂了
#include<iostream>using namespace std;
class WG
{ int No;
char name[10];
long int telphone;
int number;
int homenum;
char time[10];
public:
void setNo(int N)
{
No=N;
};
void setname(char na[])
{
strcpy(name,na);
};
void settelphone(long int t)
{
telphone=t;
};
void setnumber(int n)
{
number=n;
};
void sethomenum(int num)
{
homenum=num;
};
void settime(char ti[])
{
strcpy(time,ti);
};
int getNo()
{
return No;
};
char* getname()
{
return name;
};
long int gettelphone()
{
return telphone;
};
int getnumber()
{
return number;
};
int gethomenum()
{
return homenum;
};
char* gettime()
{
return time;
};
};
/*操作类*/
class compute
{ int FLAG;
int ns;
WG na[10];
int addns;
public:
void getdata();
void disp();
void initdisp();
int usechoice();
void adddate();
void namefind(char cname[10] );
void dispone(int i);
char inputonename();
void tongji();
void huifu();
void change();
void save();
void dele(char cname[10]);
void quit();
compute()
{
ns=0;
}
int getns()
{
return ns;
}
};
//输入住户信息
void compute::getdata()
{
int i,sno;
char tname[10];
char ttime[10];
int num,home;
long int tel;
cout <<" ";
cin>>ns;
for(i=0;i<ns;i++)
{
cout<<"输入住户总数";
cin>>sno;
na[i].setNo(sno);
cout<<"输入姓名";
cin>>tname;
na[i].setname(tname);
cout<<"输入电话号码";
cin>>tel;
na[i].settelphone(tel);
cout<<"输入楼栋号";
cin>>num;
na[i].setnumber(num);
cout<<"输入房间号";
cin>>home;
na[i].sethomenum(home);
cout<<"输入落户时间";
cin>>ttime;
na[i].settime(ttime);
}
}
//初始化界面
void compute::initdisp()
{
cout<<"***********************************************************"<<endl;
cout<<"** 小区物业管理系统 **"<<endl;
cout<<"***********************************************************"<<endl;
cout<<endl;
cout<<"选择操作:"<<endl;
cout<<"1.输入住户信息"<<endl;
cout<<"2.添加住户信息"<<endl;
cout<<"3.查找住户信息"<<endl;
cout<<"4.修改住户信息"<<endl;
cout<<"5.读取住户信息"<<endl;
cout<<"6.删除住户信息"<<endl;
cout<<"7.恢复住户信息"<<endl;
cout<<"8.保存住户信息"<<endl;
cout<<"9.统计"<<endl;
cout<<"0.退出"<<endl;
}
//显示
void compute::disp()
{
cout<<"\t"<<"姓名"<<"\t"<<"电话号码"<<"\t"<<"楼栋号"<<"\t"<<"房间号"<<"\t"<<"落户时间"<<endl;
for( int i=0;i<ns;i++)
{
cout<<"\t"<<na[i].getname()<<"\t"<<na[i].gettelphone()<<"\t"<<na[i].getnumber()<<"\t"<<na[i].gethomenum()<<"\t"<<na[i].gettime()<<endl;
}
}
//添加数据
void compute::adddate()
{
int i,sno;
char tname[10];
char ttime[10];
int num,home;
long int tel;
WG na[20];
if(ns==0)
{
cout<<"请选择1添加数据,然后在选择2增加记录"<<endl;
return ;
}
cout <<"输入要添加的人数:";
cin>>addns;
for(i=0;i<addns;i++)
{
cout<<"输入住户总数";
cin>>sno;
na[ns+i].setNo(sno);
cout<<"输入姓名";
cin>>tname;
na[ns+i].setname(tname);
cout<<"输入电话号码";
cin>>tel;
na[ns+i].settelphone(tel);
cout<<"输入楼栋号";
cin>>num;
na[ns+i].setnumber(num);
cout<<"输入房间号";
cin>>home;
na[ns+i].sethomenum(home);
cout<<"输入落户时间";
cin>>ttime;
na[ns+i].settime(ttime);
}
ns=ns+addns;
}
//按姓名查找
void compute::namefind(char cname[])
{
int i;
for(i=0;i<ns;i++)
{ if(na[i].getname()==cname)
{
dispone(i);
}
}
if(i>=ns)
{
cout<<"没有您要查找的记录"<<endl;
}
}
void compute::dispone(int i)
{
cout<<"\t"<<"姓名"<<"\t"<<"电话号码"<<"\t"<<"楼栋号"<<"\t"<<"房间号"<<"\t"<<"落户时间"<<endl;
cout<<"\t"<<na[i].getname()<<"\t"<<na[i].gettelphone()<<"\t"<<na[i].getnumber()<<"\t"<<na[i].gethomenum()<<"\t"<<na[i].gettime()<<endl;
}
char compute::inputonename ()
{
char cname[10];
cout<<"请输入要查找的住户姓名";
cin>>cname;
return cname[10];
}
//删除记录
void compute::dele (char cname[])
{
int cunt,i,flag=0;
for (i=0;i<ns;i++)
{
if(na[i].getname()==cname )
{
cunt=i;
flag=1;
}
else
{
cout<<"输入错误,请重新输入!"<<endl;
return ;
}
}
for(i=cunt;i<ns-1;i++)
{
na[i].setname(na[i+1].getname());
na[i].settelphone (na[i+1].gettelphone ());
na[i].setnumber(na[i+1].getnumber());
na[i].sethomenum(na[i+1].gethomenum());
na[i].settime(na[i+1].gettime());
}
ns=ns-1;
}
//退出系统
void compute::quit ()
{
FLAG=0;
cout<<"程序即将关闭!"<<endl;
_sleep(1000);
_sleep(1000);
_sleep(1000);
return ;
}
//主函数
void main()
{
compute obj;
int opt;
while(1)
{ obj.initdisp ();
opt=obj.usechoice ();
switch(opt)
{
case 1:
cout<<"==================================================="<<endl;
obj.getdata ();
cout<<"==================================================="<<endl;
break;
case 2:
cout<<"==================================================="<<endl;
obj.adddate ();
cout<<"==================================================="<<endl;
break;
case 3:
cout<<"==================================================="<<endl;
char c_name[10];
c_name=obj.inputonename (); ???//这里怎么弄都是错,应该怎么改,
obj.namefind (c_name);
cout<<"==================================================="<<endl;
break;
case 4:
cout<<"==================================================="<<endl;
obj.change ();
cout<<"==================================================="<<endl;
break;
case 5:
cout<<"==================================================="<<endl;
obj.disp ();
cout<<"==================================================="<<endl;
break;
case 6:
cout<<"==================================================="<<endl;
obj.dele ();
cout<<"==================================================="<<endl;
break;
case 7:
cout<<"==================================================="<<endl;
obj.huifu ();
cout<<"==================================================="<<endl;
break;
case 8:
cout<<"==================================================="<<endl;
obj.save ();
cout<<"==================================================="<<endl;
break;
case 9:
cout<<"==================================================="<<endl;
obj.tongji ();
cout<<"==================================================="<<endl;
break;
case 0:
cout<<"==================================================="<<endl;
obj.quit();
cout<<"==================================================="<<endl;
break;
default :
cout<<"==================================="<<endl;
cout<<"选择错误,谢谢!"<<endl;
cout<<"==================================="<<endl;
}
}
}