这是一个存折的问题,后两张图片是题目要求,我写的代码能运行,但是不太符合要求,请问我还该怎么改动
修改如下,供参考:
#include <iostream>
using namespace std;
class FDAccount {
private:
char* accounts; //账号
char* name; //账户名称
double balance; //存款余额
int term; //存款期限
protected:
double interest_rate;//存款利率
public:
FDAccount(char* ID, char* depositor, double amount, int period, double rate)
{
if (amount < 0 || rate < 0)
cout << "数据不正确" << endl;
else
accounts = ID, name = depositor, balance = amount, term = period, interest_rate = rate;
}
double fetch(char* ID, char* depositor, double amount)
{
cout << "Account:" << (char*)ID << endl << "Name:" << (char*)depositor << endl << "Amount:" << amount << endl;
balance = balance - amount;
return balance;
}
void update()
{
balance = balance + balance * (interest_rate / 100.0) * (term / 12.0);
}
void show()
{
cout << "Account:" << accounts << endl << "Name:" << name << endl << "Term:" << term << endl;
cout << "Interest_rate:" << interest_rate << endl << "Balance:" << balance << endl;
}
};
int main()
{
char s1[10], s2[20];
double c, d, e = 3000.00;
int f;
cout << "请输入账号" << endl;
cin >> s1;
cout << "请输入账户名称" << endl;
cin >> s2;
cout << "请输入存款期限" << endl;
cin >> f;
cout << "请输入存款利率" << endl;
cin >> c;
cout << "请输入存款金额" << endl;
cin >> d;
FDAccount deporitor(s1, s2, d, f, c);
deporitor.show();
deporitor.update();
deporitor.show();
deporitor.fetch(s1,s2,500);
deporitor.show();
return 0;
}
为什么show时冒号两边的空格不统一?
不知道你这个问题是否已经解决, 如果还没有解决的话: