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;
}
相关推荐
不灭的黄金瞳1232 小时前
Java数据类型与变量
java·开发语言·intellij-idea
f狐0狸x2 小时前
【C++修炼之路】C++继承的探索
c++·继承
程序猫.2 小时前
算法刷题笔记:模拟题从入门到实战(含 LeetCode 例题与习题)
java·数据结构·算法
虚无的纽扣2 小时前
【C++】C++11的魔法:不止右值引用,C++11赋予的编程神力
c++
小白学大数据3 小时前
Python 项目实战:用 Flask 构建生产级 MySQL 增删改查 REST API
开发语言·人工智能·python·mysql·flask
Nil2083 小时前
leetcode 20有效的括号
开发语言
jaysee-sjc3 小时前
【苍穹外卖】Day01:从零认识企业级项目开发
java·开发语言·数据库·mysql·spring·intellij-idea·mybatis
码匠许师傅3 小时前
【C++三方组件】RE2:工业级正则的安全与性能
c++
ThornArmor3 小时前
《向内深潜,向外飞掠》
c语言·开发语言·c++·vim·visual studio
传奇开心果编程3 小时前
【仓颉语言基础语法学与练】第1课:从零开始
开发语言·学习·华为