?? operater.cpp
字號:
#include "operater.h"
void Operater::display()
{
cout<<endl<<endl;
cout<<"**************************** 學生管理系統 **************************"<<endl;
cout<<"1: 添加一個學生信息"<<endl;
cout<<"2: 刪除一個學生信息"<<endl;
cout<<"3: 顯示所有學生的姓名"<<endl;
cout<<"4: 根據姓名顯示單個學生所有信息"<<endl;
cout<<"5: 根據姓名對單個學生進行編輯"<<endl;
cout<<"6: 幫助菜單"<<endl;
cout<<"7: 保存數據"<<endl;
cout<<"0: 退出系統"<<endl;
cout<<"********************************************************************"<<endl;
}
void Operater::Loop()
{
List L1; //List 對象
char ch[20];
nodetype *p, *head;
int i; //存放節點序號
p=L1.load(); //初始化:從外部讀入數據創建鏈表
head=p;
display();
while(1)
{
cout<<endl<<endl;
cout<<"請輸入選擇(幫助選項--> 6 ): "<<endl;
cin>>ch;
system("cls");
if(L1.check(ch, "1"))
{
p=L1.insnode(0);
head=p;
system("cls");
cout<<endl;
cout<<"************** 添加一個學生信息 ******************"<<endl;
cout<<"下面輸入個人信息: "<<endl;
L1.editperson(p);
cout<<"下面輸入學科成績: "<<endl;
L1.editscore(p);
cout<<"下面輸入聯系方式: "<<endl;
L1.edittelephone(p);
}
if(L1.check(ch, "2"))
{
system("cls");
cout<<endl;
cout<<"************** 刪除一個學生信息 ******************"<<endl;
L1.dispname();
cout<<"請輸入學生姓名: "<<endl;
cin>>ch;
i=L1.find2(ch);
L1.delnode(i);
}
if(L1.check(ch, "3"))
{
system("cls");
cout<<endl;
cout<<"************** 顯示所有學生姓名 ******************"<<endl;
L1.dispname();
}
if(L1.check(ch, "4"))
{
system("cls");
cout<<endl;
cout<<"************** 根據姓名顯示單個學生所有信息 ******************"<<endl;
L1.dispname();
cout<<"請輸入學生姓名: "<<endl;
cin>>ch;
p=L1.find(ch);
L1.dispnode(p);
}
if(L1.check(ch, "6"))
{
display();
}
if(L1.check(ch, "7")) //保存數據
{
FILE *fp;
if((fp=fopen("student.txt", "w"))==NULL)
{
cout<<"打開文件失敗"<<endl;
return;
}
int i;
char t[255];
//將 L1.listlen() 賦予字符串中的數字
sprintf(t, "The Length Of Link: %d\n", L1.listlen());
fputs(t, fp);
strcpy(t, "\n");
fputs(t, fp);
p=L1.findnode(1); //將鏈表頭指針賦予 p
for(i=0; i<L1.listlen(); i++)
{
fputs(p->address, fp); //輸出地址
fputs(p->birthday, fp); //輸出生日
fputs(p->sc.num, fp); //輸出學號
fputs(p->sc.chinese, fp); //輸出語文成績
fputs(p->sc.english, fp); //輸出英語成績
fputs(p->sc.math, fp); //輸出數學成績
fputs(p->sc.physics, fp); //輸出物理成績
fputs(p->pe.name, fp); //輸出姓名
fputs(p->pe.sex, fp); //輸出性別
fputs(p->pe.GJ, fp); //輸出國籍
fputs(p->pe.MZ, fp); //輸出民族
fputs(p->pe.XL, fp); //輸出學歷
fputs(p->te.SJ, fp); //輸出手機
fputs(p->te.JD, fp); //輸出家庭電話
fputs(p->te.XD, fp); //輸出學校電話
fputs(t, fp);
p=p->next;
}
p=head;
fclose(fp);
}
if(L1.check(ch, "5"))
{
char c[20];
system("cls");
cout<<endl;
cout<<"************** 根據姓名對單個學生進行編輯 ******************"<<endl;
L1.dispname();
cout<<"請輸入學生姓名: "<<endl;
cin>>c;
p=L1.find(c);
system("cls");
cout<<endl<<endl;
cout<<"*********************************************************"<<endl;
cout<<"1: 編輯個人信息"<<endl;
cout<<"2: 編輯學科成績"<<endl;
cout<<"3: 編輯聯系方式"<<endl;
cout<<"4: 顯示個人信息"<<endl;
cout<<"5: 顯示學科成績"<<endl;
cout<<"6: 顯示聯系方式"<<endl;
cout<<"7: 顯示該學生所有信息"<<endl;
cout<<"8: 幫助菜單"<<endl;
cout<<"9: 返回上一級菜單"<<endl;
cout<<"*********************************************************"<<endl;
while(1)
{
cout<<endl<<endl;
cout<<"請輸入選擇(幫助選項--> 8 ): "<<endl;
cin>>c;
system("cls");
if(L1.check(c, "1"))
{
system("cls");
cout<<endl;
cout<<"************** 編輯個人信息 ******************"<<endl;
L1.editperson(p);
}
else if(L1.check(c, "2"))
{
system("cls");
cout<<endl;
cout<<"************** 編輯學科成績 ******************"<<endl;
L1.editscore(p);
}
else if(L1.check(c, "3"))
{
system("cls");
cout<<endl;
cout<<"************** 編輯聯系方式 ******************"<<endl;
L1.edittelephone(p);
}
else if(L1.check(c, "4"))
{
system("cls");
cout<<endl;
cout<<"************** 顯示個人信息 ******************"<<endl;
L1.dispperson(p);
}
else if(L1.check(c, "5"))
{
system("cls");
cout<<endl;
cout<<"************** 顯示學科成績 ******************"<<endl;
L1.dispscore(p);
}
else if(L1.check(c, "6"))
{
system("cls");
cout<<endl;
cout<<"************** 顯示聯系方式 ******************"<<endl;
L1.disptelephone(p);
}
else if(L1.check(c, "7"))
{
system("cls");
L1.dispnode(p);
}
else if(L1.check(c, "8"))
{
system("cls");
L1.help();
}
else if(L1.check(c, "9"))
{
display();
break; //用 break 跳出本循環,不要用 return ,return 是退出程序
}
}
}
else if(L1.check(ch, "0"))
return;
}
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -