//Self-study, I can't understand T_T for the sentence "get the daily accumulated value of the deposit amount up to the specified date". Therefore, modify part of the content of the class and ignore part of the logic =_=…
#include <iostream> #include <cmath> using namespace std; class SavingsAccount { //Savings account class private: int id; //account double balance; //balance double rate; //The annual interest rate of the deposit double interest=0.0; //interest //Record an account, date is the date, amout is the amount, and desc is the description void record(int date, double amout); public: SavingsAccount(int date, int id, double rate); int getID() { return id; } double getBalance() { return balance; } double getRate() { return rate; } void deposit(int date, double amount); void withdraw(int dadte, double amount); //settlement interest double lixi(int date, double amount); //display account information void show(); }; // Implementation of SavingsAccount related member functions SavingsAccount::SavingsAccount(int date, int id, double rate) :id(id), balance(0), rate(rate) { cout << date << "\t#" << id << " is created" << endl; } void SavingsAccount::record(int date, double amount) { amount = floor(amount * 100+0.5)/100; //The purpose of the floor function: keep two decimal places balance += amount; cout << date << "\t#" << id << "\t" << amount <<"\t"<< balance << endl; } void SavingsAccount::deposit(int date, double amount) { record(date, amount); lixi(date, amount); } void SavingsAccount::withdraw(int date, double amount) { if (amount > getBalance()) //If the money to be withdrawn is greater than the deposit balance cout << "Error:not enough money" << endl; else record(date, -amount); lixi(date, -amount); } void SavingsAccount::show() { cout << "#" << id << "\tBalance:" << (balance+interest)<<endl; cout << "#" << id << "\tlixi:" << interest; } double SavingsAccount::lixi(int date, double amount) { //Calculate deposit interest under different operations and accumulate interest += ((amount*rate) / 365)*(90 - date); interest = floor(interest * 100 + 0.5) / 100; return interest; } intmain() { //create two accounts SavingsAccount sa0(1, 21325302, 0.015); SavingsAccount sa1(1, 58320212, 0.015); //several accounts (operations) sa0.deposit(5, 5000); sa1.deposit(25, 10000); sa0.deposit(45, 5500); sa1.withdraw(60, 4000); // output each account information sa0.show(); cout << endl; sa1.show(); cout << endl; return 0; }