中易网

求大神帮注释一下这个程序,拜托了

答案:1  悬赏:10  
解决时间 2021-04-28 17:58
  • 提问者网友:✐ۖ﹏ℳ๓北风
  • 2021-04-27 19:03
求大神帮注释一下这个程序,拜托了
http://zhidao.baidu.com/question/2012087793890112028.html
最佳答案
  • 二级知识专家网友:爱情是怎么炼成的
  • 2021-04-27 20:16
// 通讯录.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>  
#include <iostream> 

using namespace std;

class Contact_person      
{  
    private:  
        int ID;//该联系人的数字编号    
        string name;   //姓名
string tel;    //手机号
string remark;//remark为备注  
    public: 
        void assign(int id,string n,string t,string r)
{  
            ID=id;  
            name=n;  
            tel=t;  
            remark=r;  
        }  
void print()  
{  
            cout<< "名字  :" << name << endl;  
            cout<< "电话  :" << tel << endl;  
            cout<< "备注  :" << remark << endl;  
        }
string getName()
{
return name;  //返回姓名
}
string getTel()
{
return tel;   //返回手机号
}
string getRemark()
{
return remark;  //返回备注
}
}; 

class System{            
private:
Contact_person p[100];
int count;
public:
System();
void add();
void showAll();
void searchName();
void searchTel();
void Updata();
void Delete();
};

System::System()
{
for(int i=0;i<100;i++)
{
p[i].assign(0,"0","0","0");
}
count=0;
}

void System::add()
{
string name,tel,remark;  
cout << "请输入电话" << endl;  
    cin >> tel;
for(int i=0;i<count;i++)
{
if(p[i].getTel()==tel)
return;   //如果号码相同,就结束该函数
}
    cout << "请输入联系人姓名" << endl;  
    cin >> name;  

    cout << "请输入备注"<< endl;  
    cin >> remark;
p[count].assign(count,name,tel,remark);
count++;
}

void System::showAll()
{
for(int i=0;i<count;i++)
{
p[i].print();  //打印通讯录信息
}
}

void System::searchName()
{
string Name;
cout<<"请输入名字:";
cin>>Name;
for(int i=0;i<count;i++)
{
if(p[i].getName()==Name)
{
p[i].print();  
}
}
}

void System::searchTel()
{
string Tel;
cout<<"请输入电话号码:";
cin>>Tel;
for(int i=0;i<count;i++)
{
if(p[i].getTel()==Tel)
{
p[i].print();  
}
}
}

void System::Updata()  
{
char UpdataOption;
string Name;
string Tel;
string Remark;
cout<<"请输入修改的名字:";
cin>>Name;
for(int i=0;i<count;i++)
{
if(p[i].getName()==Name)  //查找到要更新信息的成员
{
p[i].print();
cout<<"是否更改(Y/C/N)(YES/CANCEL/NEXT)";
cin>>UpdataOption;
if (UpdataOption == 'Y' || UpdataOption == 'y')  
{
bool Flags=true;
while(Flags)
{
int Option;
cout<<"1.修改姓名"<<endl
<<"2.修改电话号码"<<endl
<<"3.修改备注"<<endl
<<"4.全部修改"<<endl
<<"5.退出"<<endl;
cout<<"请输入修改指令:";
cin>>Option;
switch(Option)
{
case 1:
cout << "请输入联系人姓名" << endl;  
cin >> Name;
p[i].assign(i,Name,p[i].getTel(),p[i].getRemark());
break;
case 2:
cout << "请输入电话" << endl;  
cin>>Tel;
p[i].assign(i,p[i].getName(),Tel,p[i].getRemark());
break;
case 3:
cout << "请输入备注"<< endl;  
cin>>Remark;
p[i].assign(i,p[i].getName(),p[i].getTel(),Remark);
break;
case 4:
cout << "请输入联系人姓名" << endl;  
cin >> Name;
cout << "请输入电话" << endl;  
cin>>Tel;
cout << "请输入备注"<< endl;  
cin>>Remark;
p[i].assign(i,Name,Tel,Remark);
break;
case 5:
Flags=false;
break;
default:
break;
}
}
}
else if (UpdataOption == 'N' || UpdataOption == 'n')  
{
continue;
}
else
{
return;  //输入其他直接结束该函数
}
}
}
}

void System::Delete()  
{
string Tel;
char DeleteOption;
cout<<"请输入电话号码:";
cin>>Tel;
for(int i=0;i<count;i++)
{
if(p[i].getTel()==Tel)
{
p[i].print();
cout<<"是否删除(Y/N):";
cin>>DeleteOption;
if(DeleteOption=='Y'||DeleteOption=='y')
{
for(int j=i;j<count;j++)
{
p[j].assign(j,p[j+1].getName(),p[j+1].getTel(),p[j+1].getRemark());
}
count--;
}
else
{
break;
}
}
}
}

int main(int argc, char* argv[])  
{
int option;
System *s=new System();
while(1)
{
cout << "***********************************" << endl;     
        cout<<"1 . 新建联系人" << endl;  
        cout<<"2 . 查找联系人" << endl;
cout<<"3 . 更改联系人" << endl;
cout<<"4 . 显示联系人" << endl;
cout<<"5 . 删除联系人" << endl;
        cout<<"6 . 退出" << endl ;  
        cout<<"  请输入指令:" << endl;  
        cout<<"***********************************" << endl; 
cin>>option;
switch(option)  //选择相应功能
{
case 1:
s->add();
break;
case 2:
int SearchOption;
cout<<"1.按姓名找"<<endl;
cout<<"2.电话号码查找"<<endl;
cout<<"请输入指令"<<endl;
cin>>SearchOption;
switch(SearchOption)
{
case 1:
s->searchName();
break;
case 2:
s->searchTel();
break;
default:
break;
}
break;
case 3:
s->Updata();
break;
case 4:
s->showAll();
break;
case 5:
s->Delete();
break;
case 6:
return 0;
default:
break;
}
}
return 0;
}希望能让你满意。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息