📄 people.cpp
字号:
#include"people.h"
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
people::people()
{
Total=0;
Open();
}
void people::Print()
{
int j;
clrscr();
for(j=0;j<Total;j++)
cout<<List[j].Name<<" "<<List[j].Year<<" "<<List[j].Phone<<" "<<List[j].Email<<endl;
getch();
Draw();
}
void people::Add()
{
clrscr();
cout<<"Input Name:";cin>>List[Total].Name;
for(int i=0;i<Total;i++)
{
if(strcmp(List[i].Name,List[Total].Name)==0){i=-1; cout<<"You have inputed the same Name."<<endl;cout<<"Please input the name:";cin>>List[Total].Name;}else;
}
cout<<"Input Year:";cin>>List[Total].Year;
cout<<"Input Phone:";cin>>List[Total].Phone;
cout<<"Input Email:";cin>>List[Total].Email;
Total++;Write(); Draw();
}
void people::Find()
{
char N[50];int ok=0;
clrscr();
cout<<"Please input the name:";cin>>N;
for(int i=0;i<Total;i++)
{
if(strcmp(List[i].Name,N)==0){ok=1;cout<<List[i].Name<<" "<<List[i].Year<<" "<<List[i].Phone<<" "<<List[i].Email<<endl;break;}else;
}
if(!ok) cout<<"The name not found."<<endl;else;
getch();
Draw();
}
void people::Del()
{
char N[50];int ok=0;
cout<<"Input the Name:";cin>>N;
for(int i=0;i<Total;i++)
{
if(strcmp(List[i].Name,N)==0)
{
ok=1;
for(int j=i;j<Total-1;j++)
{
strcpy(List[j].Name,List[j+1].Name);
strcpy(List[j].Year,List[j+1].Year);
strcpy(List[j].Phone,List[j+1].Phone);
strcpy(List[j].Email,List[j+1].Email);
}
Total--;
Write();
}else;
}
if(!ok) cout<<"The name not found."<<endl;else;
getch(); Draw();
}
void people::Change()
{
char N[50]; int ok=0;
clrscr();
cout<<"Please input the Name:";cin>>N;
for(int i=0;i<Total;i++)
{
if(strcmp(List[i].Name,N)==0)
{
ok=1;
cout<<"Input Name:";cin>>List[i].Name;
cout<<"Input Year:";cin>>List[i].Year;
cout<<"Input Phone:";cin>>List[i].Phone;
cout<<"Input Email:";cin>>List[i].Email;
Write();
break;
}
else;
}
if(!ok) cout<<"The name not found.";else;
getch(); Draw();
}
void people::Q()
{
exit(1);
}
void people::Open()
{
ifstream File(".\\data.txt");
while(!File.eof())
{
File>>List[Total].Name>>List[Total].Year>>List[Total].Phone>>List[Total].Email;
Total++;
}
Total--;
}
void people::Write()
{
ofstream File(".\\data.txt");
for(int j=0;j<Total;j++)
File<<List[j].Name<<" "<<List[j].Year<<" "<<List[j].Phone<<" "<<List[j].Email<<endl;
}
void people::Draw()
{
char ch=0;
Mark:clrscr();
gotoxy(32,6);cout<<"Control Menu";
gotoxy(32,8);cout<<"1.Add a person.";
gotoxy(32,9);cout<<"2.Find a person.";
gotoxy(32,10);cout<<"3.Del a person.";
gotoxy(32,11);cout<<"4.Print All.";
gotoxy(32,12);cout<<"5.Change a person.";
gotoxy(32,13);cout<<"6.Quit.";
gotoxy(33,16);cout<<"Input:";cin>>ch;
switch(ch)
{
case '1':Add();break;
case '2':Find();break;
case '3':Del();break;
case '4':Print();break;
case '5':Change();break;
case '6':Q();break;
default:goto Mark;break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -