Account.h
#include <iostream>
#include <string>
using namespace std;
class Account {
public:
int num;
string name;
int money;
public:
Account(int num, const string &name, int money);
void showMes();
void inMes(int m);
void outMes(int m);
};
Account.cpp
#include "Account.h"
#include <iostream>
#include <string>
using namespace std;
Account::Account(int num, const string &name, int money) {
this->num = num;
this->name = name;
this->money = money;
}
void Account::showMes() {
cout<<"num="<<num;
cout<<",name"<<name;
cout<<",money"<<money<<endl;
}
void Account::inMes(int m) {
this->money += m;
}
void Account::outMes(int m) {
if(m<money){
cout<<"余额不足"<<endl;
} else {
this->money -= m;
}
}
TestAccount.cpp
#include <iostream>
#include "Account.h"
#include "string"
using namespace std;
int main() {
int num;
string name;
int money;
cout<<"请输入账号"<<num<<endl;
cin>>num;
cout<<"请输入姓名"<<name<<endl;
cin>>name;
cout<<"请输入余额"<<money<<endl;
cin>>money;
Account zhangsan(num,name,money);
zhangsan.showMes();
int m;
cout<<"请输入存款金额"<<endl;
cin>>m;
zhangsan.inMes(m);
zhangsan.showMes();
cout<<"请输入取款金额"<<endl;
cin>>m;
zhangsan.outMes(m);
zhangsan.showMes();
return 0;
}
|