问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
#include<iostream>
using namespace std;
class Account
{
public:
Account(char name[], long num, float amount); //类的有参构造函数
Account(); //类的无参构造函数
void deposit(float amount); //往账户中存款
int withdraw(float amount); //从账户中取款(考虑透支情况)
float getBalance(); //查询余额
private:
char mName[20]; //银行账户的户名
long mSN; //本账户的帐号
float mBalance; //本账户当前的余额
};
Account::Account(char name[], long num, float amount) {
for (int i = 0; i < 20; i++) {
name[i] = mName[i];
}
mSN = num;
amount = mBalance;
}
void Account::deposit(float amount) {
mBalance = mBalance + amount;
}
int Account::withdraw(float amount) {
if (amount > mBalance) {
cout << "您的余额不足" << endl;
return 0;
}
else {
mBalance = mBalance - amount;
}
return mBalance;
}
float Account::getBalance() {
return mBalance;
}
void main() {
int a;
char name1[10]; long num1;
float amount1 = 0;
cout << "--------------------注册界面--------------------" << endl;
cout << "用户名:" << endl;
for (int i = 0; i < 10; i++) {
cin >> name1[i];
}
cout << "账号:";
cin >> num1;
Account user1(char name1, long num1, float amount1);
for (;;) {
cout << "--------------------操作界面--------------------" << endl;
cout << "1:存款;" << endl;
cout << "2.取款;" << endl;
cout << "3.查询余额" << endl;
cout << "4.退出" << endl;
cout << "------------------------------------------------" << endl;
cin>>a;
switch (a) {
case(1):
cout << "请输入您要存的金额" << endl;
cin >> amount1;
user1.deposit(amount1);
system("pause");
system("cls");
continue;
case(2):
cout << "请输入你要取的金额" << endl;
cin >> amount1;
user1.withdraw(amount1);
system("pause");
system("cls");
continue;
case(3):
user1.getBalance;
system("pause");
system("cls");
continue;
case(4):
system("cls");
break;
}
}
}
运行结果及报错内容
调用类里的函数时出现:表达式必须具有类类型,但它以及具有(。。)