每日100!银行账户源代码!
Test.cpp
#include “stdafx.h”
#include <stdlib.h>
#include"class.h"
#include
#include “string”
using namespace std;
int main() {
string name;
string id;
double balance;
string password;
string address;
double min_balance;
float money_rate;
int operate;//操¨´作Á¡Â
double money;
int year;
cout << “请?输º?入¨?客¨ª户¡ì信?息¡é” << endl;
cout << “------------------------------------------------------------------” << endl;
cout << “姓?名?:êo” ;
cin >> name;
cout << “账?号?:êo”;
cin >> id;
cout << “余®¨¤额?:êo”;
cin >> balance;
cout << “密¨¹码?:êo”;
cin >> password;
cout <<“地Ì?址¡¤:êo”;
cin >> address;
cout << “最Á?小?余®¨¤额?:êo”;
cin >> min_balance;
cout << “利¤?率¨º:êo”;
cin >> money_rate;
SaveingBank yujianhong(id,name,balance,password,address,min_balance,money_rate);
cout << “-------------------请?选?择?以°?下?几?项?操¨´作Á¡Â操¨´作Á¡Â--------------------------------------” << endl;
cout << " 1:êo打䨰印®?客¨ª户¡ì信?息¡é" << endl;
cout << " 2:êo存ä?款?" << endl;
cout << " 3:êo取¨?款?" << endl;
cout << " 4:êo修T改?密¨¹码?" << endl;
cout << “---------------------------------------------------------------------------” << endl;
while (cin >> operate){
switch(operate) {
case 1:
yujianhong.GetBank();
cout << “------------------------------------------------------------------------------” << endl;
break;
case 2:
cout << “请?输º?入¨?存ä?款?金e额?:” << endl;
cin >> money;
cout << "当Ì¡À前¡ã余®¨¤额?为a" << yujianhong.deposit(money) << endl;
cout << "预¡è计?存ä?款?年¨º限T:" << endl;
cin >> year;
cout << "预¡è计?收º?益°?" << yujianhong.profit(year)<< endl;
cout << "-----------------------------------------------------------------------------" <<endl;
break;
case 3:
cout << "请?输º?入¨?取¨?款?金e额?" << endl;
cin >> money;
yujianhong.draw(money);
cout << "当Ì¡À前¡ã余®¨¤额?是º?:êo" <<yujianhong.GetBalance() << endl;
cout << "-----------------------------------------------------------------------------" <<endl;
break;
case 4:
yujianhong.change_password();
cout << "-----------------------------------------------------------------------------" <<endl;
break;
case 5:
cout << "输º?入¨?有®D误¨®,ê?请?重?新?输º?入¨?" << endl;
cout << "-----------------------------------------------------------------------------" <<endl;
}
}
return 0;
}
Class.h
#include
#include
using namespace std;
class Bank{
protected:
const string id;
string name;
double balance;
public:
Bank(const string id, string name, double balance):id(id) //const修T饰º?的Ì?对?象¨®用®?初?始º?化¡¥列¢D表À¨ª初?始º?化¡¥
{
this->name = name;
this->balance = balance;
}
string GetId() { return id; }
string GetName() { return name; }
double GetBalance() { return balance; }
};
class SaveingBank:public Bank{
protected:
string password ;
string address;
double min_balance;
double money_rate;
public:
SaveingBank(const string id, string name, double balance, string password,
string address,double min_balance,double money_rate):Bank(id,name,balance){
this->password = password;
this->address = address;
this->min_balance = min_balance;
this->money_rate = money_rate;
}
string GetPassword(){return password ;}//获?取¨?密¨¹码?
string GetAddress(){return password ;}//获?取¨?地Ì?址¡¤
double GetMin_balance(){return min_balance; }//获?取¨?最Á?小?余®¨¤额?
double GetMoney_rate(){return money_rate; }//获?取¨?利¤?率¨º
double deposit(double money){
balance += money;
return balance;
} //存ä?款?是º?一°?个?方¤?法¤¡§要°a用®?函¡¥数ºy实º¦Ì现?
double draw(double money){
if(money <= balance - min_balance){
balance -= money;
return balance;
}else{
cout << "余®¨¤额?不?足Á?,ê?请?重?新?选?择?" << endl;
}
}
double profit(int year){
return (money_rate*balance*year);
}
//
string change_password(){
string new_password;
string number;
cout << "请?输º?入¨?旧¨¦密¨¹码?" << endl;
cin >> number;
if(number==password){
cout << "请?输º?入¨?新?密¨¹码?" << endl;
cin >> new_password;
password = new_password;
cout << "密¨¹码?修T改?成¨¦功|" << endl;
}else{
//cerr与®?cout的Ì?主¡Â要°a区?分¤?就¨ª是º?,ê?cout输º?出?的Ì?信?息¡é可¨¦以°?重?定¡§向¨°,ê?而?cerr只?能¨¹输º?出?到Ì?标À¨º准Á?输º?出?(ꡧ显?示º?器¡Â)ê?上¦?。¡ê
// test >>cout.txt ? ?运?行D结¨¢果?是º?:êo ? ?在¨²生¦¨²成¨¦的Ì?cout.txt文?件t中D输º?出?了¢?"hello world---cout" ?
// ?同ª?时º¡À在¨²显?示º?器¡Â上¦?输º?出?了¢?"hello world---cerr"
// ? ?也°2就¨ª是º?说¦Ìcout的Ì?输º?出?可¨¦以°?重?定¡§向¨°到Ì?一°?个?文?件t中D,ê?而?cerr必À?须?输º?出?在¨²显?示º?器¡Â上¦?。¡ê ? ? ?
cerr << "原-始º?密¨¹码?错䨪误¨®,ê?请?重?新?先¨¨择?操¨´作Á¡Â" << endl;
return password;
}
}
//获?取¨?账?户¡ì信?息¡é
void GetBank(){
cout << "姓?名?:êo" << GetName() << endl;
cout << "账?号?:êo" << GetId() << endl;
cout << "余®¨¤额?:êo" << GetBalance() << endl;
cout << "密¨¹码?:êo" << GetPassword() << endl;
cout << "地Ì?址¡¤:êo" << GetAddress() << endl;
cout << "最Á?小?余®¨¤额?:êo" << GetMin_balance() << endl;
cout << "利¤?率¨º:êo" << GetMoney_rate() << endl;
}
};
运行结果