学生成绩管理系统[通俗易懂]

学生成绩管理系统

大家好,又见面了,我是全栈君。

#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->next!=NULL;pre1=move1,maxpre=pre1,move1=move1->next,max=move1){for(pre2=move1,move2=move1->next;move2!=NULL;pre2=move2,move2=move2->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(){ifstream fin;int i;char str[25];cout<<"请输入路径及文件名称:"<<endl;cin.ignore();gets(str);fin.open(str);if(!fin){cout<<"没有此文件"<<endl;system("pause");return 0;}studentnode * p;fin.ignore(100,'*');while(fin){p=new studentnode;p->totalmark=0;fin.getline(p->name,100,'*');i=0;while(i!=SUBJECT){fin.getline(p->mark[i].subject,100,'*');fin>>p->mark[i].score;p->totalmark+=p->mark[i].score;i++;}if(head->next==NULL){head->next=p;p->next=NULL;} else{p=head->next;head->next=p;}}cout<<"信息已经保存在链表中"<<endl;system("pause");return 0;}//9依据姓名进行查找int student::searchbyname(){if(head->next==NULL){cout<<"没有学生,请加入或者从文件里读取"<<endl;system("pause");return 0;}studentnode * p=head->next;char findname[10];int i;cout<<"请输入姓名:";cin.ignore();gets(findname);while(p){if(!strcmp(p->name,findname)){cout<<"经查找。找到该生信息例如以下:"<<endl<<endl;cout<<"姓名:"<<p->name;i=1;while(i!=SUBJECT+1){cout<<"科目:"<<p->mark[i-1].subject;cout<<" 成绩:"<<p->mark[i-1].score;i++;}cout<<endl;system("pause");return 1;}p=p->next;}cout<<"没有此学生,请加入或者从文件里读取"<<endl;system("pause");return 0;}int showmenu(){int choice;char * menu[9]={ "1:输入学生成绩保存到链表\n","2:计算每位学生总成绩\n","3:依照总成绩大小对记录进行排序\n","4:输出全部学生成绩到一个文件里\n","5:显示新输入的学生信息\n","6:从文件里读取信息\n","7:将文件信息保存在链表中\n","8:依据姓名查找学生记录\n","9:结束程序\n"};cout<<" "<<"*****************************************************"<<endl;cout<<" *"<<" "<<"学生成绩管理系统"<<" *"<<endl;cout<<" "<<"*****************************************************"<<endl;for(choice=0;choice<9;choice++)cout<<" "<<menu[choice];cout<<" "<<"*****************************************************"<<endl;cout<<"please choose to continue"<<endl;do{cin>>choice;}while(choice>9||choice<1);return choice;}int main(){int menuitem,flag=1;student stu;while(flag){system("cls");menuitem=showmenu();switch(menuitem){case 1:{stu.addstudent();break;}case 2:{stu.countmark();break;}case 3:{stu.sortbymark();break;}case 4:{stu.save();break;}case 5:{stu.show();break;}case 6:{stu.display();break;}case 7:{stu.readfiletolist();break;}case 8:{stu.searchbyname();break;}case 9:{flag=0;break;}}}return 0;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115232.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • myeclipse8.5注册码在线生成_MyEclipse激活码

    myeclipse8.5注册码在线生成_MyEclipse激活码主要是myeclipse8.0的注册码,估计7.5的也能用,注册码都是到2014年12月过期,附送注册机Subscriber:zxSubscriptionCode:mLR8ZO-655444-6967865456424254Subscriber:huahuaSubscriptionCode:uLR8ZO-655444-69678657696224504Subscriber:yayaSubsc

    2022年9月30日
    2
  • 线性回归 均方误差_线性回归模型中随机误差项的意义

    线性回归 均方误差_线性回归模型中随机误差项的意义刚开始学习机器学习的时候就接触了均方误差(MSE,MeanSquaredError),当时就有疑惑,这个式子是怎么推导的,但是因为懒没有深究。今天看到了唐宇迪老师的机器学习课程,终于理解他是怎么推导的了。问题描述我们有工资和年龄两个特征,要预测银行会带宽给我们多少钱。1.拟合函数假设:年龄:x1x_1x1​工资:x2x_2x2​年龄的参数:θ1θ_1θ1​工资的参数:θ2θ_2θ2​那么有拟合函数:(1)将它转化为矩阵表达形式为:(2)其中x0全为1。2.误差真实值和预

    2022年9月29日
    4
  • spring bean之间的关系:继承;依赖「建议收藏」

    spring bean之间的关系:继承;依赖

    2022年2月6日
    50
  • vim乱码恢复_linux保存退出命令

    vim乱码恢复_linux保存退出命令初始时,安装好Ubuntu以后,使用Vim退出以后会显示乱码,这是由于Ubuntu的Vim默认是链接到了/usr/bin/gnome,这是不同于一般使用习惯的Vim,所以我们如果需要使用一般习惯的Vim,并且解决Vim退出以后的乱码问题,我们必须使Vim链接到我们常用的Vim.basic,步骤如下:1.使用apt-get安装Vim包,系统默认安装的是Vim-gnome包,命令如下:sud

    2022年8月24日
    8
  • perl正则表达式中文问题

    perl正则表达式中文问题
     
    在使用perl从地址中提取街道的时候遇到了个很诡异的问题
    同样一个地址,连续进行两次匹配出来的结果居然不一样
    一次是正常的,一次是乱码,搞了半天没弄明白是怎么回事
    看来perl的中文处理能力还是有待加强
    后来在进行正则匹配之前尝试用了useencoding”gbk”; 
    还算运气不错,居然搞定了
    useencoding”gbk”; 
    $address=~/^(.*(市|区))?(.*?(街|路|道)).*

    2022年5月31日
    23
  • 快速查找Python安装路径方法「建议收藏」

    快速查找Python安装路径方法「建议收藏」我相信一定有很多的人跟我一样,经常忘记Python安装的路径,每当用到的时候,最笨的办法就是在全局电脑里,直接查找Python,这样是肯定能查到的,但是如果你的电脑文件超级多,这将是一个工厂量很大的事情,你要等好久的。便捷的方法时:打开我们的cmd命令输入Python输入importsys输入print(sys.path)列表中的第五个将是你的安装路径…

    2022年6月12日
    48

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号