#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<conio.h>
#include<Windows.h>
//#include<windows.h>
using namespace std;
string ID;//具有唯一性
class Person
{
protected:
string No; //学号
string Age;//年龄
string QQ;//QQ号码
char Name[20]; //姓名
char Sex[10]; //性别
string Tel; //电话号码
char domitory[25];//宿舍
char canteen[25];//最喜欢的食堂
char sports[100];//最喜欢的运动
char subject[50];//最喜欢的科目
Person *next;
public:
Person(string ID,char *Name,char*Sex,string Age,string Tel,char*domitory,string QQ,char*canteen,char*sports,char*subject)
{
strcpy(this->Name,Name);
strcpy(this->Sex,Sex);
this->QQ=QQ;
strcpy(this->domitory,domitory);
strcpy(this->canteen,canteen);
strcpy(this->sports,sports);
strcpy(this->subject,subject);
this->Tel=Tel;
this->No=ID;
this->Age=Age;
}
friend class Manage;
};
class Manage
{
private:
Person *person;
public:
Manage()
{
person=0;
Load();
}
~Manage()
{
Person *p;
p=person;
while(p)
{
p=p->next;
delete person;
person=p;
}
person=0;
}
void Find(char Name[20]);//按姓名查找
void Find(string ID);//按编号查找
void Add(); //加入加信息
void Delete(); //删除信息
void Modify(string ID); //改动信息
void Query(); //查询信息
void TJ(); //清除文件信息
void Save(); //保存数据
void Load(); //读入数据
void Look();//预览
void DesTory();
void Output(Person *p)
{
cout<<"\t\t【 学号 】:"<<p->No<<endl;
cout<<"\t\t【 姓名 】:"<<p->Name<<endl;
cout<<"\t\t【 性别 】:"<<p->Sex<<endl;
cout<<"\t\t【 年龄 】:"<<p->Age<<endl;
cout<<"\t\t【 联系电话 】:"<<p->Tel<<endl;
cout<<"\t\t【 QQ号码 】:"<<p->QQ<<endl;
cout<<"\t\t【 宿舍地址 】:"<<p->domitory<<endl;
cout<<"\t\t【最喜欢的饭堂】:"<<p->canteen<<endl;
cout<<"\t\t【最喜欢的科目】:"<<p->subject<<endl;
cout<<"\t\t【最喜欢的运动】:"<<p->sports<<endl;
cout<<endl;
}
};
void Manage::Add()
{
system("cls");
Person *p,*p2; //新结点指针
string No,Age,Tel,QQ;
char Name[20],Sex[10],domitory[25],canteen[25],sports[100],subject[50];
char c;
cout<<"\n\t ◆ 新增学生通讯录 ◆\n";
cout<<"================================================"<<endl;
//输入学生信息
cout<<"输入学号: \t";
cin>>No;
cout<<endl;
{
Person *p1;
p1=person;
while(p1)
{
if(p1->No==No)
{
break;
}
else
{
p1=p1->next;
}
}
if(p1!=NULL)
{
cout<<"该学号已存在,是否改动该学生信息(Y/N) "<<endl;
cin>>c;
if(toupper(c)=='Y')
{
cout<<"该学生信息为:"<<endl;
Find(No);
cout<<endl;
Modify(No);
return ;
}
else
return ;
}
}
cout<<"输入姓名: \t";
cin>>Name;
cout<<endl;
cout<<"输入性别: \t";
cin>>Sex;
cout<<endl;
cout<<"输入年龄: \t";
cin>>Age;
cout<<endl;
cout<<"输入QQ号码: \t";
cin>>Tel;
cout<<endl;
cout<<"输入宿舍地址: \t";
cin>>domitory;
cout<<endl;
cout<<"输入最喜欢的饭堂:\t";
cin>>canteen;
cout<<endl;
cout<<"输入最喜欢的科目:\t";
cin>>subject;
cout<<endl;
cout<<"输入最喜欢的体育运动:\t";
cin>>sports;
cout<<endl;
p=new Person(No,Name,Sex,Age,Tel,domitory,QQ,canteen,sports,subject);
p->next=0;
//学生结点加入链表
if(person) //若已经存在结点
{
p2=person;
while(p2->next) //查找尾结点
{
p2=p2->next;
}
p2->next=p; //连接
}
else //若不存在结点(表空)
{
person=p; //连接
}
system("cls");
cout<<"\t\t\t【联系人已成功加入】\n"<<endl;
cout<<"\t\t是否继续加入联系人?(Y/N) "<<endl;
cin>>c;
if(toupper(c)=='Y')
{
Add();
return ;
}
else
return ;
}
void Manage::Delete() //删除人员
{
system("cls");
char c;
string No;
cout<<"\n\t◆ 删除信息 ◆\n";
cout<<"===================================================";
cout<<"输入要删除的学生ID:\t";
cin>>No;
cout<<endl;
//查找要删除的结点
Person *p1,*p2;
p1=person;
while(p1)
{
if(p1->No==No)
break;
else
{
p2=p1;
p1=p1->next;
}
}
//删除结点
if(p1!=NULL)//若找到结点,则删除
{
cout<<"所要删除的学生的信息例如以下:\n"<<endl;
Output(p1);
cout<<"确定是否删除(Y/N): ";
cin>>c;
if(toupper(c)!='Y')
return;
// system("pause");
if(p1==person) //若要删除的结点是第一个结点
{
person=p1->next;
delete p1;
}
else //若要删除的结点是兴许结点
{
p2->next=p1->next;
delete p1;
}
cout<<"\t\t【联系人已成功删除】\n";
cout<<"是否继续删除(Y/N) "<<endl;
cin>>c;
if(toupper(c)=='Y')
{
Delete();
return ;
}
else
return ;
}
else //未找到结点
cout<<"\n\t\tOops!系统未能找到该同学\n";
getch();//等待按下随意键继续
}
void Manage::Modify(string ID)
{
Person *p1;
char c;
p1=person;
while(p1)
{
if(p1->No==ID)
break;
else
{
p1=p1->next;
}
}
if(p1!=NULL)//若找到结点
{
system("cls");
cout<<"所要改动的学生的信息例如以下:\n"<<endl;
Output(p1);
do
{
cout<<"1.改动姓名 2.改动性别 3 改动年龄\n"<<endl;
cout<<"4.改动电话号码 5.改动宿舍地址 6.改动QQ号码\n"<<endl;
cout<<"7.改动最喜欢饭堂 8.改动最喜欢运动 9.改动最喜欢科目\n"<<endl;
cout<<"0.退出改动\n"<<endl;
cout<<"请选择(0-9)要改动的信息:\n"<<endl;
cin>>c;
if(c!='0')
cout<<"请输入新的信息: ";
switch(c)
{
case '1': cin>>p1->Name; break;
case '2': cin>>p1->Sex; break;
case '3': cin>>p1->Age; break;
case '4': cin>>p1->Tel; break;
case '5': cin>>p1->domitory; break;
case '6': cin>>p1->QQ; break;
case '7': cin>>p1->canteen; break;
case '8': cin>>p1->sports; break;
case '9': cin>>p1->subject; break;
default: break;
}
}while(c!='0');
system("cls");
cout<<"\t 【联系人已成功改动】\n"<<endl;
cout<<"是否继续改动(Y/N): "<<endl;
cin>>c;
if(toupper(c)=='Y')
{
cout<<"请输入要改动人员的ID: ";
cin>>ID;
cout<<endl;
Modify(ID);
return ;
}
else
return ;
}
else //未找到结点
cout<<"未找到该学生!\n";
getch();//暂停(会等待你按下随意键,再继续运行以下的语句;)
}
void Manage::Save() //数据写入到文件
{
ofstream fPerson("Person.txt",ios::out);
char c;
cout<<"\n【将要保存数据,是否继续?】[Y/N]:";
cin>>c;
if(toupper(c)!='Y')
return;
Person *p=person;
while(p)
{
fPerson<<p->No<<" "<<p->Name<<" "<<p->Sex<<" "<<p->Age<<" "<<p->Tel<<" "<<p->domitory<<" "<<p->QQ<<" "<<p->canteen<<" "<<p->sports<<" "<<p->subject<<endl;
p=p->next;
}
fPerson.close();
cout<<"\n【已成功保存数据】\n";
system("pause");
}
void Manage::Load() //数据读入
{
ifstream fPerson;
Person *p=person;
string No,Age,Tel,QQ;
char Name[20],Sex[10],domitory[25],canteen[25],sports[100],subject[50];
fPerson.open("person.txt",ios::in);
fPerson>>No>>Name>>Sex>>Age>>Tel>>domitory>>QQ>>canteen>>sports>>subject; while(fPerson.good())//文件打开成功时
{
p=new Person(No,Name,Sex,Age,Tel,domitory,QQ,canteen,sports,subject);
p->next=0;
//结点加入链表
if(person) //若已经存在结点
{
Person *p2;
p2=person;
while(p2->next) //查找尾结点
{
p2=p2->next;
}
p2->next=p; //连接
}
else //若不存在结点(表空)
{
person=p; //连接
}
fPerson>>No>>Name>>Sex>>Age>>Tel>>domitory>>QQ>>canteen>>sports>>subject;
}
fPerson.close();
}
void Manage::Find(string ID)
{
Person *p1;
p1=person;
while(p1)
{
if(p1->No==ID)
break;
else
{
p1=p1->next;
}
}
if(p1!=NULL)
{
Output(p1);
}
else
cout<<"\n\t\tOops!系统未能找到该同学\n"<<endl;
} void Manage::Find(char Name[20])
{
Person *p1;
int count=0;
p1=person;
while(p1)
{
if(strcmp(p1->Name,Name)==0)
{
count++;
Output(p1);
}
p1=p1->next;
}
if(count)
{
cout<<"\t●查询结果例如以下:●"<<endl;
cout<<"\n系统共为您找到了 "<<count<<" 个名字为 ★"<<Name<<"★ 的同学\n"<<endl;
}
else
cout<<"\n\t\tOops!系统未能找到该同学\n"<<endl;
}
void Manage::Query()
{
char c;
string ID,Tel,QQ;
char Name[20];
do{
cout<<"1.按学号查找 2.按名字查找 3.按电话号码查找 4.按QQ查找 5.退出查找"<<endl;
cin>>c;
// system("cls");
cout<<endl;
switch(c)
{
case '1': {
cout<<"输入学号 ID: ";
cin>>ID;
Find(ID);
}; break;
case '2': {
cout<<"输入姓名 Name: ";
cin>>Name;
Find(Name);
}; break;
case '3': {
cout<<"输入电话号码 Tel:"<<endl;
cin>>Tel;
Find(Tel);
};break;
case '4': {
cout<<"输入QQ号码 QQ:"<<endl;
cin>>QQ;
Find(QQ);
};break;
case '5':break;
default: cout<<"Oops! 输入有误 请又一次输入...\n"<<endl;
}
}while(c!='1'&&c!='2'&&c!='3'&&c!='4'&&c!='5');
cout<<"\t\t\t 【查找成功】\n"<<endl;
cout<<"是否继续查找?(Y/N) "<<endl;
cin>>c;
if(toupper(c)=='Y')
{
Query();
return ;
}
else
return ;
system("pause");
}
void Manage::Look()
{
//设置字体颜色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_BLUE);
system("cls");
Person *p1;
int count=0;
char c;
p1=person;
while(p1)
{
cout<<"学号: "<<p1->No<<"\t姓名: "<<p1->Name<<endl;
count++;
p1=p1->next;
}
if(count!=0)
{
cout<<"\n\t【预览信息载入成功!】 \n"<<endl;
cout<<"是否查询具体信息?(Y/N): ";
cin>>c;
if(toupper(c)=='Y')
{
Query();
return;
}
else
return ;
}
else
{
cout<<"Oops! 尚未创建通讯录,是否如今创建?(Y/N)"<<endl;
cin>>c;
if(toupper(c)=='Y')
{
Add();
return;
}
else
return ;
}
}
void Manage::DesTory()
{ //设置字体为红色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED);
char c;
system("cls");
cout<<"\n\t\t\t ◆清除信息◆ \n"<<endl;
cout<<"=============================================================="<<endl;
cout<<"\t\t\t ※警告※\n\n\t清除通讯录信息会导致全部已保存的信息全然丢失!!!\n"<<endl;
cout<<"★是否决定清除全部通讯录信息?★(Y/N): "<<endl;
cin>>c;
if(toupper(c)!='Y')
return;
cout<<"★您确认要清楚全部通讯录信息吗?★(Y/N)"<<endl;
cin>>c;
if(toupper(c)!='Y')
return;
else
{
Person *p;
p=person;
while(p)
{
p=p->next;
delete person;
person=p;
}
person=0;
// ofstream fPerson("person.txt");
// fPerson.close();
}
system("pause");
}
void Manage::TJ()
{
Person *p1;
int count=0,Boy=0,Girl=0;
p1=person;
while(p1)
{
count++;
if(strcmp(p1->Sex,"男")==0)
Boy++;
if(strcmp(p1->Sex,"女")==0)
Girl++;
p1=p1->next;
}
cout<<"通讯录内共同拥有 "<<count<<"人\n"<<endl;
cout<<"男生: "<<Boy<<"人"<<endl<<"女生: "<<Girl<<"人"<<"\n"<<endl;
system("pause");
}
int main(void)
{
Manage m;
int c;
do
{
//设置字体为绿色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_GREEN);
system("cls");
cout<<" ★ 通讯录系统 ★ "<<endl;
cout<<"============================================================================="<<endl;
cout<<" ( ̄3 ̄)│ 【 1.新增通讯录 】│ ◢◣ ◢◣。 ◢◣ ☆圣★"<<endl;
cout<<" │ │ ◢★◣ ◢★◣。 ◢★◣ ★诞☆"<<endl;
cout<<" (╯_╰)│ 【 2.删除名单 】│ ◢■■◣ ◢■■◣。 ◢■■◣ ☆节★"<<endl;
cout<<" │ │◢■■■◣ ◢■■■◣。◢■■■◣ ★快☆"<<endl;
cout<<" (⊙_⊙)│ 【 3.改动名单 】│︸︸||︸︸ ︸︸||︸︸ ︸︸||︸︸ ☆乐★"<<endl;
cout<<" │ │"<<endl;
cout<<" ( -﹏-)│ 【 4.查询具体信息 】││\__╭╭╭╭╭__/│"<<endl;
cout<<" │ ││           │ "<<endl;
cout<<" (∩_∩)│ 【 5.保存数据 】││           │ ╭─────╮"<<endl;
cout<<" │ ││           │ │ 欢迎使用通 │"<<endl;
cout<<" (≧o≦)│ 【 6.预览信息 】││ ≧       ≦ │< 讯录,请按数│"<<endl;
cout<<" │ ││ ≡ ╰┬┬┬╯ ≡ │ │ 字提示操作!│"<<endl;
cout<<" (〒_〒)│ 【 7.清空名单 】││    ╰─╯    │ ╰──────╯"<<endl;
cout<<" │ │╰──┬O───O┬──╯"<<endl;
cout<<" (→_→)│ 【 8.人数统计 】│ │ ╬ │"<<endl;
cout<<" │ │ ╰┬───┬╯ ──Made by George.S"<<endl;
cout<<" (ㄒoㄒ)│ 【 0.退出系统 】│ SYSU-CS-Class2"<<endl;
cout<<"============================================================================="<<endl;
cout<<"请输入对应数字选择(1-8): ";
cin>>c;
switch(c)
{
case 1: m.Add(); break;
case 2: m.Delete();break;
case 3: {
system("cls");
cout<<"请输入要改动人员的ID: ";
cin>>ID;
cout<<endl;
m.Modify(ID);
};break;
case 4: {
system("cls");
m.Query();
}; break;
case 5: m.Save(); break;
case 6: m.Look(); break;
case 7: m.DesTory(); break;
case 8: m.TJ(); break;
default: break;
}
}while(c!=0);
char s;
cout<<"\n【是否要保存您的全部操作?】(Y/N): "<<endl;
cin>>s;
if(toupper(s)=='Y')
m.Save();
return 0;
}

