//1
//类声明文件.h
#ifndef bank_hpp
#define bank_hpp
#include
class BankAccount
{
private:
std::string fullname;
std::string account;
double deposit;
public:
//默认构造函数
BankAccount();
//录入函数
BankAccount(std::string & fname, std::string & acc,
double deposit = 0.0);
//存入
bool dps(double dps);
//取出
bool take(double dps);
//查看
void show() const;
};
#endif /* bank_hpp */
//接口文件(类共用成员函数定义)
#include
#include
#include “bank.hpp”
//默认构造
BankAccount::BankAccount()
{
deposit = 0.0;
}
//录入信息
BankAccount::BankAccount(std::string & fname, std::string & acc,
double dp)
{
fullname = fname;
account = acc;
deposit = dp;
}
//存入
bool BankAccount::dps(double dp)
{
if (deposit < dp + deposit)
{
deposit += dp;
return true;
}
else
return false;
}
//取出
bool BankAccount::take(double dp)
{
if (deposit > deposit - dp)
{
deposit -= dp;
return true;
}
else
return false;
}
//显示
void BankAccount::show() const
{
using std::cout;
cout <<fullname <<’ ’ << account << ’ ’ << "$ " << deposit << ‘\n’;
}
//main.cpp
#include
#include
#include “bank.hpp”
int main()
{
using namespace std;
char ch;
double pd = 0.0;
BankAccount bank_acc1;
string fname, acc;
cout <<“请输入全名 :\n”;
getline(cin, fname);
cout <<“请输入账户 :\n”;
getline(cin, acc);
bank_acc1 = BankAccount(fname, acc, pd);
cout <<“请选择你的操作: \n”;
cout <<“1) 显示信息。 2)存钱。\n”;
cout <<“3) 取钱。 4) 退出。\n”;
while (cin >> ch && ch != ‘4’)
{
switch(ch)
{
case ‘1’: bank_acc1.show();
break;
case ‘2’: cout <<"请输入要存入多少钱: ";
cin >> pd;
if (!bank_acc1.dps(pd))
cout <<“存钱错误!\n”;
break;
case ‘3’: cout <<"请输入要取的钱数: ";
cin >> pd;
if (!bank_acc1.take(pd))
cout <<“取钱错误!\n”;
break;
}
cout <<“请选择你的操作: \n”;
cout <<“1) 显示信息。 2)存钱。\n”;
cout <<“3) 取钱。 4) 退出。\n”;
}
cout <<“Bye!\n”;
return 0;
}
//2题
//类定义
#ifndef name_hpp_
#define name_hpp_
#include
using namespace std;
// class definition
class Person
{
private:
static const int LIMIT = 25;
string lname