问题:编写一个程序,定义并实现一个银行类;
运行图:
源代码:
#include <iostream>
#include <iomanip>
#include <string.h>
using namespace std;
class bank
{
private:
long id;
double balance;
static double Rational;
double ck;
public:
bank()
{
id=10000;
balance=0;
}
void bank1(long a1,double b1)
{
id=a1;
balance=b1;
}
void setrational(double r)
{
Rational=r;
}
void get()
{
ck=balance*Rational/100;
}
void display()
{
cout<<"账号:"<<id<<"; "<<"存款:"<<balance<<"; "<<"本息:"<<ck<<endl;
}
double dis()
{
return ck+balance;
}
};
double bank::Rational=0;
int main()
{
double a,b,c1,d,e,f,g;
cout<<"请输入利率:请输入3个账号及对应的存款:"<<endl;
cin>>g>>a>>b>>c1>>d>>e>>f;
bank c,t2,t3,t4;
t2.bank1(a,b);
t3.bank1(c1,d);
t4.bank1(e,f);
c.setrational(g);
c.get();
//c.display();
t2.setrational(g);
t2.get();
t2.display();
t3.setrational(g);
t3.get();
t3.display();
t4.setrational(g);
t4.get();
t4.display();
cout<<"3个账户的本息:"<<t3.dis()+t2.dis()+t4.dis();
}