一位考北京工业研究生的学长的一道复试题
这个。。有点水呀
题目内容大概就是成绩的录入、查询、筛选以及简单的统计,最后将结果放入txt文本中。
#include
#include
#include
#include
#include
using namespace std;
const int N = 105;
int tempp[N];
int summ;
struct student
{
int num_class;
char name[20];
float sco_math;
}stu[N];
void Init ()
{
for (int i=1; i<=5; i++)
{
printf ("请输入第 %d 个学生的
", i);
printf ("学号:");
scanf ("%d", &stu[i].num_class);
printf ("姓名:");
scanf ("%s", stu[i].name);
printf ("成绩:");
scanf("%f", &stu[i].sco_math);
putchar ('
');
}
}
int select ()
{
int sum_nine = 0;
int fet = 0;
for (int i=1; i<=100; i++)
{
if(9 == (stu[i].num_class%10)+((stu[i].num_class%100)/10))
{
tempp[++fet] = i;
sum_nine++;
}
}
summ = sum_nine;
return sum_nine;
}
float average ()
{
float tem_sum=0;
for (int i=1; i<=summ; i++)
{
tem_sum += stu[tempp[i]].sco_math;
}
return (tem_sum/summ);
}
int main ()
{
int s;
float a;
Init();
s = select();
a = average();
printf ("满足学号‘个位数’和‘十位数’之和为 9 的学号的总数为:%d
", s);
printf ("这些同学的平均数学成绩为:%f
", a);
ofstream ss;
ss.open("select.txt");
for (int i=1; i<=summ; i++)
{
ss << stu[tempp[i]].num_class << ' ' << stu[tempp[i]].name << ' ' << stu[tempp[i]].sco_math;
ss << endl;
}
ss.close();
printf ("
Thank you very much!
Good bey!
");
return 0;
}