In: Computer Science
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom.
Welcome to the DeVry Bank Automated Teller Machine
Check balance
Make withdrawal
Make deposit
View account information
View statement
View bank information
Exit
The result of choosing #1 will be the
following:
Current
balance is: $2439.45
The result of choosing #2 will be the
following:
How much
would you like to withdraw? $200.50
The result of choosing #3 will be the
following:
How much
would you like to deposit?
$177.32
The result of choosing #4 will be the following:
Name: (Student’s first and last name goes here)
Account Number: 1234554321
The result of choosing #5 will be the
following:
01/01/11 -
McDonald’s - $6.27
01/15/11 - Kwik Trip - $34.93
02/28/11 - Target - $124.21
The result of choosing #6 will be the
following:
Devry Bank,
established 2011
(123) 456-7890
12345 1st St.
Someplace, NJ 12345
The result of choosing #7 will be the
following:
*Exit the
program - terminate console application.
You will create a Menu Builder class (for menu applications), a Test Menu class (for Main), and a MenuBuilder.h for a total of three files as a demonstration of understanding, creating, and using classes.
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class MenuBuilder
{
private:
double balance; // private data member
public:
MenuBuilder();
~MenuBuilder();
// methods
void buildMenu();
void processInput(int);
};
#include "MenuBuilder.h"
// constructor
MenuBuilder::MenuBuilder(void);
{
balance = 2439.45;
}
MenuBuilder::MenuBuilder()
{
}
// deconstructor
MenuBuilder::~MenuBuilder(void)
{
}
// output the menu
void MenuBuilder::buildMenu()
{
cout << endl;
cout << " Welcome to the DeVry Bank Automated
Teller Machine" << endl << endl;
cout << " 1. Check Balance " <<
endl;
cout << " 2. Make Withdrawl " <<
endl;
cout << " 3. Make Deposit " << endl;
cout << " 4. View Account Information " <<
endl;
cout << " 5. View Statement " <<
endl;
cout << " 6. View Bank Information " <<
endl;
cout << " 7. Exit " << endl;
cout << " Enter Selection: " << endl;
}
// Process user's choice
void MenuBuilder::processInput(int choice)
{
double withdrawl;
double deposit;
double balance;
switch (choice)
{
case 1: cout << " Your current balance is: "
<< balance << endl; break;
case 2: cout << " How much would you like to
withdraw? " << endl;
cin >> withdrawl;
if (balance > withdrawl
&& withdrawl > 0)
balance =
balance - withdrawl;
cout << " Your balance after
withdrawl is : " << balance << endl;
else
cout << "
Invalid withdrawl!" << endl;
break;
case 3: cout << " How much would you like to
deposit? " << deposit << endl;
cin >> deposit;
if (deposit > 0)
balance =
balance + deposit;
cout << " You balance after
deposit is: " << balance << endl;
else
cout << "
Invalid deposit! " << endl;
break;
case 4: cout << " Account information : "
<< endl;
cout << " Name: Alicia
Shorts" << endl;
cout << " Account Number:
246743522829" << endl;
break;
case 5: cout << " 01/01/11 - McDonald's - $6.27
" << endl;
cout << " 01/15/11- Kwik Trip
- $34.93" << endl;
cout << " 02/28/11-
Target-$124.21" << endl;
break;
case 6: cout << " DeVry Bank, established 2011"
<< endl;
cout << " (123) 456-7890"
<< endl;
cout << " 12345 1st St."
<< endl;
cout << " Someplace, NJ
12345" << endl;
break;
case 7: cout << "Invalid selection" <<
endl; break;
default: cout << " Invalid selection" <<
endl; break;
}// switch
}
#include "MenuBuilder.h"
int main()
{
// declare variables
MenuBuilder transaction;
int choice = 0;
while (choice != 7)
{
transaction.buildMenu();
cin >> choice;
transaction.processInput(choice);
}
The errors are mainly because of improper using of if-else blocks in switch statement.
Working Code:
File: main.cpp
#include "MenuBuilder.h"
int main()
{
// declare variables
MenuBuilder transaction;
int choice = 0;
while (choice != 7)
{
transaction.buildMenu();
cin >>
choice;
transaction.processInput(choice);
}
}
File: MenuBuilder.h
#ifndef MENUBUILDER_H_INCLUDED
#define MENUBUILDER_H_INCLUDED
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class MenuBuilder
{
private:
double balance; // private data member
public:
MenuBuilder();
~MenuBuilder();
// methods
void buildMenu();
void processInput(int);
};
#endif // MENUBUILDER_H_INCLUDED
File: MenuBuilder.cpp
#include "MenuBuilder.h"
// constructor
MenuBuilder::MenuBuilder(void)
{
balance = 2439.45;
}
// destructor
MenuBuilder::~MenuBuilder(void)
{
}
// output the menu
void MenuBuilder::buildMenu()
{
cout << endl;
cout << "
Welcome to the DeVry Bank Automated Teller Machine" << endl
<< endl;
cout << " 1. Check Balance "
<< endl;
cout << " 2. Make Withdrawl "
<< endl;
cout << " 3. Make Deposit "
<< endl;
cout << " 4. View Account
Information " << endl;
cout << " 5. View Statement "
<< endl;
cout << " 6. View Bank
Information " << endl;
cout << " 7. Exit " <<
endl;
cout << "
Enter Selection: ";
}
// Process user's choice
void MenuBuilder::processInput(int choice)
{
double withdrawl;
double deposit;
switch (choice)
{
case 1: cout << "
Your current balance is: $" << balance << endl;
break;
case 2: cout <<
" How much would you like to withdraw? $";
cin >> withdrawl;
if (balance > withdrawl && withdrawl > 0)
{
balance = balance - withdrawl;
cout << " Your balance after withdrawl is : $" <<
balance << endl;
}
else
{
cout << " Invalid withdrawl!" << endl;
}
break;
case 3: cout <<
" How much would you like to deposit? $";
cin >> deposit;
if (deposit > 0)
{
balance = balance + deposit;
cout << " You balance after deposit is: $" << balance
<< endl;
}
else
{
cout << " Invalid deposit! " << endl;
}
break;
case 4: cout <<
" Account information : " << endl;
cout << " Name: Alicia Shorts" << endl;
cout << " Account Number: 246743522829" << endl;
break;
case 5: cout <<
" 01/01/11 - McDonald's - $6.27 " << endl;
cout << " 01/15/11- Kwik Trip - $34.93" << endl;
cout << " 02/28/11- Target-$124.21" << endl;
break;
case 6: cout <<
" DeVry Bank, established 2011" << endl;
cout << " (123) 456-7890" << endl;
cout << " 12345 1st St." << endl;
cout << " Someplace, NJ 12345" << endl;
break;
case 7: exit(0);
default: cout
<< " Invalid selection" << endl; break;
}// switch
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sample Output: