zoukankan      html  css  js  c++  java
  • 编程作业—C++初探 简单的学生信息处理程序实现

    简单的学生信息处理程序实现

    来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩。)

    注意: 总时间限制: 1000ms 内存限制: 65536kB

    描述

    在一个学生信息处理程序中,要求实现一个代表学生的类,并且所有成员变量都应该是私有的。

    (注:评测系统无法自动判断变量是否私有。我们会在结束之后统一对作业进行检查,请同学们严格按照题目要求完成,否则可能会影响作业成绩。)

    输入

    姓名,年龄,学号,第一学年平均成绩,第二学年平均成绩,第三学年平均成绩,第四学年平均成绩。

    其中姓名、学号为字符串,不含空格和逗号;年龄为正整数;成绩为非负整数。

    各部分内容之间均用单个英文逗号","隔开,无多余空格 

    输出

    一行,按顺序输出:姓名,年龄,学号,四年平均成绩(向下取整)。

    各部分内容之间均用单个英文逗号","隔开,无多余空格。

    样例输入

    Tom,18,7817,80,80,90,70

    样例输出

    Tom,18,7817,80

     1 #include <iostream>
     2 #include<string>
     3 #include<cstdio>
     4 using namespace std;
     5 class Student {
     6 private:
     7     int age, score1, score2, score3, score4;
     8     char name[100], num[100];
     9     int average;
    10 public:
    11     Student(char aname[], int aage, char anum[],int ascore1, int ascore2, int ascore3, int ascore4) {
    12         strcpy(name, aname);
    13         age = aage;
    14         strcpy(num, anum);
    15         score1 = ascore1;
    16         score2 = ascore2;
    17         score3 = ascore3;
    18         score4 = ascore4;
    19     }
    20 
    21     int getAverage() {
    22         return (score1 + score2 + score3 + score4) / 4;
    23     }
    24 
    25     char * getName() {
    26         return name;
    27     }
    28 
    29     int getAge() {
    30         return age;
    31     }
    32 
    33     char * getNum() {
    34         return num;
    35     }
    36 
    37 };
    38 int main() {
    39     char name[100], a, num[100];
    40     int age, score1, score2, score3, score4;
    41     cin.getline(name, 100, ',');
    42     cin >> age;
    43     a = getchar();
    44     cin.getline(num, 100, ',');
    45     cin >> score1 >> a >> score2 >> a >> score3 >> a >> score4;
    46     Student s(name, age, num, score1, score2, score3, score4);
    47     cout << s.getName() << "," << s.getAge() << "," << s.getNum() << "," << s.getAverage();
    48     return 0;
    49 }
  • 相关阅读:
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    微信小程序TodoList
    C语言88案例-找出数列中的最大值和最小值
    C语言88案例-使用指针的指针输出字符串
  • 原文地址:https://www.cnblogs.com/dagon/p/4739583.html
Copyright © 2011-2022 走看看