教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 范文大全 > 行业范文 >

C ++课程设计《学生成绩管理系统》

来源:网络收集 时间:2026-08-23
导读: C++程序设计 #includeiostream #includestring #includefstream #includecstdlib using namespace std; enum {SUBJECT=5};//一共五门 typedef struct { char subject[10];//科目名称 int score;//科目成绩 }markinfo; typedef struct studentnode { markinfo

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字,全部文档内容请下载后查看。喜欢就下载吧 ……

C ++课程设计《学生成绩管理系统》.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/fanwen/1983705.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)