Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have created the base class below, but am having an issue with the second half of the question that requires me to incorporate the

I have created the base class below, but am having an issue with the second half of the question that requires me to incorporate the base class into the new program. This base class needs to be implemented as a header and included in main.

You are now working for a department store, and your task is to create a point-of-sale application to allow customers to calculate the total cost of their sale including taxes.

Using C++ object-oriented programming (OOP), the base class, Simplemath, has the following derived classes within: Addition, Subtraction, Division, Multiplication. The user has the option to choose which calculation he or she prefers to use.

Create a C++ program that does the following:

Calculates sales tax and total cost based on the type of purchased product using the following categories and tax percentages:

Category 1 - Clothing: 6%

Category 2 - Beauty products: 7%

Category 3 - Grocery: 3%

Category 4 - Gardening: 6%

Category 5 - School supplies: 3%

Category 6 - Tobacco products: 10%

Creates an array to store the numbers users input and uses the switch statement to calculate the sales tax and final cost based on the category of the purchased product

Prompts the user for category and price of the product

Calculates and displays the final cost

BASE CLASS PROGRAM:

#include "stdafx.h"

#include

#include

using namespace std;

int numberInput1 = 0;

int numberInput2 = 0;

void addition();

void subtraction();

void multiplication();

void division();

int displayMenu();

int main()

{

int goodbye = 0;

cout << "Welcome to Math Calc program!" << endl;

do

{

int option = displayMenu();

switch (option)

{

case 1:

addition();

break;

case 2:

subtraction();

break;

case 3:

multiplication();

break;

case 4:

division();

break;

case 5:

cout << "Thank you for using the Math Calc program." << endl;

goodbye = -1;

break;

}

} while (goodbye != -1);

::system("Pause");

cout << "Good-Bye!" << endl;

return 0;

}

void addition()

{

cout.width(40); cout << "ADDITION MATH!" << endl;

cout.width(42); cout << "-------------- " << endl;

int size = 0;

int answer = 0;

cout << "How many addition problems would you like to enter? ";

cin >> size;

cout << endl;

int *myArray1 = new int[size];

int *myArray2 = new int[size];

for (int i = 1; i <= size; i++)

{

cout << "Number set " << i << endl;

cout << "Please enter the 1st number between 0-9999: ";

cin >> numberInput1;

while (numberInput1 < 0 || numberInput1 > 9999)

{

cout << "WARNING! Please enter the 1st number again between 0-9999: ";

cin >> numberInput1;

}

myArray1[i] = numberInput1;

cout << "Please enter the 2nd number between 0-9999: ";

cin >> numberInput2;

while (numberInput2 < 0 || numberInput2 > 9999)

{

cout << "WARNING! Please enter 2nd number again between 0-9999: ";

cin >> numberInput2;

}

myArray2[i] = numberInput2;

cout << endl;

}

cout << "------------------------ ";

cout << "Display of your Addition problems " << endl;

for (int i = 1; i <= size; i++)

{

answer = myArray1[i] + myArray2[i];

cout << setw(12) << myArray1[i] << endl;

cout << setw(8) << "+" << setw(4) << myArray2[i] << endl;

cout << setw(12) << "-------";

cout << endl << setw(12) << answer << " ";

cout << "------------------------ ";

}

::system("PAUSE");

}

void subtraction()

{

cout.width(40); cout << "SUBTRACTION MATH!" << endl;

cout.width(42); cout << "----------------- " << endl;

int size = 0;

int answer = 0;

cout << "How many subtraction problems you want to enter? ";

cin >> size;

cout << endl;

int *myArray1 = new int[size];

int *myArray2 = new int[size];

for (int i = 1; i <= size; i++)

{

cout << "Number set " << i << endl;

cout << "Please enter the 1st number between 0-9999: ";

cin >> numberInput1;

while (numberInput1 < 0 || numberInput1 > 9999)

{

cout << "WARNING! Please enter the 1st number again between 0-9999: ";

cin >> numberInput1;

}

myArray1[i] = numberInput1;

cout << "Please enter the 2nd number between 0-9999: ";

cin >> numberInput2;

while (numberInput2 < 0 || numberInput2 > 9999)

{

cout << "WARNING! Please enter 2nd number again between 0-9999: ";

cin >> numberInput2;

}

myArray2[i] = numberInput2;

cout << endl;

}

cout << "------------------------ ";

cout << "Display of your Subtraction problems " << endl;

for (int i = 1; i <= size; i++)

{

answer = myArray1[i] - myArray2[i];

cout << setw(12) << myArray1[i] << endl;

cout << setw(8) << "-" << setw(4) << myArray2[i] << endl;

cout << setw(12) << "-------";

cout << endl << setw(12) << answer << " ";

cout << "------------------------ ";

}

::system("PAUSE");

}