通讯录C++console application的更多相关文章

  1. 如何将Console application的Program函数变成支持async的?

    如何将Console application的Program函数变成支持async的?   class Program { static void Main(string[] args) { Task ...

  2. win32 console application 如何修改图标?

    win32 console application ,不要看这名字高端大气上档次,让你摸不着头脑,其实他就是我们最先学习c语言那种黑色窗口的东西......话说他怎么修改图标呢?第一种方法是:右键-〉 ...

  3. Hello World 之 控制台版本(Console Application)

    原文:Hello World 之 控制台版本(Console Application) 先来介绍下Hello, World   "Hello, World"程序指的是只在计算机屏幕 ...

  4. RESTful Console Application

    RESTful Console Application Introduction Inspirited by RESTFul architecture, A console application t ...

  5. Using Spring.net in console application

    Download Spring.net in http://www.springframework.net/ Install Spring.NET.exe Create a console appli ...

  6. Fix Visual Studio 2013 Razor CSHTML Intellisense in Class Library or Console Application

    https://mhusseini.wordpress.com/2015/02/05/fix-visual-studio-2013-razor-cshtml-intellisense-in-class ...

  7. C# 控制台程序(Console Application )启动后隐藏

    背景 前段时间给项目编写了数据适配器,读取其他系统的数据后推送到MQ上,我们的系统通过订阅MQ的方式来获取.由于其他系统支持C#编程,且为了一时方便,选择了C#的控制台程序. 最近用户在使用中,总是不 ...

  8. .NET 如何隐藏Console Application的窗口

    1)创建Console Application工程 2)修改Output type 为Windows Application即可

  9. VS2015 create a C++ console application based on WinRT

    1. Enable /ZW 2. Disable /Gm 3. #using C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcpack ...

