我有一个名为 account 的基类。三个类从帐户继承。这些类别是储蓄、支票和信用卡。在我的 main() 中,我试图创建一个切换菜单,以便当用户选择 1 时,它将调用 makeDeposit(),它是帐户的一部分,但通过储蓄来实现。这样当用户选择 3 时,它将调用 makeDeposit(),但通过检查来完成。这是我写的代码。我已声明对象保存 sa;当我调用 makeDeposit 时,我试图将其写为 sa.makeDeposit()。这是代码:
int main ()
{
saving sa;
creditCard cca;
checking ca;
string n;
int option;
int exit = 1;
cout << endl;
cout << "Checking Balance:" << " " << " " << "Savings balance:" << " " << " " << "Credit Card balance:" << " " << endl;
cout << endl;
cout << " (1) Savings Deposit " << endl;
cout << " (2) Savings withdrawel " << endl;
cout << " (3) Checking Deposit " << endl;
cout << " (4) Write A Check " << endl;
cout << " (5) Credit Card Payment " << endl;
cout << " (6) Make A Charge " << endl;
cout << " (7) Display Savings " << endl;
cout << " (8) Display Checkings " << endl;
cout << " (9) Display Credit Card " << endl;
cout << " (0) Exit " << endl;
cin >> option;
do{
switch ( option )
{
case 1 : double amtD;
cout << " Please enter how much you would like to deposit into savings " << endl;
cin >> amtD;
double sa.makeDeposit(double amtD);
break;
case 2 : double makeWithdrawel();
break;
case 3 : double makeDeposit();
break;
case 4 :
break;
case 5 :
break;
case 6 : double makeWithdrawel();
break;
case 7 : int display();
break;
case 8 : int display();
break;
case 9 : int display();
break;
case 0 : exit = 0;
break;
default : exit = 0;
cout << " ERROR ";
}
}
while(exit==1);
return 0;
}
这是我的班级储蓄:
#include "stdafx.h"
#include "iostream"
#include "Account.h"
#include <string>
#include <sstream>
using namespace std;
class saving: public account
{
public :
double doWithdraw(double amount);
saving();
saving(string itsName, long itsTaxID, double itsBalance);
}
和我的帐户课程:
#include "stdafx.h"
#include <string>
#include <sstream>
using namespace std;
class account {
public :
void setName(string name); void setTaxID(long taxID); void setBalance(double balance);
string getName(); long getTaxID(); double getBalance();
double makeDeposit( double amount );
account();
account(string itsName, long itsTaxID, double itsBalance);
int display();
private :
string itsName;
long itsTaxID;
double itsBalance;
protected :
double last10withdraws[10];
double last10deposits[10];
int numdeposits;
int numwithdraws;
};
知道我做错了什么吗?