个人答案:
①
#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();
input_data();
cout << endl << "不及格者:" << endl;
for (i = 0; i < n; i++)
{
if (score[i] < 60)
cout << name[i] << " + " << num[i] << " + " << score[i] << endl;
}
return 0;
}
void input_data()
{
int i;
for (i = 0; i < n; i++)
{
cout << "请输入第 " << i + 1 << " 个学生的姓名、学号、成绩 :";
cin >> name[i] >> num[i] >> score[i];
}
}
②
#include <iostream>
#include <iomanip>//控制输出
#include <string>//字符串处理
using namespace std;
int main()
{
string s[10];
int num[10], i;
float score[10];
for (i = 0; i < 10; i++)
{
cout << "请输入第" << i + 1 << " 个学生的名字,学号,成绩: ";
cin >> s[i] >> num[i] >> score[i];//输入学生的名字,学号,成绩
}
for (i = 0; i < 10; i++)
if (score[i] < 60)//输出不合格的条件
cout << setw(8) << s[i] << ' ' << num[i] << ' ' << score[i] << endl;//setw(8)为控制输出宽度
system("pause");
return 0;
}
结果(其一):
参考答案:
#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();
input_data();
cout<<endl<<"The list of failed:"<<endl;
for(i=0;i<n;i++)
if(score[i]<60)
cout<<name[i]<<" "<<num[i]<<" "<<score[i]<<endl;
return 0;
}
void input_data()
{int i;
for (i=0;i<n;i++)
{cout<<"input name,number and score of student "<<i+1<<":";
cin>>name[i]>>num[i]>>score[i];}
}