可以在main函数中调用类中的变量么?
#include <iostream>using namespace std;
const int invest = 100;
class Daphne
{
private:
int year1;
float arrural1;
public:
float benifit1;
int sum1()
{
arrural1 = invest * 0.1;
benifit1 = invest;
for (year1 = 1; year1 < 100 ; year1 ++)
{
benifit1 += arrural1;
cout << "The " << year1 << " year,Daphne's benifit is: " << benifit1 << endl;
}
return benifit1;
}
};
class Cleo
{
private:
int year2;
float arrural2;
float total;
public:
float benifit2;
int sum2()
{
benifit2 = invest;
total = benifit2;
for (year2 = 1; year2 < 100 ; year2 ++)
{
arrural2 = total * 0.05;
total = benifit2 + arrural2;
benifit2 += arrural2;
cout << "The " << year2 << " year,Cleo's benifit is:\t " << benifit2 << endl;
}
return benifit2;
}
};
int main()
{
Daphne s1;
Cleo s2;
s1.sum1();
s2.sum2();
return 0;
}
程序的目的是想要输出什么时候Cleo的钱超过Daphne的。我想用类来实现。但是不知道在主函数中写判断Cleo超过Daphne时的语句。哪位大侠来指导下啊。。。