Question

In: Computer Science

I am getting 7 errors can someone fix and explain what I did wrong. My code...

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);
   }

Solutions

Expert Solution

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:


Related Solutions

I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
I kept getting errors trying to make this code to work, can someone show me what...
I kept getting errors trying to make this code to work, can someone show me what i am doing wrong? import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.*; import java.util.*; import java.nio.file.*; import java.nio.charset.*; import java.util.*; //@WebServlet(name = "Assignment3_1", urlPatterns = { "/ReadFile" }) public class ReadFile extends HttpServlet{ static Charset myCharset = Charset.forName("US-ASCII"); @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType("text/html"); PrintWriter printer = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>"); out.println("Assignment 5.1"); out.println("</title>"); out.println("<h1>Is Bitcoin money?</h1>"); out.println("</head>"); out.println("<body>");...
In the following code down below I am not getting my MatrixElementMult right. Could someone take...
In the following code down below I am not getting my MatrixElementMult right. Could someone take a look at it and help fix it? Also, when I print out the matrices I don't want the decimals. I know it's a format thing but I'm new to C and not getting it. Thanks! #include <stdlib.h> #include <stdio.h> #include <math.h> #define N 8 typedef struct _Matrix { double element[N][N]; } Matrix; void PrintMatrix(Matrix a){ int i,j; for(i=0;i<N;i++){ for(j=0;j<N;j++){ printf(" %.1f ",a.element[i][j]); }...
Can someone please tell me why I am getting errors. I declared the map and it's...
Can someone please tell me why I am getting errors. I declared the map and it's values like instructed but it's telling me I'm wrong. #include <iostream> #include <stdio.h> #include <time.h> #include <chrono> #include <string> #include <cctype> #include <set> #include <map> #include "d_state.h" using namespace std; int main() { string name; map<string,string> s; map<string,string>::iterator it; s[“Maryland”] = "Salisbury"; s[“Arizona”] = "Phoenix"; s[“Florida”] = "Orlando"; s[“Califonia”] = "Sacramento"; s[“Virginia”] = "Richmond"; cout << "Enter a state:" << endl; cin >> name;...
c++ I am getting errors that say "expected a declaration". can you explain what it means...
c++ I am getting errors that say "expected a declaration". can you explain what it means by this and how I need to fix it?   #include <iostream> using namespace std; //functions void setToZero(int board[8][8]); void displayBoard(int oboard[8][8]); void movingFunction(); int main() {    // chess board 8x8    int board[8][8];    // all of the possible moves of the knight in 2 arrays    int colMove[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };    int rowMove[8]...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell that says payment is undefined. I am trying to create a main.js file that imports the function from the hr.js file; call the function passing the necessary arguments and log the result to the console. main.js var Dev = require("./hr.js") const { add } = require("./hr.js") var dev_type = 1; var hr = 40; console.log("your weekly payment is " + payment(dev_type, hr)) dev_type =...
Develop the following code for quiz (i am getting some errors)in python in such a manner...
Develop the following code for quiz (i am getting some errors)in python in such a manner that it shoulde be having extra 3 attempts(for wrong answrs) for all questions if the user entered wrong answer · for ex: If the user entered correct answer for first question #then 3 attempts will be carried to next questions. If the user entered 3 times wrong answer in 1st question itself means it sholud display as no more attempts and you got o...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT