If you look back at the original question, it says,"You have to define one class for each object. Each object should contain, as a minimum, the following attributes and member functions." Am I suppose to use a nested class to access member functions from the SavingAccount class? For example, in main, I'm using an ATM object called UserData to access member functions in the SavingAccount class.
*Area of interest in bold red.
Code:
#include <iostream>
#include <string>
using namespace std;
class SavingAccount
{
private:
string name,
IdNo;
double balance,
rate;
public:
//Constructor; Initializes the user's name, I.D., and balance
SavingAccount(string UserID, string UserName, double bal = 0.00);
//Destructor
~SavingAccount();
bool Withdraw(double);
};
SavingAccount::SavingAccount(string UserID, string UserName, double bal)
{
name = UserName;
IdNo = UserID;
balance = bal;
}
SavingAccount::~SavingAccount()
{
}
bool SavingAccount::Withdraw(double amount)
{
cout <<"Test" << endl;
}
class ATM
{
public:
SavingAccount amount;
};
int main()
{
string UserName,
UserID;
cout <<"AUTOMATIC TELLER MACHINE PROGRAM" << endl;
cout <<"--------------------------------" << endl;
cout <<"This program works like an ATM (automatic teller machine) - allowing the user to";
cout <<"withdraw money from their account. For this exercise, we will withdraw $100.00." << endl;
cout << endl;
//Get User's Name and I.D. number
cout <<"Please enter your name." << endl;
getline(cin,UserName);
cout << endl;
cout <<"Please enter your I.D. number." << endl;
cin >> UserID;
cout << endl;
//Stores User's Name and I.D. number within constructor
SavingAccount UserData(UserID, UserName);
//Message sent to ATM object to withdraw $100.00
ATM UserAccess.amount.Withdraw(100.00);
system("pause");
return 0;
}
Everytime I do this, I get errors:
- expected primary-expression before "UserAccess"
- expected `;' before "UserAccess"