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;
}
相关推荐
hnjzsyjyj几秒前
东方博宜OJ 1010:数组元素的排序 ← 桶排序
数据结构·排序算法·桶排序
光影6273 分钟前
Python接口自动化测试----Requests库基础入门
开发语言·python·测试工具·pycharm·自动化
程序媛_3 分钟前
【Python】连接PostgreSQL获取手机验证码
开发语言·python·postgresql
ch.ju5 分钟前
Java Programming Chapter 4——Inherited call
java·开发语言
信看8 分钟前
Jetson Orin Quectel QMI 拨号上网
开发语言·python
小欣加油11 分钟前
Leetcode31 下一个排列
数据结构·c++·算法·leetcode·职场和发展
keykey6.11 分钟前
LSTM 文本情感分析:从词嵌入到分类实战
开发语言·人工智能·深度学习·机器学习
凤凰院凶涛QAQ14 分钟前
《Java版数据结构 & 集合类剖析》链表与LinkedList:节点手拉手,增删不用愁
java·数据结构·链表
Cx330❀16 分钟前
【Linux网络】高性能 TCP 服务器:从多线程到线程池的架构演进与落地实践
linux·运维·服务器·网络·c++·tcp/ip·架构
数据知道18 分钟前
网站到底是如何通过JS读取你的浏览器指纹的?
开发语言·javascript·ecmascript·指纹浏览器