栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

P256学生类练习题

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

P256学生类练习题

#include
#include
using namespace std;

class Student
{
public:
	Student(int number = 0, const char* name = "", float score = 0.0);//对于字符串,此处必须加const
	Student(const Student& Stu);
	~Student();
	
	void show(void);
	friend void Average(const Student* p, int length);
	friend void SetProperty(Student* p, int length);
private:
	int number;
	char name[20];
	float score;
};

Student::Student(int number, const char* name, float score)
{
	this->number = number;
	strcpy_s(this->name, strlen(name) + 1, name);
	this->score = score;
}

Student::Student(const Student& Stu)
{
	this->number = Stu.number;
	strcpy_s(this->name, strlen(Stu.name) + 1, Stu.name);
	this->score = Stu.score;
}


void Student::show(void) {
	cout << "学号:" << number << " 姓名:" << name << " 分数" << score << endl;
}
void Average(const Student* p,  int length) {
	double sum = 0;
	for (int i = 0; i < length; i++) {
		sum = sum + (p + i)->score;
	}
	cout<<"平均分"<number = i;
		cout << "学号:" << i << endl;
		cout << "姓名:";
		cin >> (p + i)->name;
		cout << "分数:";
		cin >> (p + i)->score;
		cout << endl;
	}
}
Student::~Student()
{
}


int main(void) {
	//Student S[3] = { Student(202001, "张三", 98),Student(202002, "李四", 88),Student(202003, "王五", 78)};
	//cout << average(S);
	Student* p = new Student[3];
	SetProperty(p, 3);
	Average(p,3);
	for (int i = 0; i < 3; i++) {
		(p + i)->show();
	}
	delete []p;


	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/303960.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号