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;
}
相关推荐
就叫飞六吧7 分钟前
子页面和dialog案例
开发语言·javascript·ecmascript
Jayden_Ruan21 分钟前
C++组合的输出
c++·算法·深度优先
倒流时光三十年1 小时前
Logback 系列(3):三大核心组件 Logger / Appender / Encoder
java·开发语言·logback
什巳1 小时前
JAVA练习312- 二叉搜索树中第 K 小的元素
java·数据结构·算法·leetcode
froyoisle1 小时前
CSP 真题解析:[CSP-J 2020-T3] 表达式
c++·算法·csp·信息学·信奥赛
Darkwanderor1 小时前
动、静态库相关内容的详细介绍
linux·c语言·开发语言·c++
文祐1 小时前
C++类之虚函数表没有虚继承的菱形继承
开发语言·c++·算法
sycmancia2 小时前
Qt——另一种创建线程的方式
开发语言·qt
你怎么知道我是队长2 小时前
JavaScript 函数 this 全解
开发语言·javascript·ecmascript
L-影2 小时前
单体项目结构
java·开发语言