首页 > 软件 > 声明一个Student类,在该类中包括一个数据成员score(分数)、两个静态数据成员total

声明一个Student类,在该类中包括一个数据成员score(分数)、两个静态数据成员total

软件 2023-07-01

声明一个Student类,在该类中包括一个数据成员score(分数)、两个静态数据成员total_score(总分)

#include using namespace std; class Student{ private: float score; static int count; static float total_score; public: void account(float score1) {score=score1; ++count; total_score=total_score+score; } static float sum() {return total_score; } static float average() { return total_score/c

设计一个student类,类中包括: (1)一个数据成员score(分数)及两个静态数据

#include using namespace std; class student { public: void scoretotalcount( double s ) { score = s; total = total + score; count++; } static double sum() { return total; } static double average() { return total / count; } private: double score; static double total; static double count; };

c++编程问题

参考,多多看书~ #include using namespace std; class Student { public: Student(){}; void scoretotalcount(float s) { score = s; total +=score; count++; } ~Student(){} static float sum() { return total; } static float average() { return total/count; } private: float score; static float total; stati

真心求c++编程,定义一个学生类Student,包括3个数据成员:学号id,姓名name

#include
#include
usingnamespacestd;
classStudent
{
public:
//带参数的构造函数初始化对象
Student(intid,stringname,doublescore)
:id(id),name(name),score(score)
{
count++;
total+=score;
}
//修改分数成员函数
voidChangeScore(doublenewScore)
{
total+=newScore-score;
score=newScore;
}
staticdoubleGetAverage()
{
returntotal/count;
}
private:
intid;
stringname;
doublescore;
private:
staticdoubletotal;
staticintcount;
};
//类外对静态数据成员进行定义声明
doubleStudent::total=0.0f;
intStudent::count=0;
voidmain()
{
//声明四个学生对象并初始化
Students1(1001,"James",86);
Students2(1001,"Kate",67);
Students3(1001,"Lucy",91);
Students4(1001,"LiLei",65);

cout<<"Theaveragescoreis"<//修改成绩
s1.ChangeScore(50);
s2.ChangeScore(50);
s3.ChangeScore(50);
s4.ChangeScore(50);
cout<<"Theaveragescoreis"<system("pause");
}


标签:信息技术 编程语言 CC++ 编程 定义

大明白知识网 Copyright © 2020-2022 www.wangpan131.com. Some Rights Reserved. 京ICP备11019930号-18