构造函数问题求解:(红体的2行什么意思,不是很清楚),求大神指导
#include<iostream>#include<math.h>
#include<string.h>
using namespace std;
class balance
{private:
float funds;
public:
balance(float a=0):funds(a)
{}
~balance(void)
{}
void add(const float x);
void sub(const float x);
void print(void) const;
};
void balance::add(const float x)
{
funds=funds+x;
}
void balance::sub(const float x)
{
funds=funds-x;
}
void balance::print(void) const
{
float temp=funds;
if(funds>0)
{cout<<"余额:";
}
else
{cout<<"欠款:";
temp=-temp;
}
int yuan=int(temp);
cout<<yuan<<"元";
int jiao=int((temp-yuan)*10);
cout<<jiao<<"角";
int fen=int(ceil(temp*100-yuan*100-jiao*10));
cout<<fen<<"分"<<endl;
cout<<endl;
cout<<"------------------------------------------------------"<<endl;
}
class creditcard
{
private:
long creditcardno;
char name[30];
balance remains;
public:
creditcard(const long a,char *n,balance r):creditcardno(a),remains(r)
{
strcpy(name,n);
}
~creditcard(void)
{}
void add(const float x);
void sub(const float x);
void transfer(creditcard &a,const float x);
void print(void) const;
};
void creditcard::add(const float x)
{
remains.add(x);
}
void creditcard::sub(const float x)
{
remains.sub(x);
}
void creditcard::transfer(creditcard &a,const float x)
{
cout<<"用户:"<<name<<"转账给"<<a.name<<"金额:"<<x<<"元"<<endl;
remains.sub(x);
a.remains.add(x);
}
void creditcard::print(void) const
{
cout<<"姓名:"<<name<<" ";
cout<<"账户:"<<creditcardno<<" ";
remains.print();
}
int main()
{
creditcard a1(100000,"强天晨",balance(1000));
creditcard a2(100001,"爸",balance(0));
creditcard a3(100002,"儿子",balance(-1000));
a1.print();
a2.print();
a3.print();
a1.transfer(a2,999.99);
a2.add(1000);
a3.sub(1000);
a1.print();
a2.print();
a3.print();
cout<<"最穷的永远是我啊,我穷我快乐"<<endl;
return 0;
}