?? student.cpp
字號(hào):
#include <iostream>
#include <string>
#include<fstream>
#include<iomanip>
using namespace std;
int amount=0; //記錄學(xué)生個(gè)數(shù)
ofstream *file[50];
struct score
{
float czxt;
float sjjg;
float jsj;
float yy;
float gl;
struct score *next;
};
class student
{
public:
string num;
string name;
score sc; //期末成績;
class student *next;
};
void input(student *head); //錄入
void search1(student *head); //姓名查詢
void search2(student *head); //學(xué)號(hào)查詢
void change(student *head); //修改
void shanchu(student *head); //刪除
void get(student *head); //取數(shù)據(jù)
void display(); //顯示菜單
void show(student *head); //顯示數(shù)據(jù)
void readin(student *head); //保存數(shù)據(jù)
void chushihua(student *head); //初始化
void main() //主函數(shù)
{
system("color f5");
char x;
bool flag2=0;
student *head=new student; //初始化學(xué)生數(shù)據(jù)
head->next=NULL;
cout<<" ★ 歡迎使用學(xué)生信息管理系統(tǒng) ★ \n ";
display(); //顯示菜單
do
{
do
{
cin>>x;
if((x>='0'&&x<='8'))
flag2=1;
else
{
cout<<"指令錯(cuò)誤!"<<endl;
cout<<"請選擇相應(yīng)的數(shù)字進(jìn)行操作: ";
}
}while(flag2==0);
switch(x)
{
case '0':cout<<"******************************現(xiàn)在進(jìn)行學(xué)生信息錄入******************************\n";
input(head);
cout<<"輸入的學(xué)生信息為:\n";
show(head);
cout<<"********************************************************************************\n";
display(); break;
case '1':
{
char z;
cout<<"******************************現(xiàn)在進(jìn)行學(xué)生信息查詢******************************\n";
cout<<"請選擇查詢方式:";
cout<<"(0).姓名查詢;(1).學(xué)號(hào)查詢:";
cin>>z;
while(z!='0'&&z!='1')
{
cout<<"指令錯(cuò)誤<請選擇(0)或者(1)>!"<<endl;
cout<<"請選擇查詢方式:(0).姓名查詢;(1).學(xué)號(hào)查詢:";
cin>>z;
}
switch(z)
{
case '0': search1(head);break;//按姓名查詢
case '1': search2(head);break;//按學(xué)號(hào)查詢
}
cout<<"********************************************************************************\n";
display();
break;
}
case '2': cout<<"***********************現(xiàn)在進(jìn)行學(xué)生信息修改************************************\n";
change(head);
cout<<"********************************************************************************\n";
display(); break; //按姓名修改
case '3': cout<<"***********************現(xiàn)在進(jìn)行學(xué)生信息刪除************************************\n";
shanchu(head);
show(head);
cout<<"********************************************************************************\n";
display();
break; //刪除
case '4': cout<<"***********************現(xiàn)在進(jìn)行顯示學(xué)生信息***********************************\n";
show(head);
cout<<"********************************************************************************\n";
display();
break; //顯示數(shù)據(jù)
case '5':cout<<"************************現(xiàn)在進(jìn)行初始化學(xué)生信息****************************\n";
chushihua(head);
cout<<"********************************************************************************\n";
display() ;
break;
case '6':cout<<"***********************現(xiàn)在進(jìn)行保存學(xué)生信息******************************\n";
readin(head);
cout<<"********************************************************************************\n";
display();
break;
case '7':
cout<<"********************************************************************************\n";
cout<<" ¤ 您已退出學(xué)生信息管理系統(tǒng), 謝謝您的使用! ¤ \n";
cout<<"********************************************************************************\n";
cout<<endl;
exit(0);
break;
}
}while(flag2==1);
}
void display()
{
cout<<" ++++++++++**********++++++++++**********++++++++++\n";
cout<<" $ 菜 單 $\n";
cout<<" $ ^^^^^^^^^^ $\n";
cout<<" $ 請選擇: $\n";
cout<<" $ [0]-錄入; [1]-查詢; [2]-修改; $\n";
cout<<" $ [3]-刪除; [4]-顯示; [5]-初始化; $\n";
cout<<" $ [6]-保存; [7]-退出; $\n";
cout<<" **********++++++++++**********++++++++++**********\n";
cout<<" 請選擇相應(yīng)的數(shù)字進(jìn)行操作: ";
}
/////////////////////////////////*初始化學(xué)生數(shù)據(jù)*////////////////////////////////////////
void chushihua(student *head)
{
int j=0;char c;
cout<<"注意:初始化操作將刪除<總評成績.txt>文件中的所有信息!!!!!!\n";
cout<<"是否繼續(xù)操作?(y/n):";cin>>c;
if (c='y')
{
amount=1;
file[j]=new ofstream("F:\\課設(shè)\\總評成績.txt",ios::out);
}
cout<<"......成功清除<總評成績.txt>的信息\n ";
}
/////////////////////////////////*顯示學(xué)生數(shù)據(jù)*////////////////////////////////////////
void show(student *head)
{
student *stu=head;
cout<<"| 學(xué)號(hào) | 姓名 | 操作系統(tǒng) | 數(shù)據(jù)結(jié)構(gòu) | 計(jì)算機(jī)| 英語 | 概率論 |"<<endl;
while(stu->next!=NULL)
{
stu=stu->next;
cout<<"| "<<setw(6)<<(*stu).num;
cout<<" | "<<setw(4)<<(*stu).name;
cout<<" | "<<setw(6)<<(*stu).sc.czxt;
cout<<" | "<<setw(6)<<(*stu).sc.sjjg;
cout<<" | "<<setw(5)<<(*stu).sc.jsj;
cout<<" | "<<setw(4)<<(*stu).sc.yy;
cout<<" | "<<setw(5)<<(*stu).sc.gl;
cout<<" | "<<endl;
}
}
/////////////////////////////////*保存學(xué)生數(shù)據(jù)*////////////////////////////////////////
void readin(student *head)
{
char a;
student *stu=head->next;
cout<<"現(xiàn)在保存輸入學(xué)生數(shù)據(jù),是否繼續(xù)操作?(y/n)";
cin>>a;
ofstream outfile("F:\\課設(shè)\\總評成績.txt",ios::out);
if(! outfile)
{
cout<<"打開文件錯(cuò)誤!!!!!!!\n";
exit(0);
}
while(a!='n')
{
while(stu!=NULL)
{ outfile<<"************************第"<<amount<<"個(gè)學(xué)生的數(shù)據(jù):*************************\n";
outfile<<"| 學(xué)號(hào) | 姓名 | 操作系統(tǒng) | 數(shù)據(jù)結(jié)構(gòu) | 計(jì)算機(jī)| 英語 | 概率論 |"<<endl;
outfile<<" 期末成績: \n"
<<"| "<<setw(6)<<(*stu).num<<" | "<<setw(4)<<(*stu).name<<" | "<<setw(6)<<(*stu).sc.czxt<<
" | "<<setw(6)<<(*stu).sc.sjjg<<" | "<<setw(5)<<(*stu).sc.jsj<<" | "<<setw(4)<<(*stu).sc.yy
<<" | "<<setw(5)<<(*stu).sc.gl<<endl;
amount++;
stu=stu->next;
}
break;
}
cout<<"......成功將學(xué)生數(shù)據(jù)保存到<總評成績.txt>中! ";
outfile.close();
}
/////////////////////////////////*錄入學(xué)生數(shù)據(jù)*////////////////////////////////////////
void input(student *head)
{
char c;
int j=0;
student *p=head;
file[j]=new ofstream("F:\\課設(shè)\\總評成績.txt",ios::app);
do
{
student *stu=new student;
cout<<"請輸入學(xué)號(hào):"<<setw(9);
cin>>(*stu).num;
cout<<"請輸入姓名:"<<setw(20);
cin>>(*stu).name;
cout<<"請輸入操作系統(tǒng)成績:"<<setw(2);
cin>>(*stu).sc.czxt;
cout<<"請輸入數(shù)據(jù)結(jié)構(gòu)成績:"<<setw(2);
cin>>(*stu).sc.sjjg;
cout<<"請輸入計(jì)算機(jī)成績:"<<setw(2);
cin>>(*stu).sc.jsj;
cout<<"請輸入英語成績:"<<setw(2);
cin>>(*stu).sc.yy;
cout<<"請輸入概率論成績:"<<setw(2);
cin>>(*stu).sc.gl;
stu->next=p->next;
p->next=stu;
amount++;
cout<<"數(shù)據(jù)錄入成功,想繼續(xù)錄入嗎(y/n)"; cin>>c;
p=p->next;
while(c!='y'&&c!='n')
{
cout<<"指令錯(cuò)誤<請輸入y/n!>!!!!!!"<<endl;
cout<<"數(shù)據(jù)錄入成功,想繼續(xù)錄入嗎(y/n)";
cin>>c;
}
}while(c=='y');
j++;
cout<<"輸入了 "<<amount<<"個(gè)學(xué)生的信息."<<endl;
}
/////////////////////////////////*使用姓名查詢學(xué)生數(shù)據(jù)*////////////////////////////////////////
void search1(student *head)//姓名查詢
{
char c;
string name;
do
{
student *stu=head->next;
bool flag=0;
cout<<"請輸入你要查詢的學(xué)生姓名:";
cin>>name;
do{
if(stu!=NULL&&name==(*stu).name) //輸出總成績
{
flag=1;
cout<<"您要查詢的學(xué)生是:"<<stu->name<<endl;
cout<<"| 學(xué)號(hào) | 姓名 | 操作系統(tǒng) | 數(shù)據(jù)結(jié)構(gòu) | 計(jì)算機(jī)| 英語 | 概率論 |"<<endl;
cout<<"| "<<setw(4)<<(*stu).num;
cout<<" | "<<setw(6)<<(*stu).name;
cout<<" | "<<setw(6)<<(*stu).sc.czxt;
cout<<" | "<<setw(6)<<(*stu).sc.sjjg;
cout<<" | "<<setw(5)<<(*stu).sc.jsj;
cout<<" | "<<setw(4)<<(*stu).sc.yy;
cout<<" | "<<setw(5)<<(*stu).sc.gl;
cout<<" | "<<endl;
}
stu=stu->next;
}while(stu!=NULL);
if(flag==0)
cout<<"對不起!您要查詢的學(xué)生不存在!"<<endl;
cout<<"您想繼續(xù)查詢嗎?(y/n)"; cin>>c;
while(c!='y'&&c!='n')
{
cout<<"指令錯(cuò)誤<請輸入y/n>!"<<endl;
cout<<"您想繼續(xù)查詢嗎?(y/n)";
cin>>c;
}
} while(c=='y');
}
/////////////////////////////////*用學(xué)號(hào)查詢學(xué)生數(shù)據(jù)*////////////////////////////////////////
void search2(student *head)//學(xué)號(hào)查詢
{
char c;
string no;
do
{
student *stu=head->next;
int flag=0;
cout<<"請輸入你要查詢的學(xué)生學(xué)號(hào):";
cin>>no;
do
{
if(stu!=NULL&&no==(*stu).num)
{
flag=1;
cout<<"您要查詢的學(xué)生是:"<<stu->name<<endl;
cout<<"| 學(xué)號(hào) | 姓名 | 操作系統(tǒng) | 數(shù)據(jù)結(jié)構(gòu) | 計(jì)算機(jī)| 英語 | 概率論 |"<<endl;
cout<<"| "<<setw(4)<<(*stu).num;
cout<<" | "<<setw(6)<<(*stu).name;
cout<<" | "<<setw(6)<<(*stu).sc.czxt;
cout<<" | "<<setw(6)<<(*stu).sc.sjjg;
cout<<" | "<<setw(5)<<(*stu).sc.jsj;
cout<<" | "<<setw(4)<<(*stu).sc.yy;
cout<<" | "<<setw(5)<<(*stu).sc.gl;
cout<<" | "<<endl;
}
stu=stu->next;
}while(stu!=NULL);
if(flag==0)
cout<<"對不起!您要查詢的學(xué)生不存在!!!!!!!"<<endl;
cout<<"您想繼續(xù)查詢嗎?(y/n)";
cin>>c;
while(c!='y'&&c!='n')
{
cout<<"指令錯(cuò)誤<請輸入y/n>!"<<endl;
cout<<"您想繼續(xù)查詢嗎?(y/n)"<<endl;
cin>>c;
}
}while(c=='y');
}
/////////////////////////////////*修改學(xué)生數(shù)據(jù)*////////////////////////////////////////
void change(student *head)
{
string name;
char c;
do
{
bool flag2=0;
student *stu=head ;
score sc;
cout<<"請輸入您要修改的學(xué)生的姓名:";
cin>>name;
do
{
if(name==(*stu).name)
{
flag2=1;
cout<<"請輸入新的操作系統(tǒng)成績):";
cin>>sc.czxt;
cout<<"請輸入新的數(shù)據(jù)結(jié)構(gòu)成績:";
cin>>sc.sjjg;
cout<<"請輸入新的計(jì)算機(jī)成績:";
cin>>sc.jsj;
cout<<"請輸入新的英語成績:";
cin>>sc.yy;
cout<<"請輸入新的概率論成績:";
cin>>sc.gl;
cout<<"| 學(xué)號(hào) | 姓名 | 操作系統(tǒng) | 數(shù)據(jù)結(jié)構(gòu) | 計(jì)算機(jī)| 英語 | 概率論 |"<<endl;
cout<<"| "<<setw(4)<<(*stu).num;
cout<<" | "<<setw(6)<<(*stu).name;
cout<<" | "<<setw(6)<<(*stu).sc.czxt;
cout<<" | "<<setw(6)<<(*stu).sc.sjjg;
cout<<" | "<<setw(5)<<(*stu).sc.jsj;
cout<<" | "<<setw(4)<<(*stu).sc.yy;
cout<<" | "<<setw(5)<<(*stu).sc.gl;
cout<<" | "<<endl;
cout<<".......數(shù)據(jù)修改成功!\n";
break;
}
stu=stu->next;
}while(stu!=NULL);
if(flag2==0)
{
cout<<"對不起!您要修改的學(xué)生不存在!請檢查重新輸入!"<<endl;
}
cout<<"想繼續(xù)修改嗎?(y/n)";
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令錯(cuò)誤!請重新輸入<y/n>!";
cin>>c;
}
}while(c=='y');
}
/////////////////////////////////*刪除學(xué)生數(shù)據(jù)*////////////////////////////////////////
void shanchu(student *head)//學(xué)號(hào)
{
char c;
string no;
do
{
int flag=0;
cout<<"請輸入你要?jiǎng)h除的學(xué)生學(xué)號(hào):";
cin>>no;
student *q,*p;
q=head;
while(q->next!=NULL&&q->next->num!=no)
q=q->next;
if(q->next!=NULL)
{
flag=1;
p=q->next;
q->next=q->next->next;
amount--;
free(p);
cout<<"......成功刪除! ";
}
if(flag==0)
cout<<"對不起!您要?jiǎng)h除的學(xué)生不存在!"<<endl;
cout<<"您想繼續(xù)刪除嗎?(y/n)";
cin>>c;
while(c!='y'&&c!='n')
{
cout<<"指令錯(cuò)誤<請輸入y/n>!"<<endl;
cout<<"您想繼續(xù)刪除嗎?(y/n)";
cin>>c;
}
}while(c=='y');
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -