我找了一个相近的谁能帮忙修改修改
坦白的说我也是学计算机的
,但是自己不努力,到了期末要交的时候,自己也感到很为难,希望有人会帮助我,我以后不会再这样了
题目还是上边的,这是我找到的,可是不会修改
#include <iostream>
#include <string>
#include <time.h>
#include <math.h>
#include <map>
using namespace std;
class Cbank;//中国银行
class Bbank;//工商银行
class Gbank;//农业银行
class Cbank
{
public:
string m_name;
Cbank(string name = "", int balance = 0)
{
m_name = name;
m_balance = balance;
}
int SetBalance(int balance)
{
m_balance = balance;
return balance;
}
private:
int m_balance;
friend int total(Cbank& Cb, Bbank& Bb, Gbank& Gb);
};
class Bbank
{
public:
string m_name;
Bbank(string name = "", int balance = 0)
{
m_name = name;
m_balance = balance;
}
int SetBalance(int balance)
{
m_balance = balance;
return balance;
}
private:
int m_balance;
friend int total(Cbank& Cb, Bbank& Bb, Gbank& Gb);
};
class Gbank
{
public:
string m_name;
Gbank(string name = "", int balance = 0)
{
m_name = name;
m_balance = balance;
}
int SetBalance(int balance)
{
m_balance = balance;
return balance;
}
private:
int m_balance;
friend int total(Cbank& Cb, Bbank& Bb, Gbank& Gb);
};
int total(Cbank& Cb, Bbank& Bb, Gbank& Gb)//友元函数可以访问私有成员
{
return Cb.m_balance + Bb.m_balance + Gb.m_balance;
}
int main(int argc, char *argv[])
{
Cbank cb("皇家救星");
Bbank bb("皇家救星");
Gbank gb("皇家救星");
int balance;
cout << "请输入存在人民银行的金钱数额" << endl;
cin >> balance;
cb.SetBalance(balance);
cout << "请输入存在工商银行的金钱数额" << endl;
cin >> balance;
bb.SetBalance(balance);
cout << "请输入存在农业银行的金钱数额" << endl;
cin >> balance;
gb.SetBalance(balance);
cout << "三家银行的存款总额是\t" << total(cb, bb, gb) << endl;
return 0;
}