Question

Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...

Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance.

Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly.

// BankAccount.h

#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <string>
#include <iostream>
using namespace std;
class BankAccount
{
protected :
int noOfWithdrawls;
private:
// Declaring variables
  
float balance;
static unsigned int numAccounts;
public:
// parameterized constructor
BankAccount();
BankAccount(float bal);
void Withdraw(float amount); // decreases balance by amount
void Deposit(float amount); // increases balance by amount
float GetBalance() const;
  
};
#endif

======================================

// BankAccount.cpp

#include <iostream>
#include <string>
using namespace std;
#include "BankAccount.h"

BankAccount::BankAccount()
{
this->balance=0;
}
BankAccount::BankAccount(float bal)
{
this->balance=bal;
}
// decreases balance by amount
void BankAccount::Withdraw(float amount)
{
if(balance-amount>=0)
{
this->balance-=amount;
noOfWithdrawls++;
}
}
// increases balance by amount
void BankAccount::Deposit(float amount)
{
this->balance+=amount;
}
float BankAccount::GetBalance() const
{
return balance;
}

=====================================

// CheckingAccount .h

#ifndef CHECKING_H
#define CHECKING_H
#include <string>
#include "BankAccount.h" // Account class definition
// Creating a Checking Account class derivied from Account class
class CheckingAccount : public BankAccount
{
public:
// parameterized constructor
CheckingAccount(float balance);

void Withdraw(float amt);
private:
  
};
#endif

========================================

// CheckingAccount .cpp

#include <iostream>
#include <string>
using namespace std;
#include "CheckingAccount.h"


// parameterized constructor
CheckingAccount::CheckingAccount(float balance):BankAccount(balance)
{
}

void CheckingAccount::Withdraw(float amt)
{
if(noOfWithdrawls>10)
{
BankAccount::Withdraw(amt+5);
noOfWithdrawls++;
}
else
{
BankAccount::Withdraw(amt);   
noOfWithdrawls++;
}
}

=======================================

// SavingsAccount.h

#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include <string>
#include "BankAccount.h" // Account class definition
// Creating a Checking Account class derivied from Account class
class SavingsAccount : public BankAccount
{
public:
// parameterized constructor
SavingsAccount(float balance);

void Withdraw(float amt);
private:
  
};
#endif

=======================================

// SavingsAccount.cpp

#include <iostream>
#include <string>
using namespace std;
#include "SavingsAccount.h"

SavingsAccount::SavingsAccount(float balance):BankAccount(balance)
{
  
}

void SavingsAccount::Withdraw(float amt)
{
if(noOfWithdrawls<3)
{
BankAccount::Withdraw(amt);
noOfWithdrawls++;
}
}

=====================================

// CreditAccount.h

#ifndef CREDITACCOUNT_H
#define CREDITACCOUNT_H
#include <string>
#include "BankAccount.h" // Account class definition
// Creating a Checking Account class derivied from Account class
class CreditAccount : public BankAccount
{
public:
// parameterized constructor
CreditAccount();

void Withdraw(float amt);
private:
const static double LIMIT;
float charge;
float amount;
};
#endif

====================================

// CreditAccount.cpp

#include <iostream>
#include <string>
using namespace std;
#include "CreditAccount.h"

const double CreditAccount::LIMIT=40;
// parameterized constructor
CreditAccount::CreditAccount()
{
this->charge=0;
this->amount=LIMIT;
}

void CreditAccount::Withdraw(float amt)
{
if(LIMIT-amt<0)
{
this->charge+=4000;
}
else{
this->amount-=amt;
}
}

==================================

// main.cpp

