【C++面向对象程序设计】设计CStudent类进行统计

C++面向对象程序设计
题目:设计一个CStudent类,并使CStudent类具有以下特点:

(1)该类具有学生姓名、学号、某几门课的课程成绩
(2)学生信息全部由键盘输入,以提高程序的适应性
(3)通过成员函数统计学生的平均成绩,当课程数量增加时无需修改仍可求出平均成绩
(4)输出学生的基本信息、各科成绩与平均成绩
(5)学生对象的定义采用对象数组实现
(6)统计不及格学生的人数

#include <iostream>
#include <string>
using namespace std;
class CStudent
{
	string name;
	string ID;
	double ach[10];
	double ave = 0;
	int num;
	static int count;
public:
	CStudent(string i_name, string i_ID, int i_num, double* i_ach)
{
	name = i_name;
	ID = i_ID;
	num = i_num;
	for (int i = 0; i < num; i++)
	{
		ach[i] = i_ach[i];
		ave += ach[i] / num;
	}
	for (int i = 0; i < num; i++)
	{
		if (ach[i] < 60)
		{
			count++;
			break;
		}
	}
}
	CStudent(){
	};
	void Print(){
		for (int i = 0; i < num; i++)
		cout << "第" << i+1 << "门成绩为:" << ach[i] << endl;
	cout << "平均成绩为:" << ave << endl;
	};
	void print(){
		cout << "不及格人数为:" << count << endl;
	};
};
int CStudent::count = 0;
int main()
{
	CStudent student[100] = {};
	int n;
	double ach[10];
	string name, ID;
	cout << "共需要录入多少学生的成绩" << endl;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cout << "请输入学生的姓名" << endl;
		cin >> name;
		cout << "请输入学生的学号" << endl;
		cin >> ID;
		int j;
		cout << "请输入该学生需要录入多少门成绩" << endl;
		cin >> j;
		for (int m = 0; m < j; m++)
		{
			cout << "请输入该学生的第" << m+1 << "门成绩" << endl;
			cin >> ach[m];
		}
		student[i] = CStudent(name, ID, j, ach);
		student[i].Print();
	}
	student[0].print();
	return 0;
}

 


 

  • 6
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

李 吉 脖.

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

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

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

打赏作者

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

抵扣说明:

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

余额充值