#pragma once
#include <iostream>
using namespace std;
class student
{
public:
void InitStudent(char name[]);
void ExpendMoney(float a);
void ShowMoney();
private:
static float m_ClassMoney;
char nm[20];
};
float student::m_ClassMoney = 1000;
void student::InitStudent(char name[])
{
int i = 0;
while (name[i])
{
nm[i] = name[i];
i++;
}
}
void student::ExpendMoney(float a)
{
m_ClassMoney += a;
}
void student::ShowMoney()
{
cout << "班费还剩" << m_ClassMoney << endl;
}
int main()
{
student A, B, C;
A.ExpendMoney(-50);
A.ShowMoney();
B.ExpendMoney(-98.5);
A.ShowMoney();
C.ExpendMoney(-500.53);
A.ShowMoney();
}
?本次实验更加清晰的掌握静态成员的概念和使用
了解静态成员的作用
需要输入三遍A.ShowMoney();不然只会输出一遍剩余班费
|