c++ 的学生成绩管理的开端 继承

首先 创建基类 :明确基类属性:教师 学生只有姓名共同

/* SchoolBase.h*/
#pragma once
#include<iostream>
using namespace std;
class SchoolBace
{
public:
	SchoolBace(string name);
	virtual ~SchoolBace(){}
	virtual void display() = 0;
protected:
	string name;//姓名
};
/* SchoolBase.cpp*/
#include "SchoolBace.h"

SchoolBace::SchoolBace(string name)
{
	this->name = name;
}

第二部,设计学生类,只涉及了中学,其他按照这个修改即可


/*student.h*/
#pragma once
#include"SchoolBace.h"
class mStudent :public SchoolBace
{
public:
	void display();
	mStudent(int n, string name);
	~mStudent();
protected:
	int Id = 0;
	int n = 0;
	double sumScore = 0;//总分
	double* courseScore;//单科得分
	string* courseName;//科目名
	string className;	//班级
	static int stuNum;
};

/*student.cpp*/
#include "Student.h"
int mStudent::stuNum = 1000;

void mStudent::display()
{
	cout << "学生姓名" << this->name << endl;
	cout << "学生编号为" << this->Id << endl;

	for (int i = 0; i < this->n; i++) {
		cout << "学生" << name << "的第" << i + 1 << "门课程名为:"<<this->courseName[i]<<"对应分数为 "<<this->courseScore[i] << endl;
	}
	cout << "学生" << name << "所在班级为" <<this->className<< endl;
	cout << "学生" << name << "总成绩为" << this->sumScore << endl;
}

mStudent::mStudent(int n, string name) :SchoolBace(name)
{
	this->courseName = new string[n];
	this->courseScore = new double[n];
	this->n = n;
	for (int i = 0; i < n; i++) {
		cout << "请输入" << name << "的第"<<i+1<<"门课程名及对应分数 如张xx 20.0:  " ;
		cin >> this->courseName[i] >> this->courseScore[i];
		this->sumScore += courseScore[i];
	}
	cout << "请输入" << name << "所在班级 如xxx122:  " ;
	cin >> this->className;
	this->Id = ++stuNum;
}
mStudent::~mStudent()
{
	cout << "系统退出" << endl;
	delete[] this->courseName;
	delete[] this->courseScore;
}

最后 主函数方法

#include"Student.h"
int main()
{
	SchoolBace* Stu = new mStudent(2, "张三");
/*这里n表示科目,第二个为姓名 可以自定义*/

	Stu->display();
	delete Stu;
	getchar();
	return 0;
}

 

有问题错误请留言或私信

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实验题目1:班级学生学期成绩管理系统 (1)程序功能简介 灵活运用类的继承、对象成员等机制,设计一个能够实现班级学生学期成绩管理的程序。 (2)程序设计说明 ① 个人信息类CPerson的数据成员有姓名、性别、年龄、身份证号等数据成员,成员函数根据需要自行设计; ② 学生类CStudent从CPerson派生,并增加学号、CCourse对象成员数组(大小至少3个)等数据成员,并根据需要自行设计成员函数,包括能够求解所选修课程的总学分、显示某个学生基本信息和课程信息的成员函数; ③ 课程类CCourse包括课程名、学分、分数、任课老师等数据成员,成员函数根据需要自行设计; ④ 班级类CClass的数据成员有班级名称、班级人数、CStudent对象成员数组(大小由构造函数确定)等。本班级类CClass的对象成员数组需要在构造函数中用new动态分配内存空间,在析构函数中用delete释放。在CClass类中设计包括能够求解最高成绩、最低成绩和平均成绩以及通过学号查找并输出某个学生全部信息(例如Seek())等功能在内的成员函数; ⑤ 构造三十个学生的数据,每个学生都有三门课程成绩,输出并显示这些数据; ⑥ 根据类的需要添加适当的其它成员,编完整的程序并测试。 (3)程序调试运行 运行程序查看结果,并进行源代码调试和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值