[C + + exercise] 4.1 suppose there are three banks: BOC, ICBC and ABC

Posted by Spear Chucka on Sat, 30 Nov 2019 14:23:34 +0100

  1. Suppose there are three banks: BOC, ICBC and ABC. Each bank can have many outlets, but the total deposits of all outlets are shared.
    Requirement:
    1. Please design three classes to describe these three banks. Please set the data members of each bank class as required
    2. Design the corresponding test code, input the test data to test.
/*
1. Suppose there are three banks: BOC, ICBC and ABC. Each bank can have many outlets, but the total deposits of all outlets are shared.
   Requirements: 1) please design three classes to describe the three banks. Please set the data members of each bank class according to your needs
		 2) Design the corresponding test code, input the test data to test.
*/
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

class BOC
{
	
	int num; //number
	string site;//Location
	double money;//Turnover of this site
public:
	static double gross;  //Total deposits
	BOC();	

};
BOC::BOC()
{
	cout << "------structure BOC Dot------"<<endl;
	cout << "Please enter the branch number:";
	cin >> num;
	getchar();
	cout << "Please enter the location of the outlet:";
	getline(cin, site);
	cout << "Please enter the turnover of this branch:";
	cin>>money;
	getchar();
	gross += money;
}
double BOC::gross = 0;


class ICBC
{
	int num; //number
	string site;//Location
	double money;//Turnover of this site
public:
	ICBC();
	static double gross;  //Total deposits
};
ICBC::ICBC()
{
	cout << "------structure ICBC Dot------"<<endl;
	cout << "Please enter the branch number:";
	cin >> num;
	getchar();
	cout << "Please enter the location of the outlet:";
	getline(cin, site);
	cout << "Please enter the turnover of this branch:";
	cin >> money;
	getchar();
	gross += money;
}
double ICBC::gross = 0;


class ABC
{
	
	int num; //number
	string site;//Location
	double money;//Turnover of this site
public:
	ABC();
	static double gross;  //Total deposits
};
ABC::ABC()
{
	cout << "------structure ABC Dot------"<<endl;
	cout << "Please enter the branch number:";
	cin >> num;
	getchar();
	cout << "Please enter the location of the outlet:";
	getline(cin, site);
	cout << "Please enter the turnover of this branch:";
	cin >> money;
	getchar();
	gross += money;
}
double ABC::gross = 0;


int main()
{
	BOC a[2];
	cout << endl;
	ICBC b[2];
	cout << endl;
	ABC c[2];
	cout << endl;
	
	cout << "BOC Total deposits of bank outlets:" << BOC::gross << endl;
	cout << "ICBC Total deposits of bank outlets:" << b[1].gross << endl;
	cout << "ABC Total deposits of bank outlets:" << ABC::gross << endl;

	system("PAUSE");
	return 0;
}

Test data:

beijing
30
2
xiamen
20
3
shanghai
10
4
shanghai
15
5
tianjing
20.5
6
shandong
10.2