#include<iostream>
using namespace std;
class goods
{
public:
goods() {total =0;}
void get_toal() {
cout << "当前货物总量 total = " << total << endl;
}
double add_total(double weigh) {total = total + weigh; return total;}
double reduce(double weigh) {total = total - weigh; return total;}
private:
double total;
};
int main()
{
double in = 10;
double out = 5;
goods gd;
gd.get_toal();
cout << "进货" << in << "吨货物," ;
gd.add_total(in);
gd.get_toal();
cout << "出货" << out << "吨货物," ;
gd.reduce(out);
gd.get_toal();
return 0;
}
标签:std,toal,goods,私有,成员,公用 From: https://www.cnblogs.com/littleboss/p/16830005.html