C ++课程设计《学生成绩管理系统》
C++程序设计
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
using namespace std;
enum {SUBJECT=5};//一共五门
typedef struct
{
char subject[10];//科目名称
int score;//科目成绩
}markinfo;
typedef struct studentnode
{
markinfo mark[SUBJECT];
int totalmark;
char name[10];//学生姓名
studentnode * next;
}studentnode;
class student
{
studentnode * head;
public:
student();
int addstudent();
~student();
int countmark();
int sortbymark();
int save();
int show();
int display();
int readfiletolist();
int searchbyname();
};
student::student() //用构造函数来初始化。
{
head=new studentnode;
head->next=NULL;
}
//1.输入学生姓名、成绩等数据,并保存在链表中。
int student::addstudent()
{
studentnode * p;
int i;
char check;
system("cls");
cout<<"**********************"<<endl;
cout<<"请输入学生信息:"<<endl;
do
{
p=new studentnode;
cin.ignore();
cout<<"姓名:";
gets(p->name);
i=0;
p->totalmark=0;
do
{
cout<<"科目:";
gets(p->mark[i].subject);
cout<<"成绩(0--100):";
do
{
cin>>p->mark[i].score;
}
while(p->mark[i].score>100||p->mark[i].score<0);
p->totalmark=p->totalmark+p->mark[i].score;
getchar();
}
while(++i!=SUBJECT);
if(head->next==NULL)
{
head->next=p;p->next=NULL;
}
else
{
p->next=head->next;
head->next=p;
}
cout<<"继续添加?y or n :";
check=getchar();
}
while(check!='n' &&check!='N');
return 0;
}
//2.计算每位学生总成绩。
int student::countmark()
{
studentnode * p=head->next;
if(p==NULL)
{
cout<<"没有学生,请重新输入"<<endl;system("pause");return 0;
}
else
{
cout<<"***************"<<endl;
cout<<"学生成绩汇总:"<<endl;
while(p)
{
cout<<"姓名:"<<p->name<<" 总成绩:"<<p->totalmark<<endl;
p=p->next;
}
}
system("pause");
return 0;
}
//4.输出所有学生成绩到一个文件中。
int student::save()
{
char address[35];
int i;
studentnode * p=head->next;
cout<<"请输入保存的地址"<<endl;
cin.ignore();
gets(address);
ofstream fout;
fout.open(address,ios::app|ios::out);
while(p)
{
fout<<"*";
fout<<p->name<<"*";
i=0;
while(i!=SUBJECT)
{
fout<<p->mark[i].subject<<"*";
fout<<p->mark[i].score;
i++;
}
//fout<<"*";
p=p->next;
}
fout.flush();
fout.close();
cout<<"已经保存,请查阅";
system("pause");
return 0;
}
student::~student() //析构函数
{
studentnode * p,* s;
p=head->next;
while(p)
{
s=p->next;
delete p;
p=s;
}
delete head;
}
//3.按照总成绩大小对记录进行排序
int student::sortbymark()
{
studentnode *move1=head->next;
studentnode *move2,*max,*pre1,*pre2,*maxpre,*s=move1;
if(head->next==NULL)
{
cout<<"没有记录,请添加"<<endl;system("pause");return 0;
}
for(pre1=head,max=move1,maxpre=pre1;move1->n
ext!=NULL;pre1=move1,maxpre=pre1,move1=move1->next,max=move1)
{
for(pre2=move1,move2=move1->next;move2!=NULL;pre2=move2,move2=move2->
C++程序设计
next)
if(move2->totalmark>max->totalmark)
{
maxpre=pre2;
max=move2;
}
if(move1->next==max) //交换max和move1。
{
pre1->next=max;
move1->next=max->next;
max->next=move1;
move1=max;
}
else
{
s=move1->next;
move1->next=max->next;
max->next=s;
maxpre->next=move1;
pre1->next=max;
move1=max;
}
}
cout<<"已经按照从大到小排序"<<endl;
system("pause");
return 0;
}
//5输出输入的信息
int student::show()
{
studentnode * p=head->next;
int i;
if(head->next==NULL){cout<<"没有学生记录,请添加"<<endl;system("pause"); return 0;}
else
{
while(p)
{
cout<<"姓名:"<<p->name;
i=1;
while(i!=SUBJECT+1)
{
cout<<"科目:"<<p->mark[i-1].subject;
cout<<" 成绩:"<<p->mark[i-1].score;
i++;
}
cout<<endl;
p=p->next;
}
}
system("pause");
return 0;
}
//6:从文件按读取记录
int student::display()
{
ifstream fin;
char buf[100];
char str[25];
cout<<"请输入路径及文件名:"<<endl;
cin.ignore();
gets(str);
fin.open(str);
if(!fin)
{
cout<<"没有此文件"<<endl;
system("pause");
return 0;
}
while(fin)
{
fin.getline(buf,sizeof(buf));
cout<<buf<<endl;
}
system("pause");
return 0;
}
//8从文件中读取数据,并将数据保存在链表中
int student::readfiletolist()
{
ifstr
…… 此处隐藏:3399字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [行业范文]美好的法语句子
- [行业范文]描写露珠的句子
- [行业范文]精彩禅语句子图片
- [行业范文]关于满嘴谎言的句子
- [行业范文]关于安静的句子48句
- [行业范文]关于小河的句子
- [行业范文]描写稻田的句子
- [行业范文]思念好朋友的句子
- [行业范文]赞美雪的句子
- [行业范文]早上激励人心的句子
- [行业范文]失恋忧伤的句子
- [行业范文]努力积极向上的句子
- [行业范文]对工作心灰意冷的句子
- [行业范文]失恋让人心疼的句子
- [行业范文]描写珍惜青春的句子
- [行业范文]表达思念的句子简短
- [行业范文]关于父爱的句子范例
- [行业范文]浪漫的英语句子
- [行业范文]关于周末的句子
- [行业范文]思念牵挂的句子
- 有关感恩班会课件简短(二篇)(感恩班会
- 2025年初二下乡军训心得体会800字(15篇
- 关于新员工培训方案汇编(关于新员工培
- 精选高考生寒假学习计划书(精)(高考生
- 毕业实训报告心得体会(3篇)(实训报告心
- 银行工作感悟及心得范文怎么写(四篇)(
- 精选领导干部个人政治画像报告通用(七
- 精选超市11.11活动促销方案(精品超市品
- 2025年怎么做自我介绍汇总(5篇)(至2025
- 最新企业错峰生产方案(26篇)(山西企业
- 最新暑期三下乡社会实践调研报告范本(
- 最新幼儿园大班教育教学总结怎么写(最
- 最新教师节主持词小学(优秀9篇)(教师节
- 关于小学安全教育教学方案(推荐)(关于
- 员工信模板范文怎么写(五篇)(员工信息
- 最新保险销售离职申请书(十六篇)(最新
- 最新XX小学防校园欺凌工作方案怎么写(2
- 有关特岗教师辞职信范文(推荐)(特岗教
- 精选党的建设工作要点简短(党的建设的
- 如何写安康杯竞赛活动总结汇总(4篇)(安




