17周课后自主-项目6-1-输入学生信息输出

来源:互联网 发布:淘宝优惠券链接打不开 编辑:程序博客网 时间:2024/06/13 18:21
#include<iostream>using namespace std;struct Student  //定义结构体{    char    num[13];    char    name[10];    int     cpp;    int     math;    int     english;    int     score;    double  avg;    void    print(); //成员函数};const int N = 3;int main(){    int i;    Student stu[N];    for(i = 0;i < N;i++)    {        cin >> stu[i].num >> stu[i].name            >> stu[i].cpp >> stu[i].math >> stu[i].english;    }    cout << "number\t\tname\tscore\taverage\n";    for(i = 0;i < N;i++)    {        stu[i].print();        cout << endl;    }}void Student::print() //函数实现{    score = cpp + math + english;    avg   = score / 3.0;    cout << num   << "\t"         << name  << '\t'         << score << '\t'         << avg   << '\t';}

运行结果



0 0