简单的学生信息处理程序实现
在一个学生信息处理程序中,要求实现一个代表学生的类,并且所有成员变量都应该是私有的。
(注:评测系统无法自动判断变量是否私有。我们会在结束之后统一对作业进行检查,请同学们严格按照题目要求完成,否则可能会影响作业成绩。)
输入姓名,年龄,学号,第一学年平均成绩,第二学年平均成绩,第三学年平均成绩,第四学年平均成绩。
其中姓名、学号为字符串,不含空格和逗号;年龄为正整数;成绩为非负整数。
各部分内容之间均用单个英文逗号","隔开,无多余空格。输出一行,按顺序输出:姓名,年龄,学号,四年平均成绩(向下取整)。
各部分内容之间均用单个英文逗号","隔开,无多余空格。样例输入
Tom,18,7817,80,80,90,70
样例输出
Tom,18,7817,80
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<string> #include<cstdio> using namespace std; class student { private: string name; unsigned int age; string ID; unsigned int score_first; unsigned int score_second; unsigned int score_third; unsigned int score_fourth; unsigned int score_average; public: student(string _name, unsigned int _age, string _ID, unsigned int _score_first, unsigned int _score_second, unsigned int _score_third, unsigned int _score_fourth) { name = _name; age = _age; ID = _ID; score_first = _score_first; score_second = _score_second; score_third = _score_third; score_fourth = _score_fourth; score_average = (score_first + score_second + score_third + score_fourth) / 4; } unsigned int get_score_average() { return score_average; } unsigned int get_age() { return age; } string get_name() { return name; } string get_ID() { return ID; } }; int main() { string name; unsigned int age; string ID; unsigned int score_first; unsigned int score_second; unsigned int score_third; unsigned int score_fourth; //unsigned int score_average; char* c_name = new char[100]; char* c_ID = new char[100]; scanf("%[^,],%d,%[^,],%d,%d,%d,%d", c_name, &age, c_ID, &score_first, &score_second, &score_third, &score_fourth); name = c_name; ID = c_ID; student stu(name, age, ID, score_first, score_second, score_third, score_fourth); cout << stu.get_name() << "," << stu.get_age() << "," << stu.get_ID() << "," << stu.get_score_average(); delete []c_name; delete []c_ID; return 0; }