《C++程序设计POJ》《WEEK2 类和对象初探》
简单的学生信息处理程序实现
在一个学生信息处理程序中,要求实现一个代表学生的类,并且所有成员变量都应该是私有的。
(注:评测系统无法自动判断变量是否私有。我们会在结束之后统一对作业进行检查,请同学们严格按照题目要求完成,否则可能会影响作业成绩。)
输入姓名,年龄,学号,第一学年平均成绩,第二学年平均成绩,第三学年平均成绩,第四学年平均成绩。
其中姓名、学号为字符串,不含空格和逗号;年龄为正整数;成绩为非负整数。
各部分内容之间均用单个英文逗号","隔开,无多余空格。输出一行,按顺序输出:姓名,年龄,学号,四年平均成绩(向下取整)。
各部分内容之间均用单个英文逗号","隔开,无多余空格。样例输入
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; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix