本人刚刚接触类,自己写了一个小程序,但是不会在buy()和show()里面用name age money 能否给个例子。十分感激!谢谢!
#include<iostream>
using namespace std;
class home
{
private:
char name[30];
int age;
double money;
public:
void buy(int num,double price);
void show( );
};
void home::buy(int num,double price)
{
cout<<name<<"buy things of "<<num<<"with money"<<num*price<<endl;
}
void home::show( )
{
cout<<name<<'\t'<<age<<'\t'<<money<<endl;
}
int main()
{
home home1;
home1.buy(6,300);
home1.show();
system("pause");
}
我就是不知道,我想在show和 buy里面用的时候怎么用,不然我为什么要定义他们啊?
关键是现在怎么用啊?