银行菜单项目使用类

时间:2017-05-26 00:06:02

标签: c++ class

所以我们在c ++类中学习了类,并在银行菜单项目中使用它。但是,当我把它放在一起时,我得到了错误C3867。 ' BankAccount :: deposit&#39 ;:非标准语法;使用'&'创建指向成员的指针。

class BankAccount
{
private:
    string name;
    double balance;
public:
    BankAccount();
    double getBalance();
    bool deposit(double amt);
};
BankAccount::BankAccount()
    : name("John Doe"), balance(100)
{
}

double BankAccount::getBalance()
{
    return balance;
}

bool BankAccount::deposit(double amt)
{
    cout << "Enter Amount to Deposit: ";
    cin >> amt;
    if (amt > 0)
    {
        cout << "Success" << endl;
        balance = balance + amt;
        cout << "New Balance is: " << balance << endl;
    }
    else
    {
        cout << "Invalid Transaction" << endl;
    }
}   

int main()
{
    char choice;
    BankAccount JohnDoe;

    do
    {
        cout << "A. Deposit" << endl;
        cout << "Q. Quit" << endl;
        cout << "Please Make a Choice: " << endl;
        cin >> choice;

        switch (toupper(choice))
        {
        case 'A':
            JohnDoe.deposit;
            break;
        case'Q':
            cout << "Thank You For Using Our Services Today!" << endl;
            break;
        default:
            cout << "Not a Valid Choice" << endl;
        }

    } while (toupper(choice) != 'Q');

1 个答案:

答案 0 :(得分:0)

此函数bool BankAccount::deposit(double amt)必须返回bool值。此外,该函数必须在您调用该参数时接受参数JohnDoe.deposit; JohnDoe.deposit(<pass double value>);