学生成绩管理文档格式.docx

上传人:b****3 文档编号:18245552 上传时间:2022-12-14 格式:DOCX 页数:17 大小:119.31KB
下载 相关 举报
学生成绩管理文档格式.docx_第1页
第1页 / 共17页
学生成绩管理文档格式.docx_第2页
第2页 / 共17页
学生成绩管理文档格式.docx_第3页
第3页 / 共17页
学生成绩管理文档格式.docx_第4页
第4页 / 共17页
学生成绩管理文档格式.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

学生成绩管理文档格式.docx

《学生成绩管理文档格式.docx》由会员分享,可在线阅读,更多相关《学生成绩管理文档格式.docx(17页珍藏版)》请在冰豆网上搜索。

学生成绩管理文档格式.docx

//输入选项

intGetID();

//输入学号

enumChoices{ADD=1,UPDATE,DELETE,QUERY,DISPLAY,SORTID,SORTSCORE,END};

classList;

classPerson{//抽象类

protected:

intID;

//学号

charName[10];

//姓名

public:

virtualbooloperator<

(Person&

)=0;

//<

运算符重载

virtualbooloperator>

=(Person&

//>

=运算符重载

};

classStudent:

publicPerson{//学生类

intScore[4];

//成绩

voidSwapData(Student*);

//交换数据

Student(int=0,char*=NULL,int*=NULL);

//构造函数

booloperator<

);

booloperator>

friendofstream&

operator<

<

(ofstream&

Student*);

//<

运算符重载输出到文件

friendifstream&

operator>

>

(ifstream&

//>

运算符重载从文件输入

friendostream_withassign&

(ostream_withassign&

运算符重载输出到显示器

friendistream_withassign&

(istream_withassign&

运算符重载从键盘输入

friendclassList;

classNode{//结点类

Student*Stup;

//指向学生对象指针

Node*Prev,*Next;

//指向前后结点指针

Node();

Node(Student*);

Node(Node&

//拷贝构造函数

~Node();

//析构函数

classList{

Node*Head,*Tail;

//链表头尾指针

voidInitList();

//初始化函数

List();

~List();

voidClearList();

//清空链表

Node*FindID(int&

//根据学号寻找学生所在结点

voidInsert(Node*);

//插入一个学生

Node*CreateNode(Student*);

//建立一个学生结点

voidAdd();

//增加一个学生

voidUpdate();

//修改学生成绩

voidDelete();

//删除一个学生

voidQuery();

//查找一个学生

voidSortID();

//按学号排序

voidSortScore();

//按学生总成绩排序

voidSaveBin();

//以二进制形式保存数据

voidPrintList();

//显示链表

voidPrintTitle();

//显示标题

voidPrintOne(Student*);

//显示一个学生数据

#endif

voidmain()

{

Listls;

intchoice;

while((choice=EnterChoice())!

=END)

{

switch(choice){

caseADD:

//新增一个学生

try{

ls.Add();

}

catch(int){

cout<

"

Wrong!

ThisIDisequaltootherID"

endl;

}

break;

caseUPDATE:

ls.Update();

catch(int)

cout<

Thisstudent'

sIDis'

tfound"

caseDELETE:

ls.Delete();

}

caseQUERY:

//查询一个学生数据

ls.Query();

}

break;

caseDISPLAY:

//显示全部学生数据

ls.PrintList();

caseSORTID:

//根据学号排序

ls.SortID();

caseSORTSCORE:

//根据总成绩排序

ls.SortScore();

default:

cerr<

Incorrectchoice\n"

;

ls.SaveBin();

intEnterChoice(){

\n请选择你的功能\n"

<

1:

增加一个学生2:

修改一个学生\n"

3:

删除一个学生4:

查找一个学生\n"

5:

显示全部学生数据6:

根据学号排序\n"

7:

根据分数排序8:

退出系统\n"

intmenuChoice;

cin>

menuChoice;

returnmenuChoice;

intGetID(){//输入学号

intid;

do{

Inputstudent'

sID(>

0)"

cin>

id;

}while(id<

=0);

returnid;

iomanip.h>

string.h>

Student:

:

Student(intid,char*name,int*score){//构造函数

ID=id;

if(name!

=NULL)strcpy(Name,name);

if(score!

=NULL)

for(inti=0;

i<

4;

i++)

Score[i]=score[i];

boolStudent:

operator<

per){

Student&

stup=(Student&

)per;

returnScore[3]<

stup.Score[3];

operator>

=(Person&

per){

return!

(Score[3]<

stup.Score[3]);

voidStudent:

SwapData(Student*stup){//学生数据交换

Student*t=(Student*)stup;

Studenttemp=*this;

*this=*t;

*t=temp;

/*Studentt;

inti;

t.ID=this->

ID;

strcpy(t.Name,this->

Name);

for(i=0;

i++)t.Score[i]=this->

Score[i];

this->

ID=stup->

strcpy(this->

Name,stup->

i++)this->

Score[i]=stup->

stup->

ID=t.ID;

strcpy(stup->

Name,t.Name);

i++)stup->

Score[i]=t.Score[i];

*/

ifstream&

(ifstream&

in,Student*stup){//>

in.read((char*)stup,sizeof(Student));

returnin;

ofstream&

out,Student*stup){//<

运算符重载输出至文件

out.write((char*)stup,sizeof(Student));

returnout;

istream_withassign&

in,Student*stup){//>

运算符重载从标准文件输入

InputName,Score1-Score3"

Name="

in>

stup->

Name;

Score[3]=0;

3;

Score"

="

in>

stup->

Score[3]+=stup->

ostream_withassign&

out,Student*stup){//<

运算符重载输出至标准文件

out<

ID<

\t"

Name<

out<

Score[i]<

iostream>

string>

List:

List(){//构造函数

Head=Tail=newNode();

//建立链表头结点

Head->

Next=NULL;

Prev=NULL;

InitList();

//从文件读取数据

~List(){//析构函数

ClearList();

deleteHead;

voidList:

InitList(){//从文件读取数据

ifstreaminStudent;

ofstreamoutStudent;

inStudent.open("

Student.dat"

ios:

binary);

//打开学生文件

if(!

inStudent)//文件不存在,建立该文件

inStudent.close();

outStudent.open("

outStudent.close();

//关闭文件

else//文件存在,读取学生数据

Student*stup=newStudent();

Node*nodep;

inStudent>

stup;

while(!

inStudent.eof()){

nodep=CreateNode(stup);

Insert(nodep);

stup=newStudent();

deletestup;

inStudent.close();

Add(){//增加一个学生

Student*stup;

Node*nodep;

intid=GetID();

//从键盘上输入学号

if((nodep=FindID(id))!

throw

(1);

//输入学号相同,抛出异常

stup=newStudent();

ID=id;

nodep=CreateNode(stup);

Insert(nodep);

PrintTitle();

PrintOne(stup);

Update(){//修改学生成绩

Node*nodep;

if((nodep=FindID(id))==NULL)

throw

(1);

nodep->

Stup->

for(inti=0;

Score["

]="

nodep->

nodep->

Score[3]+=nodep->

PrintOne(nodep->

Stup);

Delete(){//删除一个学生

Node*nodep,*nodel;

nodel=Head;

nodep=Head->

Next;

while(nodep!

=NULL&

&

ID!

=id)

nodel=nodep;

nodep=nodep->

if(nodep==NULL)

没有找到要删除的学号\n"

else{

nodel->

Next=nodep->

deletenodep;

}

Query(){//查询学生数据

Node*nodep;

ClearList(){//清空链表

while(Head->

Next!

=NULL){

nodep=Head->

Head->

Next=Head->

Next->

Tail=Head;

Node*List:

FindID(int&

id){//查找学号

Node*nodep=Head->

=id)nodep=nodep->

returnnodep;

Insert(Node*nodep){//在链表尾插入一个学生

Prev=Tail;

Tail->

Next=nodep;

Tail=nodep;

SortID(){//按学号排序

Node*nodef,*nodel=Tail;

if(Head!

=Tail){

while(Head->

=nodel){

nodef=Head->

while(nodef!

if(nodef->

ID>

nodef->

ID)

nodef->

SwapData(nodef->

nodef=nodef->

}

nodel=nodel->

Prev;

PrintList();

SortScore(){//按总成绩排序

Score[3]>

Score[3])

SaveBin(){//链表数据保存在二进制文件

ofstreamstudent;

student.open("

Next;

student<

Stup;

student.close();

CreateNode(Student*stup){//建立一个学生对象

Node*nodep=newNode(stup);

PrintList(){//显示链表中数据

PrintTitle();

while(nodep!

cout<

Stup;

nodep=nodep->

else

Nostudents"

PrintTitle()

IDNameScore1Score2Score3Score"

PrintOne(Student*stup){//<

Node:

Node(){

Stup=NULL;

Prev=Next=NULL;

Node(Student*stup){

Stup=stup;

Node(Node&

node){

Stup=newStudent();

Prev=newNode();

Next=newNode();

~Node(){

deleteStup;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 职业教育 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1