"C + + Chapter fourth personal bank Account management procedures case"

Source: Internet
Author: User

"Fourth chapter" personal Bank Account management procedure case Realization
#include <iostream> #include <cmath>using namespace Std;class savingsaccount//Savings account class {Private:int id;// Account double balance; Balance double rate; Deposit of the annual interest rate int lastdate; Date of last change of balance double accumulation; Balances are combined by daily and static double total; The total amount of all accounts//record one account, date, desc is the description void record (int date, double amount);//The deposit amount to a specified date is accumulated by a daily value of double accumulate (int Date) Const{return accumulation + balance* (date-lastdate);} public://constructor SavingsAccount (int date, int ID, double rate), int getId () const {return ID;} Double GetBalance () const {return balance;} Double getrate () const {return rate;} void deposit (int date, double amount); Deposit in cash void withdraw (int date, double amount); Withdraw cash//settlement interest, call the function void settle (int date) every January 1,//Display account information void Show () const;}; Savingsaccount::savingsaccount (int date, int ID, double rate): ID (ID), balance (0), rate, lastdate (date), Accumulation (0) {cout << date << "\t#" << ID << "is created" << Endl;} void Savingsaccount::record (int date, double AMount) {accumulation = accumulate (date), lastdate = Date;amount = Floor (Amount * 100 + 0.5)/100;//reserved decimal point two bits balance + = Amou Nt;cout << Date << "\t#" << ID << "\ t" << amount << "\ t" << balance << End l;} void SavingsAccount::d eposit (int date, double amount) {record (date, amount);} void Savingsaccount::withdraw (int date, double amount) {if (Amount>getbalance ()) cout << "Error:not enough money "<< Endl;elserecord (date,-amount);}  void Savingsaccount::settle (int date) {Double interest = accumulate (date) *rate/365;//Calculate annual interest if (interest! = 0) record (date, interest); accumulation = 0;} void Savingsaccount::show () const{cout << "#" << ID << "\tbalance:" << balance; int main () {//Establish several accounts SavingsAccount sa0 (1, 21325302, 0.015); SavingsAccount SA1 (1, 58320212, 0.015);//Several accounts sa0.deposit (5, 10000); Sa1.deposit (45, 5500); Sa1.withdraw (60, 4000);//The 90th day after the opening of the account to the bank's interest date, the settlement of all accounts at an annual sa0.settle (90);//output Individual account information SA0.show (); cout << endl;sa1.show (); cout << Endl;return 0;}

  

Ps:

Supporting materials: PhD "C + + programming language"

Course: the Academy Online "C + + programming language"

"C + + Chapter fourth personal bank Account management procedures case"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.