中易网

如何编写能录入学生成绩和修改并且能查询学生平均成绩和总成绩及班级排名的程序。

答案:2  悬赏:70  
解决时间 2021-01-30 02:28
相关是C语言编写代码
最佳答案
这个是 链表的 你知道的~~~
全部回答
#include # include # include # include # include # include // struct stuatom { char *name; int id; char sex; float math, eng, comp, totll, aver; void show(); void setup(); }; // class student { private: stuatom ob[100]; int stulen; public: student(); void input(); void order(); void save(); void check(); void clean(); void query(); void read(); void add(); void del(); void modify(); }; // student::student() { //用for循环对全部数组中的数据初始化 for(int i=0;i <100;i++) { ob[i].math=ob[i].eng=ob[i].comp =ob[i].totll =ob[i].aver =0; ob[i].id =0; ob[i].sex =' '; ob[i].name =null; } this->stulen =0; } // void stuatom::setup() { char n[20]; char s; int b; //如果输入学号在数据域内,跳出循环并且赋值。 //如果不在数据域内,一直循环到输入数据符合数据域为止 do { cout<<" 学号(1001与1020之间): "; cin>>b; if(b>1020||b <1001) cout<<" 数据有误!!重新输入.."<1020); id=b; //如果输入姓名在数据域内,跳出循环并且赋值。 //如果不在数据域内,一直循环到输入数据符合数据域为止 do { name=new char[strlen(n)+1]; cout<<" 姓名: "; cin>>n; }while ( strlen(n)>6 && strlen(n) <4 ); //等于没判断 strcpy(name,n); cout<<" 性别(m/f):" ; cin>>s; //如果输入性别在数据域内,跳出循环并且赋值。 //如果不在数据域内,一直循环到输入数据符合数据域为止 while (s!='m' && s!='f') { cout<<" 数据有误!!重新输入.."<>s; } sex=s; float m, e, co; cout<<" 数学(0-100): "; cin>>m; //如果输入成绩在数据域内,跳出循环并且赋值。 //如果不在数据域内,一直循环到输入数据符合数据域为止 while (m <0 || m>100) { cout<<" 数据有误!!重新输入.."<>m; } math=m; cout<<" 英语(0-100): "; cin>>e; while (e <0 || e>100) { cout<<" 数据有误!!重新输入.."<>e; } eng=e; cout<<" c++(0-100): "; cin>>co; while (co <0 || co>100) { cout<<" 数据有误!!重新输入.."<>co; } comp=co; totll=math+eng+comp; aver=(math+eng+comp)/3; } // void stuatom::show() { cout.setf(ios::left); cout.width(6); cout<<""<n; int j,i; //通过循环输入要求输入学生个数的学生的数据。 for(j=(this->stulen+1) ; j <=(this->stulen+n); j++) { cout <<" 输入学生信息 " <stulen!=0) { for (i=0;istulen ;i++) { for(j=this->stulen ;j<(this->stulen+n);j++) { if (ob[i].id==ob[j].id) { if (c==0) //c只是为了美观而已。。 { cout<<" 错误!系统检测到第"<<(j+1 )<<"位学生学号与第"<<(i+1)<<"位学生学号相同\n"; a[b]=j; b++;c++; } else { cout<<" 第"<<(j+1 )<<"位学生学号与第"<<(i+1)<<"位学生学号相同\n"; a[b]=j; b++;c++; } } } } for(c=0;c>y; while(y!='y'&& y!='y'&& y!='n'&& y!='n') { cout<<" 无效的命令,请重新输入..\n"; cout<<" 是否重新输入第"<<(a[c]+1)<<"位学生成绩?(y/n--选n则第"<<(a[c]+1)<<"位学生成绩将不保存)"; cin>>y; } if(y=='y'||y=='y') { d=a[c]; ob[d].setup(); } else { n--; for(d=a[c];d<(this->stulen+n);d++) ob[d]=ob[d+1]; for(d=(c+1);d>y; while(y!='y'&& y!='y'&& y!='n'&& y!='n') { cout<<" 无效的命令,请重新输入..\n"; cout<<" 是否重新输入第"<<(a[c]+1)<<"位学生成绩?(y/n--选n则第"<<(a[c]+1)<<"位学生成绩将不保存)"; cin>>y; } if(y=='y'||y=='y') { d=a[c]; ob[d].setup(); } else { n--; for(d=a[c];dstulen ; j <(this->stulen+n); j++) { ob[j].show(); } this->stulen+=n; //学生个数赋值 } // void student::query() { int x; cout <>x; int i; for(i=0;i stulen ;i++) { if (x==ob[i].id) break; } if(istulen ) { cout <<" 学号 姓名 性别 数学 英语 c++ 总分 平均分" <stulen; i++) { outfile <stulen ; outfile1.close(); } // void student::clean() { int i; char b[20]; ifstream infile; infile.open("list.txt",ios::in); if(!infile) { for(int i=(this->stulen-1);i <100;i++) { ob[i].math=ob[i].eng=ob[i].comp =ob[i].totll =ob[i].aver =0; ob[i].id =0; ob[i].sex =' '; ob[i].name =null; } this->stulen=0; ifstream infile1; infile1.open("stulen.txt",ios::in); infile1>>this->stulen ; infile1.close(); } else { ifstream infile1; infile1.open("stulen.txt",ios::in); infile1>>this->stulen ; infile1.close(); for(i=0;istulen ;i++) { infile>>ob[i].id; ob[i].name =new char[strlen(b)+1]; infile>>b; strcpy(ob[i].name,b); infile>>ob[i].sex ; infile>>ob[i].math ; infile>>ob[i].eng; infile>>ob[i].comp; infile>>ob[i].totll; infile>>ob[i].aver ; } infile.close (); } } // void student::read() { int i; float averm,avere,averc; averm=avere=averc=0; //system("cls"); cout <stulen; i++) { ob[i].show(); } cout <<"\n\n\n"; for(i=0; i stulen; i++) { averm +=ob[i].math; } if(i!=0) cout <<" 数学平均成绩为" stulen++; ofstream fout("list.txt",ios::app); if(!fout) { cout <<" 无法打开数据文件!\n,"; } //把添加的学生数据添加到list.txt里边去。 fout <stulen ; outfile1.close(); _getch(); } // void student::del() { int i,p; int x; p=-1; if(this->stulen==0) { cout<<" 目前没有学生成绩!"; _getch(); } else { cout <stulen; i++) { ob[i].show(); } char a; cout <<"\n\n 输入要删除的学生学号:" ; cin>>x; //通过for循环查找要删除学生的学号 for(i=0; i "; cin>> a; if (a=='y'|| a=='y') { cout <<" 删除成功!" <stulen; i++) { outfile <stulen ; outfile1.close(); this->read (); //_getch(); } else { cout<<" 回到主界面..."; _getch(); } } } } // void student::order() { int k,j; float t; char n[20]; cout <<" 成绩排名:" <stulen; i++) { ob[i].show(); } cout <<"\n\n 请输入要修改学生的学号:"; cin>>a; for(i=0; i >b; while(b!=1 &&b!=2 &&b!=3) { cout<<" 无效输入,请重新输入!\n"; cout<<"\n\n 请输入要修改的课程名的编号(1.数学, 2.英语,3.c++):"; cin>>b; } switch(b) { case 1: { float m; cout<<" 数学(0-100): "; cin>>m; //如果输入成绩在数据域内,跳出循环并且赋值。 //如果不在数据域内,一直循环到输入数据符合数据域为止 while (m <0 || m>100) { cout<<" 数据有误!!重新输入.."<>m; } ob[p].math=m;break; } case 2: { float e; cout<<" 英语(0-100): "; cin>>e; while (e <0 || e>100) { cout<<" 数据有误!!重新输入.."<>e; } ob[p].eng=e; break; } case 3: { float co; cout<<" c++(0-100): "; cin>>co; while (co <0 || co>100) { cout<<" 数据有误!!重新输入.."<>co; } ob[p].comp=co; } } ob[p].totll=ob[p].math+ob[p].eng+ob[p].comp; ob[p].aver=(ob[p].math+ob[p].eng+ob[p].comp)/3; ofstream outfile; outfile.open("list.txt",ios::trunc); for(i=0; i stulen; i++) { outfile <>this->stulen ; infile1.close(); for(i=0;istulen ;i++) { infile>>ob[i].id; ob[i].name =new char[strlen(b)+1]; infile>>b; strcpy(ob[i].name,b); infile>>ob[i].sex ; infile>>ob[i].math ; infile>>ob[i].eng; infile>>ob[i].comp; infile>>ob[i].totll; infile>>ob[i].aver ; } infile.close (); //学生数据显示格式 system("cls"); cout<<" 系统检测到以前输入过数据,数据内容如下:\n\n"; cout <stulen; i++) { ob[i].show(); } cout<<"\n\n\n"; cout<<" 原始数据是否覆盖?(y/n)"; char q; cin>>q; while(q!='y'&& q!='y'&& q!='n'&& q!='n') { cout<<" 无效的命令,请重新输入..\n"; cout<<" 原始数据是否覆盖?(y/n)"; cin>>q; } if(q=='y'||q=='y') { for(int i=0;i <100;i++) { ob[i].math=ob[i].eng=ob[i].comp =ob[i].totll =ob[i].aver =0; ob[i].id =0; ob[i].sex =' '; ob[i].name =null; } this->stulen =0; ofstream outfile1; outfile1.open("stulen.txt",ios::trunc); outfile1<stulen ; outfile1.close(); system("del list.txt"); } } } // void menu() { cout <<"\n\n"; cout <<"------------------ 学生成绩系统 -----------------" <>sel; switch(sel) { case 1: system("cls"); a.input(); cout <>y; while(y!='y'&& y!='y'&& y!='n'&& y!='n') { cout<<" 无效的命令,请重新输入..\n"; cout<<" 是否保存? (y/n)"; cin>>y; } system("cls"); if(y=='y'||y=='y') a.save(); else a.clean(); break; case 2: system("cls"); a.read(); break; case 3: system("cls"); a.del(); break; case 4: system("cls"); a.add();break; case 5: system("cls"); a.query();break; case 6: system("cls"); a.modify();break; case 7: system("cls"); a.order();break; case 8: exit(0); default: cout <<" 无效的命令!"; _getch(); break; } } }
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
问道海外版怎么我几个月没上角色都没了 怎么
2016NbA总决赛第五场比赛结果
为什么要经济侦查
我姐姐的师傅我怎么叫
大众甲壳虫有奶黄色的吗
一元硬币是铁质的吗?我拿吸铁石吸了吸,有的
请问Fortran是一门面向什么滴编程语言??
一辆汽车每分钟行驶1.2千米,1小时40分可行驶
开发手机 游戏要用什么设备 工具。 就是招来
创办了“精武门”的中国清末爱国武术家是谁?
一个人怎么能同时拥有两个微信号
狗狗淌青水鼻涕萎靡不振是什么原因
Bonium英语什么意思
造梦西游iPad每天不刷新抽奖、挑战三太子等是
dnf瞎子雷神之息关了还有光属性吗
推荐资讯
上河村地址有知道的么?有点事想过去
淘宝客中的API、APPKEY、AppSecret和淘点金各
求一个JDK1.7的安装包。
代表不服输,积极向上,永恒的词语,有吗
兄弟菜馆在哪里啊,我有事要去这个地方
谁发现的葡萄酒
弗兰德斯语言互动分析的数据整理(数字矩阵等
孟非是怎么用一句话概括什么叫公主,什么叫公
本人在四线城市,已买房,无房代,本人月收入
联想amd k12主板 内存条
裤子扣掉了,在淘宝买了扣子,怎么自己装好?
曾经很爱我的男人被我伤得很深,十年之后
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?