通讯录管理系统的设计与实现c++源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

通讯录管理系统的设计与实现源代码
#include <iostream>
#include <string>
#include <fstream>
#include<iomanip>
using namespace std;
struct Student
{
string num;//学号
string name;//姓名
int age;
char tel;
char addr;
char emal;
Student *next;
} ;
long iCount=0;
Student *head=NULL;
Student *pEnd=NULL;
void LoadRecords(char *path)//从文本里面读取记录{
fstream infile(path,ios::in);
if(!infile){}
else
{
infile>>iCount;
int t=iCount;
if(iCount!=0)
{
for(;iCount>0;iCount--)
{
Student *p=new Student;
infile>>p->num>>p->name>>p->Maths;
if(head==NULL)
{
head=p;pEnd=p;pEnd->next=NULL;
}
else
{
pEnd->next=p;
pEnd=pEnd->next;
pEnd->next=NULL;
}
}
}
iCount=t;
}
infile.close();
}
void Print(Student *h)//打印记录
{
if(h==NULL)
{
cout<<"\n****************************************\n\n";
cout<<"没有学生记录!\n";
cout<<"\n****************************************\n";
return;
}
cout<<"\n************************************************************ ********************\n\n";
cout<<"所有的学生:\n\n";
cout<<" ------------------------------------------\n";
cout<<"| "<<setw(10)<<"学号"
<<"| "<<setw(10)<<"姓名"
<<"| "<<setw(10)<<"年龄"<<"| "<<setw(10)<<"电话""| "<<
<< setw(10)<<"地址"<<"| "<< setw(10)<<"邮箱"<<" | \n"; while(h)
{
cout<<" ------------------------------------------\n";
cout<<"| "<<setw(10)<<h->num<<"| "<<setw(10)<<h->name <<"| "<<setw(10)<<h->age<<"| "<<setw(10)<<h->tel
<<"| "<<setw(10)<<h->addr<<"| "<<setw(10)<<h->emal<<" |\n";
h=h->next;
}
cout<<" ------------------------------------------\n";
cout<<"\n************************************************************ ********************\n\n";
}
void Print_All(Student *h)//输出全部
{
if(h==NULL){cout<<"\n****************************************\n";cout <<"没有学生记录!\n";cout<<"\n****************************************\n";return;} cout<<"\n************************************************************ ********************\n";
cout<<"所有学生:\n\n";
cout<<" ------------------------------------------\n";
cout<<"| "<<setw(10)<<"学号"
<<"| "<<setw(10)<<"姓名"
<<"| "<<setw(10)<<"年龄"<<"| "<<setw(10)<<"电话"
<<"| "<<setw(10)<<" 地址"<<"| "<<setw(10)<<"邮箱"<<" | \n"; for{h->number=1;h->number++}
{
cout<<" ------------------------------------------\n";
cout<<"| "<<setw(10)<<h->num<<"| "<<setw(10)<<h->name <<"| "<<setw(10)<<h->age<<"| "<<setw(10)<<h->tel
<<"| "<<setw(10)<<h->addr<<"| "<<setw(10)<<h->emal<<" |\n";
h=h->next;
}
cout<<" ------------------------------------------\n";
cout<<"\n************************************************************ ********************\n\n";
}
void Print_search(Student *h)//查询
{
if(h==NULL){cout<<"\n************************************************ ********************************\n";cout<<"没有学生记录!\n";cout<<"\n****************************************\n";return;} cout<<"\n************************************************************ ********************\n";
cout<<"所查学生:\n\n";
cout<<" ------------------------------------------\n";
cout<<"| "<<setw(10)<<"学号"
<<"| "<<setw(10)<<"姓名"
<<"| "<<setw(10)<<"年龄"<<"| "<<setw(10)<<"电话"
<<"| "<<setw(10)<<" 地址"<<"| "<<setw(10)<<"邮箱"<<" | \n"; while(h)
{
if(h->number=i)
{
cout<<" ------------------------------------------\n";
cout<<"| "<<setw(10)<<h->num<<"| "<<setw(10)<<h->name <<"| "<<setw(10)<<h->age<<"| "<<setw(10)<<h->tel
<<"| "<<setw(10)<<h->addr<<"| "<<setw(10)<<h->emal<<" |\n";
}
h=h->next;
}
cout<<" ------------------------------------------\n";
cout<<"\n************************************************************ ********************\n\n";
}
void Add(Student *s)
{
if(pEnd==NULL){head=s;pEnd=s;s->next=NULL;}
else{pEnd->next=s;pEnd=s;pEnd->next=NULL;}
cout<<"\n==================================================\n";cout<< s->name<<" 的资料添加完毕!\n";cout<<"==================================================\n"; iCount++;
}
void main()
{
LoadRecords("c:\\test.txt");
int n;
cout<<"\n************************************************************ ********************\n";
cout<<"[1] 增加一个学生\n"
<<"[2] 显示所有的学生以及他们的成绩\n"
<<"[3] 显示数组中学号为I的学生信息\n"
<<"[4] 存盘并退出\n";
cout<<"************************************************************** ******************\n\n";
cout<<"请选择操作项:[1-5] ";
cin>>n;
while(1)
{
switch (n)
{
case 1:
{
Student *p=new Student;
cout<<"\n*************************************************** *****************************\n\n";
cout<<"请输入内容:"<<endl;
cout<<"学号\t\t姓名\t\t年龄\ t\t电话\ t\t地址\ t\t邮箱\n";
cin>>p->num>>p->name>>p->age>>p->tel>>p->addr>>p->emal;Add(p );
break;
}
case 2:
Print(head);break;
case 3:
Print_search(head);break;
case 4:
{
fstream outfile("c:\\test.txt",ios::out);
if(!outfile){}
else
{
outfile<<iCount<<" ";
while(head)
{
outfile<<head->num<<" "<<head->name<<" "<<head->Maths<<" ";
head=head->next;
}
}
outfile.close();
cout<<"\n==================================================\ n";
cout<<"再见"<<endl;
cout<<"==================================================\n\ n";
return;
}
default:
cout<<"\n==================================================\ n";
cout<<"无效输入"<<endl;
cout<<"==================================================\n\ n";
}
cout<<"***************按任意键继续***************\n";
getchar();getchar();system("cls");
//if(n>=1&&n<=5)
{
cout<<"\n***************************************************** ***************************\n";
cout<<"[1] 增加一个学生\n"
<<"[2] 显示所有的学生以及他们的成绩\n"
<<"[3] 显示数组中平均成绩<40的学生以及他们的成绩\n"
<<"[4] 显示数组中学号为I的学生信息\n"
<<"[5] 存盘并退出\n";
cout<<"******************************************************* *************************\n\n";
cout<<"请选择操作项:[1-5] ";
cin>>n;
}
}
}。

相关文档
最新文档