Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class that represents a cash register. The cash register has the followi

ID: 3565509 • Letter: W

Question

Write a class that represents a cash register. The cash register has the following variables:

balance - current amount of money in register

subtotal -sub total cost of products

total - total cost of products It also has the following functions

calcTax() - applies 8.75% tax

getTotal() - given the sum, add the tax and return the total

addItemCost() - adds the item's cost to the current total

calcChange(double m) - computes change given an amount m paid

getBalance() - returns the amount of money in the register

setBalance(double b) - assigns a money amount to the register

getSubtotal() - returns the subtotal

Write a main program that asks the user how many items do they want to enter, then get the cost of those items, then displays subtotal, display tax, and then displays the total. Then ask the user for money and display their change. Also display the current balance (assume the register starts with a balance of 100.00). Allow the user to repeat entering cost of items as many times as they want.

Explanation / Answer

#include<iostream>

using namespace std;

class CashRegister{

      private:

              double balance;         // - current amount of money in register

              double subtotal;        // -sub total cost of products

              double total;           // - total cost of products

     

      public:

             CashRegister(){

                            balance = 100;

                            subtotal = total =0;

             }

             double calcTax(){                   // - applies 8.75% tax

                    double tax = 0.0875 * subtotal;

                    return tax;

             }

            

             double getTotal(){                         // - given the sum, add the tax and return the total

                               total = subtotal + calcTax();

                               return total;

             }

                              

             void addItemCost(double c){     // - adds the item's cost to the current total

                                subtotal+=c;

             }

            

             double calcChange(double m){    // - computes change given an amount m paid{

                               double change = m - total;

                               setBalance(balance+total);

                               total = 0;

                               subtotal = 0;

                               return change;

             }

            

             double getBalance(){             //- returns the amount of money in the register

                    return balance;

             }

            

             void setBalance(double b){         // - assigns a money amount to the register

                  balance = b;

             }

            

             double getSubtotal(){           // - returns the subtotal

                    return subtotal;

             }           

};

     

int main(){

    CashRegister* cr = new CashRegister();

    int option;

    do{

        int cost = 0;

        int c, n;

        cout<<"Enter number of item to purchase : ";      //purchase items

        cin >>n;

        for(int i=1;i<=n;i++){

            cout<<"Enter cost of item "<<i<<" : ";

            cin >> c;

            cost+=c;

        }

        (*cr).addItemCost(cost);              //add item cost to subtotal

        cout<<"Subtotal : "<< (*cr).getSubtotal() <<endl;

        cout<<"Tax : "<< (*cr).calcTax() <<endl;

        cout<<"Total : "<< (*cr).getTotal() <<endl<<endl;

        cout<<"Options"<<endl;

        cout<<"1. Add more items to buy."<<endl;

        cout<<"2. Proceed to payment."<<endl;

        cout<<"Any other to Exit."<<endl;

        cin>>option;

        if(option == 1){                 //add more items to buy

                     continue;

        }

        else if(option == 2){            //payment option

             double x;

             cout<<"Enter amount to pay with : ";

             cin>>x;

             cout<<"Your change returned is : "<<(*cr).calcChange(x)<<endl;

             cout<<"The balance amount of register is : "<<(*cr).getBalance()<<endl;

        }

    }while(option ==1 || option ==2);

    system("pause");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote