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;
}
相关推荐
玖笙&2 分钟前
✨WPF编程基础【3.3】:容器控件(附源码)
c++·wpf·visual studio
汉克老师16 分钟前
GESP5级C++考试语法知识(十七、二分算法提高篇(二))
c++·算法·二分算法·gesp5级·gesp五级·二分算法易错点
信奥胡老师1 小时前
B3968 [GESP202403 五级] 成绩排序
数据结构·算法
我材不敲代码1 小时前
Python 基础:列表的切片与嵌套列表使用技巧
开发语言·python
彦为君1 小时前
JavaSE-03-集合框架(详细版)
java·开发语言·python
我材不敲代码1 小时前
Python 正则表达式进阶实战:从文本清洗到复杂信息提取
c++·python·正则表达式
我命由我123451 小时前
Android Framework P3 - MediaServer 进程、认识 ServiceManager 进程
android·c语言·开发语言·c++·visualstudio·visual studio·android runtime
:1211 小时前
java基础---一些没注意的
java·开发语言
计算机安禾1 小时前
【c++面向对象编程】第48篇:Lambda表达式与std::function:OOP中的函数式编程
java·c++·算法
yuhuofei20211 小时前
【Python入门】Python中的输入与输出
开发语言·python