I have an assignment that isn't due till a few days, I'm just trying to get a head start.
So I have a program that is supposed to make "CheckingAccount.h" inherit from "BankAccount.h". I have written up the code and I am error free! But one of my functions for "setTransactionFee" or "getTransactionFee" will not do its job correctly. I am not expecting someone to write out the code for the function(even though that would be awesome!), but any ideas or help would be appreciated.
Here is what the output should look like...
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Welcome to your bank
1. Make a deposit
2. Make a withdrawal
3. Set the account name
4. Set the account number
5. Set the transaction fee
6. Display account information
7. Exit
Please enter your choice: 6
Account Information
Number:23456
Name:Joe Smith
Balance:49.00
Transaction Fee:1.00
This is the code I have written up already..
Following includes:
-Bank.cpp
-BankAccount.h (SUPER CLASS)
-CheckingAccount.h (CHILD CLASS)
/**********************BANK.CPP********************/
#include <iostream>
#include <iomanip>
#include <string>
#include "BankAccount.h"
#include "CheckingAccount.h"
usingnamespace std;
void displayMenu();
double getValidData();
//***************************************************
// main
//***************************************************
int main()
{
BankAccount CheckingAccount; //declare and create with constructor
int choice = 0;
int iValue = 0;
string name = "unknown";
do {
displayMenu();
cin >> choice;
cout << endl;
switch (choice)
{
case 1 : cout << "Deposit amount. " ;
CheckingAccount.deposit(getValidData());
break;
case 2 : cout << "Withdraw amount. " ;
CheckingAccount.withdraw(getValidData());
break;
case 3 : cout << "Enter the name: ";
cin.ignore(); //skips the newline char
getline(cin,name); //reads an entire line
CheckingAccount.setName(name);
break;
case 4 : cout << "Account number. " ;
CheckingAccount.setAcctNumber(static_cast<int>(getValidData( )) );
break;
case 5 : CheckingAccount.displayData(); //display all account data
break;
case 6 : cout << "\nBank is closed.\n" ;
break;
default : cout << "Invalid entry.";
}//switch
}while (choice != 6);
return 0;
}//end of main
//This function displays the user's menu on the screen.
//This is NOT a BankAccount member function
void displayMenu()
{
cout << "\n Welcome to your bank \n\n";
cout << "1. Make a deposit\n";
cout << "2. Make a withdrawal\n";
cout << "3. Set the account name\n";
cout << "4. Set the account number\n";
cout << "5. Display account information\n";
cout << "6. Exit\n\n";
cout << "Please enter your choice: ";
}
//This function prompts the user for a number
//and checks to see if 0 or greater. Returns
//a valid number
double getValidData()
{
double amount = 0;
cout<< "Enter value: " ; //deposit or withdraw amt or account number
cin >> amount;
while (amount < 0 )
{
cout << "Enter value: (0 or greater): " ;
cin >> amount;
}
return amount;
}
/****************************BANKACCOUNT.h************/
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
//BankAccount class declaration
class BankAccount
{
protected:
int acctNumber;
string name;
double balance;
public:
BankAccount();
BankAccount(int aNum, string aName, double amount);
void setAcctNumber(int aNum);
void setName(string aName);
void setBalance(double amount);
int getAcctNumber();
string getName();
double getBalance();
void deposit(double amount);
void withdraw(double amount);
void displayData();
};//End of BankAccount class declaration
//Member function implementation section
// Constructor function. Initializes acctNumber to 0, name to “Unknown” and
// balance to 0.0.
BankAccount::BankAccount()
{
acctNumber = 0;
name = "Unknown";
balance = 0.0;
}
//Overloaded constructor. overloaded constructor function.
//Initializes acctNumber to aNum, name to aName and balance to amount.
BankAccount::BankAccount(int aNum, string aName, double amount)
{
acctNumber = aNum;
name = aName;
balance = amount;
}
//This function copies the argument passed into the parameter to
//the private member variable acctNumber.
void BankAccount::setAcctNumber(int aNum)
{
acctNumber = aNum;
}
//This function copies the argument passed into the parameter to
//the private member variable name.
void BankAccount::setName(string aName)
{
name = aName;
}
//This function copies the argument passed into the parameter to
//the private member variable balance.
void BankAccount::setBalance(double amount)
{
balance = amount;
}
//This function returns the value of the private member variable acctNumber.
int BankAccount::getAcctNumber()
{
return acctNumber;
}
//This function returns the value of the private member variable name.
string BankAccount::getName()
{
return name;
}
//This function returns the value of the private member variable balance.
double BankAccount::getBalance()
{
return balance;
}
//This function adds the amount passed in to the balance.
void BankAccount::deposit(double amount)
{
balance = balance + amount;
}
//this function subtracts the amount passed in from the balance.
void BankAccount::withdraw(double amount)
{
balance = balance - amount;
}
// Displays the data of a bank account
void BankAccount::displayData()
{
cout << " Account Information " << endl;
cout << "-------------------------" << endl;
cout << " Number:" << setw(15) << acctNumber << endl;
cout << " Name:" << setw(15) << name << endl;
cout << fixed << showpoint << setprecision(2);
cout << " Balance:" << setw(15) << balance << endl;
}
Well, for starters, you don't seem to be calling "setTransactionFee" or "getTransactionFee" anywhere in the code you've posted. How can you tell whether they're doing the right thing?