随机推荐

  1. 【C语言探索之旅】 第二部分第八课:动态分配

    内容简介 1.课程大纲 2.第二部分第八课: 动态分配 3.第二部分第九课预告: 实战“悬挂小人”游戏 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语言 ...

  2. hdu 1226 BFS + bfs记录路径

    http://acm.hdu.edu.cn/showproblem.php? pid=1226 为了节省空间.您可以使用vis初始化数组初始化-1. 发现BFSeasy错了地方 始一直WA在这里:就是 ...

  3. 使用jquery点击一个实现button或连接,进行以下div显示,在点击隐藏

    jquery代码: <script type="text/javascript" src="js/jquery-1.7.2.js"></scr ...

  4. 使用SQLServer Audit来监控触发器的启用、禁用情况

    原文:使用SQLServer Audit来监控触发器的启用.禁用情况 使用情景: 有时候会发现在触发器中的业务逻辑没有执行,可能是因为触发器的逻辑错误所引起的.但是有时候却是因为一些触发器被禁用了. ...

  5. datatable1.9 与datatable1.10以数据差异

    我还探讨datatable1.10新用途,如果在下面的代码中的错误,欢迎.. 1.10与1.9解释官方网站之间的差异:http://www.datatables.net/upgrade/1.10 看代 ...

  6. Cocos2d-x Auto-batching 浅浅的”深入分析”

    Auto-batching是Cocos2d-x3.0新增的特性,目的是为了代替SpriteBatchNode,完毕渲染的批处理,提高绘制效率. 至于它有什么特点,能够看看官方文档,这里主要想探讨Aut ...

  7. 云盘+Git GUI云盘文件版本控制

    以下介绍操作细节 1.先下载Git GUI 下载地址:http://msysgit.github.io/ 再下载百度云网盘 下载地址:http://pan.baidu.com 接下来就是安装这两个软件 ...

  8. WPF学习(5)依赖属性

    今天我们来学习WPF一个比较重要的概念:依赖属性.这里推荐大家看看周永恒大哥的文章,讲的确实很不错.我理解的没那么深入,只能发表一下自己的浅见.提到依赖属性,不得不说我们经常使用的传统的.net属性, ...

  9. XCL-Charts画一个图(CurveChart)

    情节线图与往常不同的是,它是一个比较特殊线位置计算.所以我得到一个单独的类.相同.只需要输入数据源的基类, 加,控制要添加的.你可以画出你自己主动设置按照预期的效果. 代码: //图基类 chart ...

  10. 高性能mysql主存架构

    原文:高性能mysql主存架构 MySQL Replication(Master与Slave基本原理及配置) 主从mysql工作原理: 1:过程: (1)Mysql的复制(replication)是一 ...