Bank Homework 10 2016 4 25

Source: Internet
Author: User

#include <iostream>
#include <string>
using namespace Std;
Class Bank

{

Public

Bank (String _name)

{

name = _name;

}

String GetName () const

{

return name;

}

virtual void Printmessage () const = 0;

virtual void deposit (double m) = 0;

virtual void withdraw (double m) = 0;

Virtual double Getmoney () const = 0;

Protected

String name;

};


Class Icbc:public Bank

{

Public

ICBC (Double _money = 0): Bank ("ICBC")

{

Money = _money;

}

void Printmessage () const

{

cout << "Welcome to Industrial and commercial Bank of China" << Endl;

}

void deposit (double m)

{

Money + = m;

}

void withdraw (double m)

{

if (Money > m) money-= m;

else Money = 0;

}

Double Getmoney () const

{

return money;

}

Private

Double money;

};

Class Abc:public Bank

{

Public

ABC (Double _money = 0): Bank ("abc")

{

Money = _money;

}

void Printmessage () const

{

cout << "Welcome to agricultural Bank of China" << Endl;

}

void deposit (double m)

{

Money + = m;

}

void withdraw (double m)

{

if (Money > m) money-= m;

else Money = 0;

}

Double Getmoney () const

{

return money;

}

Private

Double money;

};



Class Accountmanager

{

Public

Accountmanager (int _size);

~accountmanager ();

void Setbank (int i, Bank *bank);

bank* Getbank (int i);

void Deposit (Bank *bank, double money);

void Withdraw (Bank *bank, double money);

void Transfer (bank *bank1, Bank *bank2, double money);

void Printaccount () const; Print the welcome message, bank name and money for each array element

Private

Bank* *banklist; Bank array, where each element is a (bank*) type

int size; The length of the bank array

};


Accountmanager::accountmanager (int _size) {
size = _size;
Banklist = new Bank*[size];
}

Accountmanager::~accountmanager () {
delete [] banklist;
}

void Accountmanager::setbank (int i, Bank *bank) {
Banklist[i] = Bank;
}

bank* Accountmanager::getbank (int i) {
return banklist[i];
}

void Accountmanager::d eposit (Bank *bank, double money) {
Bank->deposit (Money);
}

void Accountmanager::withdraw (Bank *bank, double money) {
Bank->withdraw (Money);
}

void Accountmanager::transfer (Bank *bank1, Bank *bank2, double money) {
if (Bank1->getmoney () >=money) {
Bank1->withdraw (Money);
Bank2->deposit (Money);
}
else{
Bank2->deposit (Bank1->getmoney ());
Bank1->withdraw (Bank1->getmoney ());
}

}

void Accountmanager::p rintaccount () const{
for (int i=0;i<size;i++) {
Banklist[i]->printmessage ();
Cout<<banklist[i]->getname () << "";
Cout<<banklist[i]->getmoney () <<endl;
}
}











int main ()

{

Accountmanager Accountmanager (2);

Bank *bank1 = new ICBC (100);

Accountmanager.setbank (0, BANK1);

Bank *bank2 = new ABC;

Accountmanager.setbank (1, BANK2);

Accountmanager.printaccount ();

Accountmanager.deposit (Accountmanager.getbank (0), 100);

Accountmanager.deposit (Accountmanager.getbank (1), 100);

Accountmanager.printaccount ();

Accountmanager.withdraw (Accountmanager.getbank (0), 50);

Accountmanager.withdraw (Accountmanager.getbank (1), 50);

Accountmanager.printaccount ();

Accountmanager.transfer (Accountmanager.getbank (0), Accountmanager.getbank (1), 500);

Accountmanager.printaccount ();

return 0;

}













Bank Homework 10 2016 4 25

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.