void multiplication()

{

cout.width(40); cout << "MULTIPLICATION MATH!" << endl;

cout.width(42); cout << "-------------------- " << endl;

int size = 0;

int answer = 0;

cout << "How many multiplication problems you want to enter? ";

cin >> size;

cout << endl;

int *myArray1 = new int[size];

int *myArray2 = new int[size];

for (int i = 1; i <= size; i++)

{

cout << "Number set " << i << endl;

cout << "Please enter the 1st number between 0-9999: ";

cin >> numberInput1;

while (numberInput1 < 0 || numberInput1 > 9999)

{

cout << "WARNING! Please enter the 1st number again between 0-9999: ";

cin >> numberInput1;

}

myArray1[i] = numberInput1;

cout << "Please enter the 2nd number between 0-9999: ";

cin >> numberInput2;

while (numberInput2 < 0 || numberInput2 > 9999)

{

cout << "WARNING! Please enter 2nd number again between 0-9999: ";

cin >> numberInput2;

}

myArray2[i] = numberInput2;

cout << endl;

}

cout << "------------------------ ";

cout << "Display of your multiplication problems " << endl;

for (int i = 1; i <= size; i++)

{

answer = myArray1[i] * myArray2[i];

cout << setw(12) << myArray1[i] << endl;

cout << setw(8) << "x" << setw(4) << myArray2[i] << endl;

cout << setw(12) << "-------";

cout << endl << setw(12) << answer << " ";

cout << "------------------------ ";

}

::system("PAUSE");

}

void division()

{

cout.width(40); cout << "DIVISION MATH!" << endl;

cout.width(42); cout << "-------------- " << endl;

int size = 0;

double answer = 0;

cout << "How many division problems you want to enter? ";

cin >> size;

cout << endl;

double *myArray1 = new double[size];

double *myArray2 = new double[size];

for (int i = 1; i <= size; i++)

{

cout << "Number set " << i << endl;

cout << "Please enter the 1st number between 0-9999 to be the dividend: ";

cin >> numberInput1;

while (numberInput1 < 0 || numberInput1 > 9999)

{

cout << "WARNING! Please enter the 1st number again between 0-9999 to be the dividend: ";

cin >> numberInput1;

}

myArray1[i] = numberInput1;

cout << "Please enter the 2nd number between 0-9999 to be the divisor: ";

cin >> numberInput2;

while (numberInput2 < 0 || numberInput2 > 9999)

{

cout << "WARNING! Please enter 2nd number again between 0-9999 to be the divisor: ";

cin >> numberInput2;

}

myArray2[i] = numberInput2;

cout << endl;

}

cout << "------------------------ ";

cout << "Display of your Division problems " << endl;

for (int i = 1; i <= size; i++)

{

answer = myArray1[i] / myArray2[i];

cout << setw(12) << myArray1[i] << endl;

cout << setw(14) << "--------" << " = " << answer << endl;

cout << setw(12) << myArray2[i] << endl;

cout << setw(12) << endl;

cout << "------------------------ ";

}

::system("PAUSE");

}

int displayMenu()

{

int option; //variable to hold user's selection

do

{

cout.width(55); cout << setw(25) << "" << "MATH CALC PROGRAM" << endl;

cout.width(55); cout << setw(25) << "" << "---------------------" << endl;

cout << endl;

cout.width(50); cout << setw(25) << "" << "1) Addition" << endl;

cout.width(50); cout << setw(25) << "" << "2) Subtraction" << endl;

cout.width(50); cout << setw(25) << "" << "3) Multiplication" << endl;

cout.width(50); cout << setw(25) << "" << "4) Division" << endl;

cout.width(50); cout << setw(25) << "" << "5) Quit program" << endl;

cout.width(50); cout << setw(25) << "" << "Please make a selection: ";

cin >> option;

cout << endl;

//if statement in case user enters an invalid number

if (option < 1 || option > 5)

{

cout << "Invalid selection." << endl;

cout << "Please enter a valid number." << endl;

::system("PAUSE");

}

} while (option < 1 || option > 5);

return option;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 89 2nd Symposium On Mathematical Fundamentals Of Database Systems Visegrad Hungary June 26 30 1989 Proceedings

Authors: Janos Demetrovics ,Bernhard Thalheim

1989th Edition

3540512519, 978-3540512516

More Books

Students also viewed these Databases questions