使用继承 -计算和查找学生成绩

#include<iostream>
#include<string>
#define max 3   //控制数组内学生总人数 
using namespace std;

class base  //基类
{
protected:
	string subjectname;
	int choose;//选择
	int pace;  //填空
};

class china :public base
{
protected:
	int reading;//阅读
	int essay;  //作文
	int translation;//文言文

public:
	int chinascore;
	void get(string subjectname)
	{
		this->subjectname;
		cout << "输入" << subjectname << "选择题得分" << endl;
		cin >> choose;
		cout << "输入" << subjectname << "填空题得分" << endl;
		cin >> pace;
		cout << "输入" << subjectname << "阅读得分" << endl;
		cin >> reading;
		cout << "输入" << subjectname << "作文得分" << endl;
		cin >> essay;
		cout << "输入" << subjectname << "文言文" << endl;
		cin >> translation;
	}
	void sum()
	{
		chinascore = reading + essay + translation + choose + pace + translation;
	}
};

class math :public base
{
protected:
	int count;//计算题
	int wordproblems;//应用题
public:
	int mathscore;
	void get(string subjectname)
	{
		this->subjectname;
		cout << "输入" << subjectname << "选择题得分" << endl;
		cin >> choose;
		cout << "输入" << subjectname << "填空题得分" << endl;
		cin >> pace;
		cout << "输入" << subjectname << "计算题得分" << endl;
		cin >> count;
		cout << "输入" << subjectname << "应用题得分" << endl;
		cin >> wordproblems;
	}
	void sum()
	{
		mathscore = choose + pace + count + wordproblems;
	}
};

class english :public base
{
protected:
	int hearing;//听力
	int reading;//阅读理解
	int translation;//翻译
public:
	int englishscore;//总分

	void get(string subjectname)
	{
		this->subjectname;
		cout << "输入" << subjectname << "选择题得分" << endl;
		cin >> choose;
		cout << "输入" << subjectname << "填空题得分" << endl;
		cin >> pace;
		cout << "输入" << subjectname << "听力得分" << endl;
		cin >> hearing;
		cout << "输入" << subjectname << "阅读理解得分" << endl;
		cin >> reading;
		cout << "输入" << subjectname << "翻译得分" << endl;
		cin >> translation;
	}
	void sum()
	{
		englishscore = choose + pace + hearing + reading + translation;
	}
};

class student :public english, public china, public math
{
public:
	string studentname;

	int studentscore;
	void get()
	{
		cout << "输入学生姓名" << endl;
		cin >> studentname;
	}
	void sumscore()
	{
		studentscore = chinascore + mathscore + englishscore;
	}
	void set()//输出一位学生的所有成绩
	{
		cout << "学生" << studentname << "的语文成绩是" << chinascore << endl;
		cout << "数学成绩为" << mathscore << endl;
		cout << "英语成绩为" << englishscore << endl;
		cout << "总分为" << studentscore << endl;
	}
	void setchina() //展示语文的详细得分
	{
		cout << "学生" << studentname << "的语文选择题得分为" << china::choose << endl;
		cout << "语文填空题得分为" << china::pace << endl;
		cout << "语文阅读题得分为" << china::reading << endl;
		cout << "语文作文得分为" << china::essay << endl;
		cout << "语文文言文得分为" << china::translation << endl;
		cout << "语文总分为" << china::chinascore << endl;
	}
	void setmath()//展示数学详细得分
	{
		cout << "学生" << studentname << "的数学选择题得分为" << math::choose << endl;
		cout << "数学填空题得分为" << math::pace << endl;
		cout << "数学计算题得分为" << count << endl;
		cout << "数学应用题得分为" << wordproblems << endl;
		cout << "数学总分为" << math::mathscore << endl;
	}
	void setenglish()  //展示英语详细得分
	{
		cout << "学生" << studentname << "的英语选择题得分为" << english::choose << endl;
		cout << "英语填空题得分为" << english::pace << endl;
		cout << "英语听力得分为" << hearing << endl;
		cout << "英语阅读理解得分为" << english::reading << endl;
		cout << "英语翻译得分为" << english::translation << endl;
		cout << "英语总分为" << english::englishscore << endl;
	}
};



void shoutest()
{
	cout << "1.存入学生成绩" << endl;
	cout << "2.查看学生成绩" << endl;
	cout << "3.查看学生语文详细得分" << endl;
	cout << "4.查看学生数学详细得分" << endl;
	cout << "5.查看学生英语详细得分" << endl;
	cout << "6.退出" << endl;
}


int main()
{
	student arr[max];
	while (true)
	{
		shoutest();
		int num;
		string name;
		cout << "选择所要继续的功能" << endl;
		cin >> num;
		switch (num)
		{
		case 1:
		{
			for (int i = 0; i < max; i++)
			{
				arr[i].get();
				arr[i].china::get("语文");
				arr[i].china::sum();
				arr[i].math::get("数学");
				arr[i].math::sum();
				arr[i].english::get("英语");
				arr[i].english::sum();
				arr[i].sumscore();
			}
		}
		break;

		case 2:
		{
			cout << "输入查询成绩学生名字" << endl;
			cin >> name;
			for (int i = 0; i < max; i++)
			{
				if (name == arr[i].studentname) 
				{
					arr[i].set();
					system("pause");
					system("cls");
				}
				else
				{
					cout << "查无此人" << endl;
				}
			}
			
		}
		break;
		case 3:
		{
			cout << "输入查询成绩学生名字" << endl;
			cin >> name;
			for (int i = 0; i < max; i++)
			{
				if (name == arr[i].studentname)
				{
					arr[i].setchina();
					system("pause");
					system("cls");
				}
				else 
				{
					cout << "查无此人" << endl;
				}
			}
		}
		break;
		case 4:
		{
			cout << "输入查询成绩学生名字" << endl;
			cin >> name;
			for (int i = 0; i < max; i++)
			{
				if (name == arr[i].studentname)
				{
					arr[i].setmath();
					system("pause");
					system("cls");
				}
				else
				{
					cout << "查无此人" << endl;
				}
			}
			break;
		case 5:
		{
			cout << "输入查询成绩学生名字" << endl;
			cin >> name;
			for (int i = 0; i < max; i++)
			{
				if (name == arr[i].studentname)
				{
					arr[i].setenglish();
					system("pause");
					system("cls");
				}
				else
				{
					cout << "查无此人" << endl;
				}
			}
		}
		break;
		case 6: 
		{
			return 0;
			break;;
		}
			  break;
		}

		}
	}
}

  1. 查无此人 这个是因为挨个循环 没有就无此人 可以间接的表示在数组里的位置 人少还好 人多久很难看
  2. 删了更好看 但是如果确实输入的人没存入就会直接跳过
  3. 用数组存的 因为内存溢出 所以没写所有成绩的求和
  4. 继承的权限

     5.菱形继承 前面标好 具体调用哪里的 调用父类::父类中成员  (同名的)

午安上仙符华 --一只即将熬到猝死的符华单推人

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只符华单推人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值