• 2299: 计算并输出学生成绩


    Problem Description

    (1)编写一个学生类Student,有四个数据成员,姓名char name[20], 语文成绩chinese,数学成绩math,英语成绩eglish。

    (2)从键盘输入三个学生的姓名、语文成绩、数学成绩、英语成绩, 计算每个学生的总分和平均分,并且把所有信息输出到屏幕上。输出的 每一列占12列。

    Input Description

    第一行是从键盘输入的第一个学生的姓名、语文成绩、数学成绩、英语成绩,都用空格隔开,最后输入回车。

    第二行是从键盘输入的第二个学生的姓名、语文成绩、数学成绩、英语成绩,都用空格隔开,最后输入回车。

    第三行是从键盘输入的第三个学生的姓名、语文成绩、数学成绩、英语成绩,都用空格隔开,最后输入回车。

    Output Description

    输出第一行是表头。

    第二、三、四行是三个学生的信息。

    Sample Input

    AAA 87 80 92
    BBB 76 98 85
    CCC 60 99 88

    Sample Output

            Name     Chinese        Math      Eglish         Sum         Ave
             AAA          87          80          92         259          86
             BBB          76          98          85         259          86
             CCC          60          99          88         247          82

    Source/Category

    2018C++考试

    这么简单就不用多说了

    1. #include
    2. #include
    3. using namespace std;
    4. class Student
    5. {
    6. public:
    7. char name[20];
    8. int chinese;
    9. int math;
    10. int eglish;
    11. int fsum()
    12. {
    13. return chinese + math + eglish;
    14. }
    15. int fave()
    16. {
    17. return (chinese + math + eglish) / 3;
    18. }
    19. };
    20. int main()
    21. {
    22. Student s1, s2, s3;
    23. char a[20];
    24. cin >> s1.name >> s1.chinese >> s1.math >> s1.eglish;
    25. cin >> s2.name >> s2.chinese >> s2.math >> s2.eglish;
    26. cin >> s3.name >> s3.chinese >> s3.math >> s3.eglish;
    27. cout << " Name Chinese Math Eglish Sum Ave" << endl;
    28. cout << setw(12) << s1.name << setw(12) << s1.chinese << setw(12) << s1.math << setw(12) << s1.eglish << setw(12) << s1.fsum() << setw(12) << s1.fave() << endl;
    29. cout << setw(12) << s2.name << setw(12) << s2.chinese << setw(12) << s2.math << setw(12) << s2.eglish << setw(12) << s2.fsum() << setw(12) << s2.fave() << endl;
    30. cout << setw(12) << s3.name << setw(12) << s3.chinese << setw(12) << s3.math << setw(12) << s3.eglish << setw(12) << s3.fsum() << setw(12) << s3.fave() << endl;
    31. return 0;
    32. }

  • 相关阅读:
    扫描电子显微镜(SEM)低真空技术改造以提升观测能力的解决方案
    【Java SE】“方法”论 — 《方法的概念及使用》
    如何在 ELEMENTOR 中创建、编辑和设置列样式
    运动颈挂式蓝牙耳机推荐,推荐几款适合佩戴的骨传导耳机
    [BuckeyesCTF 2022] 部分WP
    DedeCMS整合百度ueditor编辑器
    队列的基本操作以及C语言实现
    【笨~~~】在python中导入另一个模块的函数时,为什么会运行模块中剩下的部分??顶层?
    【Go】-调用企微机器人
    华为OD机试真题-任务最优调度-2023年OD统一考试(B卷)
  • 原文地址:https://blog.csdn.net/QQ3503814312/article/details/126682300