一个新手关于C++编程的问题

2024-12-02 14:00:28
推荐回答(2个)
回答(1):

= =这变量名..好长了...哈哈
是这样子的, int accountBalance;
string presentAccountBalance;
string initialBalance;
string deposit;
string money;这些应该都作为类的成员变量,
而且在你的程序里也没看到你用你写的成员函数了啊

类最后的} 后要加;
===========
建议你好好看看书上的例子把,这代码写的不合理

#include
using std::cout;
using std::cin;
using std::endl;

#include
using std::string;

class Account
{
double accountBalance;
double presentAccountBalance;
double initialBalance;
double deposit;
double money;
public:
Account()
{ cout<<"please enter the initial balance for the account:"< cin>>initialBalance;
if(initialBalance>=0)
accountBalance=initialBalance;
if(initialBalance<0)
{ accountBalance=0;
cout<<"the initial balance was invalid"< }
}
void Credit()
{
cout<<"please enter the deposit for the account:"< cin>>deposit;
presentAccountBalance=accountBalance+deposit;
}
void debit()
{
cout<<"please enter the money you want to take out from account:"< cin>>money;
if(money<=accountBalance)
presentAccountBalance=accountBalance-money;
if(money>accountBalance)
{
presentAccountBalance=accountBalance;
cout<<"Debit amount exceeded account balance"< }
}
void getBalance()
{
cout<<"the present account balance is:"< }
};
int main()
{

Account account1;
Account account2;
account1.Credit();
account1.debit();
account1.getBalance();
account2.Credit();
account2.debit();
account2.getBalance();

return 0;
}

回答(2):

class后加了一个分号,结果四十几个错误。。。改还不如直接写一个了