C课程设计
《C++课程设计》
课程设计题目:学生成绩管理系统
学生班级:*****
学生姓名:*****
学生学号:*****
(2)学生成绩管理系统需求与功能分析
学生成绩的录入、统计、查询、修改、删除、输出。画出功能结构图。
(3)学生成绩管理系统的数据结构表
序号成员名(字段名)数据类型长度字段含义
1class_0char20班级
2numint学号
3namechar8姓名
4elecflaot电子技术
5c_progfloatC程序设计
6mediaflaot多媒体技术
7engfloat大学英语
8mathfloat高等数学
9sportfloat大学体育
10polityfloat马克思主义政治经济学
11avefloat平均成绩
12orderint名次
(4)学生成绩管理系统测试数据表
class_0numnameelecc_progmediaengmathsportpolityaveorder
网络303313033101马云飞80706070706080表中其余数据自己编造。
(5)使用链表编写程序(手写源程序代码,并给出注解)
0)定义链表结点
1)主函数main():定义链表头指针,调用录入、统计等函数对成绩表进行处理;
2)建立链表函数Create():输入班级到政治课成绩信息;
3)统计函数Statistic():计算平均成绩;
4)查询函数Lookup():查询指定学号学生成绩记录;
5)修改函数Modify():修改指定学号学生成绩记录;
6)删除函数Delete():删除指定学号学生记录;
7)输出函数Output():输出班级所有学生成绩记录;
8)插入函数Insert():按平均分顺序插入新结点。
9)排序函数Sort():按平均分对学生成绩记录项进行降序排序;
程序如下:
#include
#include
#include
#include
#include
usingnamespacestd;
structNode//定义链表结点
{
char*class_0;//班级
intnumber;
char*name;//姓名
floatelec;//电子技术成绩
floatc_prog;//C程序设计成绩
floatmedia;//多媒体技术成绩
floateng;//大学英语成绩
floatmath;//高等数学成绩
floatsport;//大学体育成绩
floatpolity;//马克思主义政治经济学成绩
floatave;//平均成绩
intorder;//名次
Node*link;
Node(){link=NULL;}
Node(int_number,char*_class_0,char*_name,float_elec,
float_c_prog,float_media,float_eng,float_math,
float_sport,float_polity,float_ave,int_order,Node*next)
{
number=_number;
class_0=newchar[21];
strcpy(class_0,_class_0);
name=newchar[9];
strcpy(name,_name);
elec=_elec;
c_prog=_c_prog;
media=_media;
eng=_eng;
math=_math;
sport=_sport;
polity=_polity;
ave=_ave;
order=_order;
link=next;
}
~Node()
{
delete[]class_0;
delete[]name;
}
};
classStudentScore
{
private:
Node*first;//链表的头指针
intchoice;//选择数据的读入方式
intfileNum;//当前文件数减一
intfileLoc;//定位当前文件
string*fileName;
intoperChoice;
intRecordLength;
public:
StudentScore();
voidSave();
voidBuildList();//手工建立成绩链表
voidReadInfo(intk);//从内存中读入学生信息
voidClearList();
voidStatistic();
voidSort();
voidAdd();
voidDelete();
voidPrintList();
voidMenu();
};
StudentScore::StudentScore()
{
RecordLength=0;
operChoice=0;
first=NULL;
choice=0;
fileLoc=0;
fileNum=0;
fileName=newstring[10];//最多可以存10个文件
}
intGetOrder(Node*first,floatave);
voidStudentScore::BuildList()
{
int_number;//学号
char*_class_0=newchar[21];//班级
char*_name=newchar[9];//姓名
float_elec;//电子技术成绩
float_c_prog;//C程序设计成绩
float_media;//多媒体技术成绩
float_eng;//大学英语成绩
float_math;//高等数学成绩
float_sport;//大学体育成绩
float_polity;//马克思主义政治经济学成绩
float_ave;//平均成绩
int_order;//名次
charc;
Node*p,*r=NULL;
first=NULL;
cout<<您要输入学生成绩信息?<<endl;
while((c=getchar())=='n');
while(tolower(c)!='n')
{
cin>>_class_0;//班级
cin>>_number;
cin>>_name;//姓名
cin>>_elec;
cin>>_c_prog;
cin>>_media;
cin>>_eng;
cin>>_math;
cin>>_sport;
cin>>_polity;
_ave=(_elec+_c_prog+_media+_eng+_math+_sport+_polity)/7;//求得平均成绩
_order=GetOrder(first,_ave);
p=newNode(_number,_class_0,_name,_elec,
_c_prog,_media,_eng,_math,_sport,_polity,
_ave,_order,NULL);//建立一个新的结点储存信息
if(first!=NULL)
r->link=p;
elsefirst=p;
r=p;
RecordLength++;
cout<<您要输入学生成绩信息?<<endl;
while((c=getchar())=='n');
}
}
intGetOrder(Node*first,floatave)//名次记录有严重问题
{
intorder=1;
Node*temp=first;
for(;temp;temp=temp->link)
{if(temp->ave>ave)order++;
if(temp->aveorder)++;
}
returnorder;
}
voidStudentScore::Statistic()
{
Node*temp=first;
floata_elec=0.0;//电子技术成绩
floata_c_prog=0.0;//C程序设计成绩
floata_media=0.0;//多媒体技术成绩
floata_eng=0.0;//大学英语成绩
floata_math=0.0;//高等数学成绩
floata_sport=0.0;//大学体育成绩
floata_polity=0.0;//马克思主义政治经济学成绩
inti=0;
while(temp)
{
a_elec+=temp->elec;
a_c_prog+=temp->c_prog;
a_media+=temp->media;
a_eng+=temp->eng;
a_math+=temp->math;
a_sport+=temp->sport;
a_polity+=temp->polity;
i++;
temp=temp->link;
}
a_elec=a_elec/i;
a_c_prog=a_c_prog/i;
a_media=a_media/i;
a_eng=a_eng/i;
a_math=a_math/i;
a_sport=a_sport/i;
a_polity=a_polity/i;
cout<<电子技术平均成绩为:<<a_elec<<endl;
cout<<c程序设计平均成绩为:<<a_c_prog<<endl;
cout<<多媒体技术平均成绩为:<<a_media<<endl;
cout<<英语平均成绩为:<<a_eng<<endl;
cout<<高等数学平均成绩为:<<a_math<<endl;
cout<<体育平均成绩为:<<a_sport<<endl;
cout<<政治平均成绩为:<<a_polity<<endl;
}
voidStudentScore::Delete()
{
intstudNum;
Node*p;
Node*temp=first;
cout<<请输入要删除的学生学号<<endl;
cin>>studNum;
floataverage;
for(;temp;temp=temp->link)
{
coutnumber;
if(temp->number==studNum)
{
average=temp->ave;
if(temp==first)//说明是第一次
{
first=first->link;
deletetemp;
break;//如果不跳出的话temp=temp->link会出错
}
else
{
p->link=temp->link;
deletetemp;
break;
}
}
p=temp;
RecordLength--;
}
//下面修改学生排名
temp=first;
for(;temp;temp=temp->link)
if(temp->aveorder--;
}
voidStudentScore::Add()
{
int_number;//学号
char*_class_0=newchar[21];//班级
char*_name=newchar[9];//姓名
float_elec;//电子技术成绩
float_c_prog;//C程序设计成绩
float_media;//多媒体技术成绩
float_eng;//大学英语成绩
float_math;//高等数学成绩
float_sport;//大学体育成绩
float_polity;//马克思主义政治经济学成绩
float_ave;//平均成绩
int_order;//名次
charc;
Node*p,*r=NULL;
r=first;
while(r->link)
r=r->link;
//first=NULL;
cout<<您要输入学生成绩信息?<<endl;
while((c=getchar())=='n');
while(tolower(c)!='n')
{
cin>>_class_0;//班级
cin>>_number;
cin>>_name;//姓名
cin>>_elec;
cin>>_c_prog;
cin>>_media;
cin>>_eng;
cin>>_math;
cin>>_sport;
cin>>_polity;
_ave=(_elec+_c_prog+_media+_eng+_math+_sport+_polity)/7;//求得平均成绩
//写一个返回排名的程序
_order=GetOrder(first,_ave);
p=newNode(_number,_class_0,_name,_elec,
_c_prog,_media,_eng,_math,_sport,_polity,
_ave,_order,NULL);//建立一个新的结点储存信息
if(first!=NULL)
r->link=p;
elsefirst=p;
r=p;
RecordLength++;
cout<<您要输入学生成绩信息?<<endl;
while((c=getchar())=='n');
}
}
voidStudentScore::Sort()//简单bubble排序从高分到低分排序
{
inti=0;
Node*temp=first;
Node*before;
//Node*p=first;
for(;temp->link;)
{
if(temp->avelink->ave)
{
if(temp==first)//说明是第一个结点
{
first=first->link;
//p=temp;
//temp=temp->link;
temp->link=temp->link->link;
first->link=temp;
before=first;
}
else//不是第一个结点
{
before->link=temp->link;
temp->link=temp->link->link;
before->link->link=temp;
before=before->link;
}
}
else
{
temp=temp->link;
}
i++;//计算次数
}
for(;i>0;i--)
{
temp=first;
for(intj=0;j<i;j++)
{
if(temp->avelink->ave)
{
cout<<small!<<endl;
if(temp==first)//说明是第一个结点
{
first=first->link;
//p=temp;
//temp=temp->link;
temp->link=temp->link->link;
first->link=temp;
before=first;
}
else//不是第一个结点
{
before->link=temp->link;
temp->link=temp->link->link;
before->link->link=temp;
before=before->link;
}
}
else
{
temp=temp->link;
}
}
}
}
/*
boolIsSorted(Node*first)
{
for(;first;first=first->link)
if(first->avelink->ave)returnfalse;
returntrue;
}*/
voidStudentScore::PrintList()//打印链表程序
{
cout<<Thelistcontains:<<endl;
Node*temp=first;
for(;temp;temp=temp->link)
{
coutclass_0name<<endl;
coutorder<<endl;
}
}
voidStudentScore::ClearList()//清除链表
{
Node*p=newNode;
while(first)
{
p=first->link;
deletefirst;
first=p;
}
}
//读函数
voidStudentScore::ReadInfo(intk)//读第k个文件的信息存入链表
{
//intwordLength;//记录子段长度
int_number;//学号
char*_class_0=newchar[21];//班级
char*_name=newchar[9];//姓名
float_elec;//电子技术成绩
float_c_prog;//C程序设计成绩
float_media;//多媒体技术成绩
float_eng;//大学英语成绩
float_math;//高等数学成绩
float_sport;//大学体育成绩
float_polity;//马克思主义政治经济学成绩
float_ave;//平均成绩
int_order;//名次
Node*p,*r=NULL;
first=NULL;
ifstreamInfile(fileName[k].c_str());
if(!Infile)
{
cout<<fileisnotpresent!<<endl;
return;
}
Infile>>RecordLength;
cout<<RecordLength;
for(inti=0;i<RecordLength;i++)
{
Infile>>_class_0;//班级
//cout<<_class_0;
Infile>>_number;
Infile>>_name;//姓名
Infile>>_elec;
Infile>>_c_prog;
Infile>>_media;
Infile>>_eng;
Infile>>_math;
Infile>>_sport;
Infile>>_polity;
Infile>>_ave;
Infile>>_order;
_ave=(_elec+_c_prog+_media+_eng+_math+_sport+_polity)/7;//求得平均成绩
//写一个返回排名的程序
_order=GetOrder(first,_ave);
p=newNode(_number,_class_0,_name,_elec,
_c_prog,_media,_eng,_math,_sport,_polity,
_ave,_order,NULL);//建立一个新的结点储存信息
if(first!=NULL)
r->link=p;
elsefirst=p;
r=p;
}
}
voidStudentScore::Save()
{
stringtempName;
cout<<请输入将要保存的文件名:<<endl;
//要判断是否跟现有文件重名
cin>>tempName;
ofstreamsavefile(tempName.c_str());//要做一个转换
Node*temp=first;
savefile<<RecordLength<<endl;
for(;temp;temp=temp->link)
{
savefileclass_0numbernameelec<<
c_progmediaengmath<<
sportpolityaveorder<<endl;
}
savefile.close();
//读取文件表信息
ifstreamReadfileinfo(FileRecord.txt);
Readfileinfo>>fileNum;
for(inti=0;i<fileNum;i++)
Readfileinfo>>fileName[i];
Readfileinfo.close();
fileNum++;
fileName[i]=tempName;
//修改文件表信息
ofstreamchangefile(FileRecord.txt);
changefile<<fileNum<<endl;
for(i=0;i<fileNum;i++)
changefile<<fileName[i]<<endl;
changefile.close();
}
voidStudentScore::Menu()
{
cout<<请您选择数据的读入方式:<<endl;
cout<<(1)重新手动建立一份新的数据表<<endl;
cout<<(2)从文件中读入数据<<endl;
cout<<请选择:;
cin>>choice;
if(choice==1)
{
BuildList();
}
if(choice==2)
{
cout<<当前有如下文件,请选择读入文件:<<endl;
ifstreamfileRecord(fileRecord.txt);
if(!fileRecord)
{
cout<<fileRecordisnotpresent!<<endl;
return;
}
fileRecord>>fileNum;
cout<<当前有<<fileNum<<个文件:<<endl;
for(inti=0;i<fileNum;i++)
{
fileRecord>>fileName[i];
cout<<fileName[i]<<;
}
cout<<请您选择一个文件:;
cin>>fileLoc;
ReadInfo(fileLoc-1);
PrintList();
}
cout<<请选择您需要的操作:<<endl;
cout<<(1)统计学生各科成绩<<endl;
cout<<(2)删除某个学生成绩记录<<endl;
cout<<(3)增加某个学生成绩记录<<endl;
cout<<(4)在链表中为所有学生成绩记录排序<<endl;
cin>>operChoice;
if(operChoice==1)
Statistic();
if(operChoice==2)
Delete();
if(operChoice==3)
Add();
if(operChoice==4)
Sort();
Save();
ClearList();
}
intmain()
{
cout<<//////////////////////////////////<<endl;
cout<<欢迎使用学生成绩管理系统!<<endl;
cout<<//////////////////////////////////<<endl;
cout<<endl;
cout<<endl;
StudentScores;
s.Menu();
return0;
}
免责声明:本站发布的教育资讯(图片、视频和文字)以本站原创、转载和分享为主,文章观点不代表本网站立场。
如果本文侵犯了您的权益,请联系底部站长邮箱进行举报反馈,一经查实,我们将在第一时间处理,感谢您对本站的关注!
新励学网教育平台
海量全面 · 详细解读 · 快捷可靠
累积科普文章数:18,862,126篇