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;
}
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:
Get Answers For Free
Most questions answered within 1 hours.