C++编程题:输入10个学生的姓名、学号和成绩,输出学生的成绩等级和不及格人数。 20
3个回答
展开全部
#include<iostream>
#include<string>
using namespace std;
const int n=10;
string name[n]; //定义姓名数组
int num[n],score[n]; //定义学号和成绩数组
int main()
{int i;
void input_data();
int_data();
cout<<endl<<"不及格名单:"<<endl;
for(i=0;i<n;i++)
if(score[i]<60)
cout<<"name[i]"<<" "<<"num[i]"<<" "<<score[i]<<endl;
return 0;
}
viod input_data()
{int i;
for(i=0;i<n;i++)
{cout<<"请输入学生的姓名、学号和成绩"<<i+1<<":";
cin>>name[i]>>num[i]>>score[i];
}
return 0;
}
2014-05-05
展开全部
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
struct Student
{
string name;
double acct;
double score;
};
int main()
{
Student students[10];
int counts=0;
int countA=0;
int countB=0;
int countC=0;
int countD=0;
for(int i=0;i<10;i++)
{
cout<<"Enter students"<<i+1<<" name : "<<endl;
getline(cin,students[i].name);
cout<<"Enter students"<<i+1<<" acct: "<<endl;
cin>>students[i].acct;
cout<<"Enter students"<<i+1<<" score: "<<endl;
cin>>students[i].score;
while(cin.get()!='\n')
continue;
}
for(int i=0;i<10;i++)
{
if(students[i].score<60)
countD++;
else if(students[i].score<70)
countC++;
else if(students[i].score<80)
countB++;
else if(students[i].score<90)
countA++;
else
counts++;
}
cout<<"not pass: "<<countD<<endl;
cout<<"60~70: "<<countC<<endl;
cout<<"70~80: "<<countB<<endl;
cout<<"80~90: "<<countA<<endl;
cout<<"90~100: "<<counts<<endl;
system("pause");
return 0;
}
简单来说估计就是这样。
如果要求输出每个学生的等级稍微修改一下就可以了。
#include<string>
#include<cstring>
using namespace std;
struct Student
{
string name;
double acct;
double score;
};
int main()
{
Student students[10];
int counts=0;
int countA=0;
int countB=0;
int countC=0;
int countD=0;
for(int i=0;i<10;i++)
{
cout<<"Enter students"<<i+1<<" name : "<<endl;
getline(cin,students[i].name);
cout<<"Enter students"<<i+1<<" acct: "<<endl;
cin>>students[i].acct;
cout<<"Enter students"<<i+1<<" score: "<<endl;
cin>>students[i].score;
while(cin.get()!='\n')
continue;
}
for(int i=0;i<10;i++)
{
if(students[i].score<60)
countD++;
else if(students[i].score<70)
countC++;
else if(students[i].score<80)
countB++;
else if(students[i].score<90)
countA++;
else
counts++;
}
cout<<"not pass: "<<countD<<endl;
cout<<"60~70: "<<countC<<endl;
cout<<"70~80: "<<countB<<endl;
cout<<"80~90: "<<countA<<endl;
cout<<"90~100: "<<counts<<endl;
system("pause");
return 0;
}
简单来说估计就是这样。
如果要求输出每个学生的等级稍微修改一下就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
具体点,成绩等级的对应关系是什么样的?是否要写成面向对象的?是否要求接口与实现分离?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询