跳至内容
Z Courses
A Simple Web Classroom
用户工具
登录
站点工具
搜索
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您在这里:
frontpage
»
趣题
»
cpp
»
期末考试排名
趣题:cpp:期末考试排名
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
<markdown> # 期末考试排名 ## 题目描述 期末考试结束了,班主任想对本班学生的成绩进行一个排名。大概的思路是确定要排名的人数,然后输入这些同学的姓名、语文、数学、外语成绩,最后输出学生姓名、总分及班级排名。 ## 代码参考 </markdown> <sxh cpp> #include <iostream> using namespace std; struct st{ string name; float chinese; float math; float english; float sum; int rank; }; int main() { int n; cout <<"请输入学生数:"; cin >> n; st st1[n]; cout << "请按照以下提示输入:"<<endl; cout <<"姓名 语文 数学 外语"<<endl; for(int i=0;i<n;i++) { cin >> st1[i].name >> st1[i].chinese>>st1[i].math>>st1[i].english; st1[i].sum=st1[i].chinese+st1[i].math+st1[i].english; } for(int i=0;i<n;i++) { int c=1; for(int j=0;j<n;j++) { if(st1[i].sum<st1[j].sum) c++; } st1[i].rank=c; } for(int i=0;i<n;i++) { cout << st1[i].name <<"的总分是:"<<st1[i].sum<<",班级排名:"<<st1[i].rank<<endl; } } </sxh>
页面工具
显示页面
修订记录
反向链接
回到顶部