#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. Apple Watch 1.0 开发介绍 1.2 简介 配置Xcode工程

    WatchKit app需要一个现有的iOS app.在iOS app工程中,添加一个新的WatchKit app target,它包含了WatchKit app和WatchKit extension ...

  2. SQL Server 开发利器 SQL Prompt 6.5 T-SQL智能感知分析器 下载地址 完全破解+使用教程

    SQL脚本越写越多,总是觉得编写效率太过于低下,这和打字速度无关.在我个人编写SQL脚本时,至少会把SQL的格式排列成易于阅读的,因为其他人会阅读到你的SQL,无论是在程序中或是脚本文件中,良好的排版 ...

  3. Block学习一门:基本使用,使用block包NSURLRequest异步请求

    首先,看一下下面的代码: void (^myFirstBlock)(int theOne,int theTwo) = ^(int theOne,int theTwo){ NSLog(@"== ...

  4. ajax jsonp跨域

    js跨域问题是指:js不同域进行数据传输或通信之间,让我们用ajax到不同的域请求数据.或js获得在不同领域的框架页(iframe)数据.只有到协议.域名.port无论是有不同的.它们被认为是不同的域 ...

  5. c++日历v1.12版

    ////////////////////////////新增信息修改功能,未完善. #include<iostream> #include <string> #include& ...

  6. hdu 4856 Tunnels(bfs+状态压缩)

    题目链接:hdu 4856 Tunnels 题目大意:给定一张图,图上有M个管道,管道给定入口和出口,单向,如今有人想要体验下这M个管道,问最短须要移动的距离,起点未定. 解题思路:首先用bfs处理出 ...

  7. Android 推断SD卡是否存在及容量查询

    首先要在AndroidManifest.xml中添加SD卡訪问权限 <!-- 在SDCard中创建与删除文件权限 --> <uses-permission android:name= ...

  8. 2014 ACM湖南匹配10会议省赛

    2014湖南游戏..... 1:牡丹江Regional有些球队没来的冲突 2:题目比較水 3:队友神勇发挥 最终在开局不利的情况下完毕了翻盘,拿到了第二名.....没有抓住机会顺势夺冠还是非常遗憾的. ...

  9. FreeBSD包管理

    FreeBSD软件没有安装Ubuntu的apt-get.它也不是Gentoo的portage.有三种方式: package ports 自主进行源代码编译安装 这里简介前两种. FreeBSD 6.0 ...

  10. P/Invoke与逆向P/Invoke

    1.在在 C# 中通过 P/Invoke 调用Win32 DLL这篇文中,详细介绍了P/Invoke的基本知识以及使用. 2.InAttribute和OutAttribute特性与C#中ref和out ...