#include <iostream>
#include <iomanip>
#include "BankAccount.h" // Account class definition
//#include "SavingsAccount.h" // SavingsAccount class definition
#include "CheckingAccount.h" // CheckingAccount class definition
#include "SavingsAccount.h" // CheckingAccount class definition
#include "CreditAccount.h" // CheckingAccount class definition
using namespace std;
int main()
{
int choice;
SavingsAccount sa(5000);
CheckingAccount ca(10000);
  
while(true)
{
cout<<"\n:: MENU ::"<<endl;
cout<<"1.Deposit"<<endl;
cout<<"2.Withdraw"<<endl;
cout<<"3.Balance"<<endl;
cout<<"4.Exit"<<endl;
  
cout<<"Enter Choice :";
cin>>choice;
switch(choice)
{
case 1:{
continue;
}
case 2:{
continue;
}
case 3:{
continue;
}
case 4:{
break;
}
default:{
cout<<"** Invalid Choice **"<<endl;
continue;
}
  
  
}

break;
}

  
return 0;
}

Homework Answers

Answer #1

Note : I developed the main() function. If u have atleast sample output I would have developed the code exactly as per ur requirement.Anyway....plz check. below code...Thank u

========================================

// BankAccount.h

#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <string>
#include <iostream>
using namespace std;
class BankAccount
{
protected :
int noOfWithdrawls;
private:
// Declaring variables
  
float balance;
static unsigned int numAccounts;
public:
// parameterized constructor
BankAccount();
BankAccount(float bal);
void Withdraw(float amount); // decreases balance by amount
void Deposit(float amount); // increases balance by amount
float GetBalance() const;
  
};
#endif

======================================

// BankAccount.cpp

#include <iostream>
#include <string>
using namespace std;
#include "BankAccount.h"

BankAccount::BankAccount()
{
this->balance=0;
}
BankAccount::BankAccount(float bal)
{
this->balance=bal;
}
// decreases balance by amount
void BankAccount::Withdraw(float amount)
{
if(balance-amount>=0)
{
this->balance-=amount;
noOfWithdrawls++;
}
else{
cout<<"____Insufficient funds____"<<endl;
}
}
// increases balance by amount
void BankAccount::Deposit(float amount)
{
this->balance+=amount;
}
float BankAccount::GetBalance() const
{
return balance;
}

========================================

// SavingsAccount.h

#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include <string>
#include "BankAccount.h" // Account class definition
// Creating a Savings Account class derivied from Account class
class SavingsAccount : public BankAccount
{
public:
// parameterized constructor
SavingsAccount(float balance);
SavingsAccount();

void Withdraw(float amt);
private:
  
};
#endif

=============================================

// SavingsAccount.cpp

#include <iostream>
#include <string>
using namespace std;
#include "SavingsAccount.h"

SavingsAccount::SavingsAccount(float balance):BankAccount(balance)
{
  
}

SavingsAccount::SavingsAccount()
{

}
void SavingsAccount::Withdraw(float amt)
{
if(noOfWithdrawls<3)
{
BankAccount::Withdraw(amt);
noOfWithdrawls++;
}
}

========================================

// CheckingAccount.h

#ifndef CHECKING_H
#define CHECKING_H
#include <string>
#include "BankAccount.h" // Account class definition
// Creating a Checking Account class derivied from Account class
class CheckingAccount : public BankAccount
{
public:
// parameterized constructor
CheckingAccount(float balance);
CheckingAccount();
void Withdraw(float amt);
private:
  
};
#endif

=============================================

// CheckingAccount.cpp

#include <iostream>
#include <string>
using namespace std;
#include "CheckingAccount.h"


// parameterized constructor
CheckingAccount::CheckingAccount(float balance):BankAccount(balance)
{
}

CheckingAccount::CheckingAccount()
{

}
void CheckingAccount::Withdraw(float amt)
{
if(noOfWithdrawls>10)
{
BankAccount::Withdraw(amt+5);
noOfWithdrawls++;
}
else
{
BankAccount::Withdraw(amt);   
noOfWithdrawls++;
}
}

==============================================

// CreditAccount.h

#ifndef CREDITACCOUNT_H
#define CREDITACCOUNT_H
#include <string>
#include "BankAccount.h" // Account class definition
// Creating a Checking Account class derivied from Account class
class CreditAccount : public BankAccount
{
public:
// parameterized constructor
CreditAccount();

void Withdraw(float amt);
double getLimit();
private:
const static double LIMIT;
float charge;
float amount;
};
#endif

