标签:blog 使用 os io for ar div amp
基于控制台的学生成绩信息管理系统,实现学生的成绩管理,实现学生的增加,删除,查询和总分的计算,并可查看总分排名;
使用技术:C++,STL;后续还会继续完善,包括添加注释,把增加学生功能封装成一个方法,完善输出格式等一些细节的改善
#include<iostream>
#include<string>
#include<list>
#include<algorithm>
using namespace std;
class student{
private:
int No;
string Name;
double Math;
double Eng;
double Chn;
double Cpro;
double Sum;
public:
student(int no,string name,double math,double eng,
double chn,double cpro){
No=no;
Name=name;
Math=math;
Eng=eng;
Chn=chn;
Cpro=cpro;
Sum=math+eng+chn+cpro;
}
void print()
{
cout<<No<<" "<<Name<<" "<<Math<<" "<<Eng<<" "
<<Chn<<" "<<Cpro<<" "<<Sum<<endl;
}
int getno()
{
return No;
}
double getsum()
{
return Sum;
}
~student(){
}
};
void print(list<student> lst);
void print_no(list<student> &lst);
void cmp_no(student& st1,student& st2);
void print_sum(list<student> &lst);
void find(list<student> &lst);
int del(list<student> &lst);
void main_remid();
void score_remind();
int main()
{
int No;
string Name;
double Math;
double Eng;
double Chn;
double Cpro;
list<student> lst;
char op=‘ ‘;
main_remid();
while(op!=‘q‘)
{
cin>>op;
switch(op)
{
case ‘1‘:
score_remind();
print_no(lst);
break;
case ‘3‘:
find(lst);
break;
case ‘4‘:
del(lst);
break;
case ‘5‘:
score_remind();
print_sum(lst);
break;
case ‘6‘:
main_remid();
break;
case ‘2‘:
cout<<"请输入要增加学生的学号:"<<endl;
cin>>No;
bool flag=false;
for(list<student>::iterator it=lst.begin(); it!=lst.end();it++)
if(No==it->getno()){
cout<<"添加失败,此学号已存在,请重新操作"<<endl;
flag=true;
}
if(flag) break;
cout<<"请输入要增加学生的姓名"<<endl;
cin>>Name;
cout<<"请输入要增加学生的数学成绩:"<<endl;
cin>>Math;
cout<<"请输入要增加学生的英语成绩:"<<endl;
cin>>Eng;
cout<<"请输入要增加学生的语文成绩:"<<endl;
cin>>Chn;
cout<<"请输入要增加学生的C语言成绩:"<<endl;
cin>>Cpro;
student st(No,Name,Math,Eng,Chn,Cpro);
lst.push_back(st);
break;
}
if(op!=‘q‘)
cout<<"请继续选择您想要的操作:"<<endl;
}
return 0;
}
void addst()
{
}
void print(list<student> lst)
{
for(list<student>::iterator it=lst.begin();it!=lst.end();it++)
it->print();
}
void print_no(list<student> &lst)
{
int j,i=0;
int a[1024]={0};
for(list<student>::iterator it=lst.begin();it!=lst.end();it++)
a[i++]=it->getno();
sort(a,a+i);
for(j=0;j<i;j++)
for(list<student>::iterator jt=lst.begin();jt!=lst.end();jt++)
if(a[j]==jt->getno())
jt->print();
}
void print_sum(list<student> &lst)
{
int i=0;
double a[1024]={0};
for(list<student>::iterator it=lst.begin();it!=lst.end();it++)
a[i++]=it->getsum();
sort(a,a+i);
while(i--)
for(list<student>::iterator jt=lst.begin();jt!=lst.end();jt++)
if(a[i]==jt->getsum())
jt->print();
}
void find(list<student> &lst)
{
cout<<"请输入要查询学生的学号:"<<endl;
int no;
cin>>no;
for(list<student>::iterator it=lst.begin();it!=lst.end();it++)
{
if(no==it->getno())
it->print();
if(it==lst.end())
cout<<"不存在此学号,请重新选择操作"<<endl;
}
}
int del(list<student> &lst)
{
cout<<"请输入要删除学生的学号:"<<endl;
int no;
cin>>no;
for(list<student>::iterator it=lst.begin();it!=lst.end();it++)
if(no==it->getno())
{
lst.erase(it);
return 0;
}
cout<<"删除失败,不存在此学号"<<endl;
}
void main_remid()
{
cout<<"请选择要执行的操作"<<endl;
cout<<"1.查询所有学生的成绩信息"<<endl;
cout<<"2.增加学生"<<endl;
cout<<"3.查找学生"<<endl;
cout<<"4.删除学生"<<endl;
cout<<"5.查看总分排名"<<endl;
cout<<"6.查看此提示"<<endl;
cout<<"q.退出系统" <<endl;
}
void score_remind()
{
cout<<"学号 "<<"姓名 "<<"数学 "<<"英语"
<<"C语言 "<<"总成绩"<<endl;
}
标签:blog 使用 os io for ar div amp
原文地址:http://www.cnblogs.com/forerve/p/3908716.html