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;
}
相关推荐
larance13 分钟前
机器学习特征预处理之标准化/归一化
开发语言·python·机器学习
夜不会漫长29 分钟前
数据结构:链表
数据结构·链表
农村小镇哥29 分钟前
C#中的字符串格式化
服务器·开发语言·c#
Android洋芋1 小时前
AI辅助C盘清理
c语言·开发语言·人工智能·ai辅助c盘清理
剑锋所指,所向披靡!2 小时前
数据结构之关键路径
数据结构·算法
笨笨饿2 小时前
101_详解USB协议
java·jvm·数据结构
J-Tony112 小时前
【Redis】数据结构&&持久化
数据结构·数据库·redis
来一碗刘肉面2 小时前
队列的链式实现
数据结构·c++·算法·链表
naturerun2 小时前
逐步插入回路法构造欧拉回路的算法
c++·算法
灯澜忆梦3 小时前
Go 语言 _JSON---序列化与反序列化
开发语言·golang·json