#include <iostream>
#include <string>
class BankAccount
{
private:
std::string name;
std::string accountnum;
double balance;
public:
BankAccount(std::string client,std::string accnum,double bl=0);
void showAccount(void) const ;
void deposit(double dep);
void withdraw(double wd);
};
BankAccout::BankAccount(std::string client,std::string accnum,double bl)
{
name=client;
accountnum=accnum;
balance=bl;
}
void BankAccount::showAccount(void) const
{
std::cout<<"name:"<<name
<<" accout number:"<<accountnum
<<" balance:"<<balance<<std::endl;
}
void BankAccount::deposit(double dep)
{
balance += dep;
}
void BankAccount::withdraw(double wd)
{
balance += wd;
}
int main()
{
// std::cout << "Hello world!" << std::endl;
// using std::cout;
// using std::string;
using namespace std;
BankAccount cl ("Michael D","786654321",2000.0);
cl.showAccount();
cout<<"after deposit 522.39 into the account:";
cl.deposit(522.39);
cl.showAccount();
cout<<"after withdraw 221.12 into the account:";
cl.withdraw(221.12);
cl.showAccount();
return 0;
}
[问题]高手帮忙看看我的程序那里有问题,找了半天也没发现!可以直接拷贝编译,多谢
-
- 帖子: 13
- 注册时间: 2007-09-11 18:07
-
- 帖子: 458
- 注册时间: 2006-11-27 12:25
-
- 帖子: 2
- 注册时间: 2007-10-26 13:17
这样就可以了
#include <iostream>
#include <string>
using namespace std;
class BankAccount
{
private:
string name;
string accountnum;
double balance;
public:
BankAccount(string client="no",string accnum="zero",double bl=0)
{
name=client;
accountnum=accnum;
balance=bl;
}
void showAccount(void) const ;
void deposit(double dep);
void withdraw(double wd);
};
void BankAccount::showAccount(void) const
{
cout<<"name:"<<name<<" accout number:"<<accountnum<<" balance:"<<balance<<std::endl;
}
void BankAccount::deposit(double dep)
{
balance += dep;
}
void BankAccount::withdraw(double wd)
{
balance -= wd;
}
int main()
{
BankAccount h("Michael D","786654321",2000.0);
h.showAccount();
cout<<"after deposit 522.39 into the account:";
h.deposit(522.39);
h.showAccount();
cout<<"after withdraw 221.12 into the account:";
h.withdraw(221.12);
h.showAccount();
return 0;
}
#include <string>
using namespace std;
class BankAccount
{
private:
string name;
string accountnum;
double balance;
public:
BankAccount(string client="no",string accnum="zero",double bl=0)
{
name=client;
accountnum=accnum;
balance=bl;
}
void showAccount(void) const ;
void deposit(double dep);
void withdraw(double wd);
};
void BankAccount::showAccount(void) const
{
cout<<"name:"<<name<<" accout number:"<<accountnum<<" balance:"<<balance<<std::endl;
}
void BankAccount::deposit(double dep)
{
balance += dep;
}
void BankAccount::withdraw(double wd)
{
balance -= wd;
}
int main()
{
BankAccount h("Michael D","786654321",2000.0);
h.showAccount();
cout<<"after deposit 522.39 into the account:";
h.deposit(522.39);
h.showAccount();
cout<<"after withdraw 221.12 into the account:";
h.withdraw(221.12);
h.showAccount();
return 0;
}