一篇复试题

一位考北京工业研究生的学长的一道复试题
这个。。有点水呀
题目内容大概就是成绩的录入、查询、筛选以及简单的统计,最后将结果放入txt文本中。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <fstream>
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 个学生的\n", i);
        printf ("学号:");
        scanf ("%d", &stu[i].num_class);
        printf ("姓名:");
        scanf ("%s", stu[i].name);
        printf ("成绩:");
        scanf("%f", &stu[i].sco_math);
        putchar ('\n');
    }
}

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 \n", s);
    printf ("这些同学的平均数学成绩为:%f \n", a);

    /////////////////////////////////////////////
    ofstream ss;
    ss.open("select.txt");
    for (int i=1; i<=summ; i++)
    {
        ss << stu[tempp[i]].num_class << '\t' << stu[tempp[i]].name << '\t' << stu[tempp[i]].sco_math;
        ss << endl;
    }
    /////////////////////////////////////////////
    ss.close();
    printf ("\n Thank you very much! \n Good bey! \n");
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值