===============================================

//CreditAccount.cpp

#include <iostream>
#include <string>
using namespace std;
#include "CreditAccount.h"

const double CreditAccount::LIMIT=40;
// parameterized constructor
CreditAccount::CreditAccount()
{
this->charge=0;
this->amount=LIMIT;
}

void CreditAccount::Withdraw(float amt)
{
if(LIMIT-amt<0)
{
this->charge+=4000;
}
else{
this->amount-=amt;
}
}

double CreditAccount::getLimit()
{
cout<<"Charges :$"<<charge<<endl;
return amount;
}

=======================================

// main.cpp

#include <iostream>
#include <iomanip>
#include <ctime>

#include <cstdlib>
#include "BankAccount.h" // Account class definition
//#include "SavingsAccount.h" // SavingsAccount class definition
#include "CheckingAccount.h" // CheckingAccount class definition
#include "SavingsAccount.h" // CheckingAccount class definition
#include "CreditAccount.h" // CheckingAccount class definition
using namespace std;

int menu();
int main()
{
srand(time(NULL));
int choice;
double amt;
SavingsAccount sa;
CheckingAccount ca;
CreditAccount credit;

  
while(true)
{
cout<<"\n:: MENU ::"<<endl;
cout<<"1.Savings Account"<<endl;
cout<<"2.Checking Account"<<endl;
cout<<"3.Credit Account"<<endl;
cout<<"4.Exit"<<endl;
  
cout<<"Enter Choice :";
cin>>choice;
switch(choice)
{
case 1:{
choice=menu();
switch(choice)
{
case 1:{
cout<<"Enter amount to deposit :$";
cin>>amt;
sa.Deposit(amt);
cout<<"Your Balance :$"<<sa.GetBalance()<<endl;
break;
}
case 2:{
cout<<"Enter amount to withdraw :$";
cin>>amt;
sa.Withdraw(amt);
cout<<"Your Balance :$"<<sa.GetBalance()<<endl;
break;
}
  
}
continue;
}
case 2:{
choice=menu();
switch(choice)
{
case 1:{
cout<<"Enter amount to deposit :$";
cin>>amt;
ca.Deposit(amt);
cout<<"Your Balance :$"<<ca.GetBalance()<<endl;
break;
}
case 2:{
cout<<"Enter amount to withdraw :$";
cin>>amt;
ca.Withdraw(amt);
cout<<"Your Balance :$"<<ca.GetBalance()<<endl;
break;
}
  
}
continue;
}
case 3:{
int shoppingBill=rand()%(5) + 1;
cout<<"Your Shopping Amount is :$"<<shoppingBill<<endl;
credit.Withdraw(shoppingBill);
cout<<"You Limit in Credit Account :$"<<credit.getLimit()<<endl;
continue;
}
case 4:{
break;
}
default:{
cout<<"** Invalid Choice **"<<endl;
continue;
}
  
  
}
break;
}

  
return 0;
}

int menu()
{
int choice;
while(true)
{
cout<<"1.Deposit :"<<endl;
cout<<"2.Withdraw "<<endl;
cout<<"Enter Choice :";
cin>>choice;
if(choice==1 || choice==2)
{
break;
}
else{
cout<<"** Invalid.Must be either 1 or 2 **"<<endl;
}
}
return choice;
}

