用c++语言编写通讯录,不用文件能不能用c++编写

#include

#include

using namespace std;

const int nu=100;

enum Sex{Man,Woman,mid};

class Stuinf{

private:

string Name;

string Num;

enum Sex sex;

int Age;

string Address;

string Phone;

Stuinf *next;

public:

Stuinf(){Name="no name";Num="no num";sex=mid;Age=0;Address="no address";Phone="no phone";next=NULL;}

void setname(){cout>Name;}

string getname(){return Name;}

void setnum(){cout>Num;}

string getnum(){return Num;}

void setsex(){int x;cout>x;sex=(x==0)?Man:Woman;}

string getsex(){return (sex==Man)?"Man":"Woman";}

void setage(){cout>Age;while(!(0>Age;}}

int getage(){return Age;}

void setaddress(){cout>Address;}

string getaddress(){return Address;}

void setphone(){cout>Phone;}

string getphone(){return Phone;}

void setnext(Stuinf *stu){next=stu;}

Stuinf* getnext(){return next;}

~Stuinf(){};

};

int main(){

Stuinf *head=new Stuinf();Stuinf *st[nu];int i;

int n;

cout>n;

while(!(0>n;

}

while(n){

switch (n){

case 1:{

int num;

cout>num;

for(i=0;isetname();

st[i]->setage();

st[i]->setnum();

st[i]->setphone();

st[i]->setaddress();

st[i]->setsex();

st[i]->setnext(head->getnext());

head->setnext(st[i]);

}

break;

}

case 2:{

Stuinf* p;

p=new Stuinf();

p->setname();

p->setage();

p->setnum();

p->setphone();

p->setaddress();

p->setsex();

p->setnext(head->getnext());

head->setnext(p);

break;

}

case 3:{

string number;

cout>number;

Stuinf* p;Stuinf* q;

p=head;

if(head->getnext()==NULL) coutgetnum()!=number){

q=p;

p=p->getnext();

}

if(p->getnext()==NULL)

coutsetnext(p->getnext());

p->~Stuinf();

cout>na;

Stuinf * p=head->getnext();

while(p){

if(p->getname()==na) break;

p=p->getnext();

}

if(p==NULL) coutgetname()getnum()getage()getaddress()getsex()getphone()>na;

Stuinf * p=head->getnext();

while(p){

if(p->getname()==na) break;

p=p->getnext();

}

if(p==NULL) coutsetname();

coutsetnum();

coutsetage();

coutsetaddress();

coutsetsex();

coutsetphone();

cout>n;

}

}。

全部

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值