C++考试成绩统计(类实现)

题目:有三名同学,在一次考试中三科成绩分别如下表,请输出三名同学的平均成绩:

|----|-----|-----|-----|
| | 语文 | 数学 | 英语 |
| 张三 | 100 | 100 | 100 |
| 李四 | 90 | 50 | 100 |
| 王五 | 60 | 70 | 80 |

cpp 复制代码
#include <iostream>
#include <string>
/*考试成绩统计*/
using namespace std;

class Score {
	private :
		string id;
		int chinese;
		int english;
		int math;
	public :
		Score(string name, int score1, int score2, int score3) : id(name), chinese(score1), english(score2), math(score3) {}
		
		double getAvgScore(){
			return (chinese + math + english) / 3.0;
		}
		
		string getName() {
			return id;
		}
}; 

int main() {
	Score s1("张三", 100, 100, 100);
	Score s2("李四", 90, 50, 100);
	Score s3("王五", 60, 70, 80);
	
	cout << s1.getName() << "的平均成绩是" << s1.getAvgScore() << endl;
	cout << s2.getName() << "的平均成绩是" << s2.getAvgScore() << endl;
	cout << s3.getName() << "的平均成绩是" << s3.getAvgScore() << endl;
	
	return 0;
}
相关推荐
Best-Wishes24 分钟前
科来网络分析系统(技术交流版)使用说明书
开发语言·junit·php
代码不停1 小时前
自动化测试(java)
java·开发语言·selenium·自动化
别动我齐刘海2 小时前
Linux 系统调试学习1
linux·运维·服务器·c++·学习·机器学习·机器人
鬼手点金3 小时前
opencode-rules 插件
java·开发语言·前端·人工智能·chrome·git·github
爱上网的小舟3 小时前
星际战士2启动错误怎么办?5种游戏报错解决方法
开发语言·php
阿里嘎多学长4 小时前
2026-10-12 GitHub 热点项目精选
开发语言·程序员·github·代码托管
wangchunyu1145 小时前
Python 数据可视化实战入门教程
开发语言·python·信息可视化
Shaoshing5 小时前
前缀和与差分
java·数据结构·算法·前缀和·差分
mmmmath_35 小时前
LeetCode.429.N叉树的层序遍历
数据结构·leetcode
学逆向的6 小时前
C 突破编译器限制
c语言·开发语言·网络安全