==================================================

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Complete the missing code for the constructors as indicated in the comments in all three header...
Complete the missing code for the constructors as indicated in the comments in all three header files. C++ mainDriver.cpp #include <string> #include "Address.h" #include "Date.h" #include "Person.h" using namespace std; int main() {    Person p1;    Person p2("Smith", "Bobby", "[email protected]", 111, "Main St", "Clemson",            "SC", 29630, 1, 31, 1998);    cout << endl << endl;    p1.printInfo();    p2.printInfo();    return 0; } Person.h #ifndef PERSON_H #define PERSON_H #include <iostream> #include <string> using namespace std; class...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits from base class Account and include an additional data member of type double that represents the fee charged per transaction (transactionFee). Write Checking- Account’s constructor that receives the initial balance, as well as a parameter indicating a transaction fee amount. If transaction fee is less than zero, the transactionFee will be set to zero. Write the chargeFee member function that updates the balance by...
In main.cpp, write a templated function more which takes in two variables of the same type...
In main.cpp, write a templated function more which takes in two variables of the same type and returns whichever variable is greater than (>) the other. You can and may need to add something to the food class in order for more to be able to be called properly. //food.h #ifndef _FOOD_H #define _FOOD_H #include <iostream> #include <string> using namespace std; class Food { private: string name; int quantity; public: Food(); void setName(string newName); void setQuantity(int newQuantity); string getName(); int...
C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L...
C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L W T. But it showed L L L.IDK why the moveNo is not working. I am asking for help, plz dont put some random things on it. main.cpp #include <iostream> #include "computer.h" #include "human.h" #include "referee.h" using namespace std; int main() {     human h;     computer c;     referee r;     r.compare(h,c);     return 0; } computer.cpp #include<iostream> #include "computer.h" using namespace std;...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Utilize the code from last week Add a default, full, and copy constructor. Also add a...
Utilize the code from last week Add a default, full, and copy constructor. Also add a constructor that allows you to specify only the name of the video game with no high score or times played specified. Adjust your code to demonstrate use of all 4 constructors and output of the resulting objects. #include <iostream> #include <string> #include <iomanip> using namespace std; class VideoGame { private:     string name;     int highScore;     int numOfPlays; public:     VideoGame() {        ...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h"...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h" template StackLinked::StackLinked (int maxNumber) { } template StackLinked::StackLinked(const StackLinked& other) { } template StackLinked& StackLinked::operator=(const StackLinked& other) { } template StackLinked::~StackLinked() {    clear(); } template void StackLinked::push(const DataType& newDataItem) throw (logic_error) {    } template DataType StackLinked::pop() throw (logic_error) { } template void StackLinked::clear() {    StackNode* t;    while ( top != NULL)    {        t = top;       ...
Convert this C++ to JavaScript and run in browser. #include <cstdlib> #include <ctime> #include <sstream> #include...
Convert this C++ to JavaScript and run in browser. #include <cstdlib> #include <ctime> #include <sstream> #include <iostream> using namespace std; /* * */ class Dice{ private: static const int MAXDICE=6; static const int MINDICE=1; int faceVal; public: Dice(int); void setFace(int); int getFace(); string toString(); }; Dice::Dice(int faceVal) { if(faceVal<MINDICE&&faceVal>MAXDICE) { setFace(1); } else { this->faceVal=faceVal; } } void Dice::setFace(int faceVal) { this->faceVal=faceVal; } int Dice::getFace() { return faceVal; } string Dice::toString() { stringstream ss; ss<<faceVal; string str="face value is ";...
Please fill in the blank bolded below that would be the best choice for this program....
Please fill in the blank bolded below that would be the best choice for this program. #include <iostream> using namespace std; const int size = 100000; class TheBig { public: double operator[](int index) const {return (theData[index]);} private: double theData[size]; }; void firstToBeThe( ______________________________________________________) { for (int i = 0; i <size; i++) cout << value[i] <<endl; } int main() { TheBig one; firstToBeThe(one); }
Please Use C++ I tried to calculate complex number by using *= and operator /= but...
Please Use C++ I tried to calculate complex number by using *= and operator /= but I got an incorrect result compared with the result of complex number calculator For example, When I calculate ( (c5 *= c4) *= c4) by using my operator function, the result was 1.08288e+06+1.11262e+07i on output, However, when using a complex calculator, the result was = −253987.448 − 355181.112i, so I got the wrong answer There is my code below. It compiles well, but my...