Question: How would you program a c++ program so that when a customer inputs money/change into a register that the register gives the correct amount of

How would you program a c++ program so that when a customer inputs money/change into a register that the register gives the correct amount of change back (grabbing the largest first)? Keeping in mind that the register only contains ns Start up amounts: Ten five dollar bills Ten one dollar bills One roll of quarters ($10) One roll of dimes ($5) One roll of nickels ($2)...?

Directions:

A 2 part menu should display the pizza sizes with costs and the available toppings. Make sure to convey the differing costs for the toppings. You can design the menu any way you'd like. The menu of toppings must be displayed before each selection. Don't expect the user to memorize the menu.

When the manager hits the "magic" exit button, a complete list of the number of each product sold must be displayed. In addition, the number of each monetary unit left must be displayed AND output to the file: "Report.txt"

User Input

Minimally, your machine must accept ten, five and one dollar bills, quarters, dimes, and nickels

You must permit multiple coins/bills to be entered individually. So, a user can't enter 35 cents - they would have to enter a quarter and a dime.

Don't accept any wooden nickels...

You cannot keep any extra money

You must give change according to what is on hand - if you are out of one dollar bills, check if you have enough quarters on hand

If the user doesn't have enough money or there isn't enough change, you must return the exact denominations that they entered

The cash register

Must maintain the total of each monetary unit

Must calculate the profit (total sales)

Cannot create 2 dimes and a nickel from a quarter

Start up amounts: Ten five dollar bills Ten one dollar bills One roll of quarters ($10) One roll of dimes ($5) One roll of nickels ($2)

More general directions:

Your group (2 or 3 students) is to develop a "pizza" class and implementation to simulate a pizza shop. The system is to permit the employees of the establishment to generate an order, "make" the pizza (simply indicate when appropriate that the pizza is ready), and have the pizza picked up by the customer.

In order to complete the pricing of pizza, use the following:

Pizzas come in at least three sizes 12", 14", and 16"

Plain pizza costs -- $6.95, $7.95, and $8.95

Toppings cost $ .50 for the 12" and 14" And $1.00 for the 16"

After the 3rd topping, additional toppings are half price

The program is to show the sizes and toppings available, give directions on how to order pizzas and how to terminate. The pizzaria only accepts cash and never carries anything larger than a ten dollar bill When the program terminates, the profit for the day must be displayed and the number of each denomination must be shown.

Your program must contain:

a cash register object

a pizza object (that includes vectors)

Each object must be fully defined

overloaded operators including input and output

constructors

setters and getters

vectors

default arguments where appropriate

constants where appropriate

I currently have five files in visual studio. Pizza.cpp, pizza.h, Register.cpp, Register.h, and main.cpp. I am getting close to the end, but i would really appreciate someone else's perspective and code on how to do this. I can throw my code up if needed.

MAIN

#include "Pizza.h"

#include "Register.h"

#include

#include

using namespace std;

int main() {

Register reg(40, 50, 40, 10, 10, 10);

while (1)

reg.Menu();

system("pause");

}

PIZZA.CPP

#include "Pizza.h"

Pizza::Pizza() {

size = 0;

}

void Pizza::Reset() {

size = 0;

toppings.clear();

}

int Pizza::GetSize() {

return size;

}

vector Pizza::GetToppings() {

return toppings;

}

void Pizza::SetSize(int size) {

this->size = size;

}

void Pizza::AddTopping(string topping) {

this->toppings.push_back(topping);

}

PIZZA.H

#pragma once

#include

#include

using namespace std;

class Pizza

{

private:

int size;

vector toppings;

public:

Pizza();

void Reset();

int GetSize();

vector GetToppings();

void SetSize(int size);

void AddTopping(string topping);

};

REGISTER.CPP

#include "Register.h"

Register::Register(int nickels, int dimes, int quarters, int dollars, int fiveDollars, int tenDollars) {

this->nickels = nickels;

this->dimes = dimes;

this->quarters = quarters;

this->dollars = dollars;

this->fiveDollars = fiveDollars;

this->tenDollars = tenDollars;

this->pizza = Pizza();

pizzaPrice = 0;

}

void Register::OpenRegister() {

cout << "Opening Register..." << endl;

mciSendString("open cdaudio", 0, 0, 0);

mciSendString("set CDAudio door open", 0, 0, 0);

INPUT ip = { 0 };

ip.type = INPUT_KEYBOARD;

ip.ki.wVk = VK_VOLUME_UP;

SendInput(1, &ip, sizeof(INPUT));

ip.ki.dwFlags = KEYEVENTF_KEYUP;

SendInput(1, &ip, sizeof(INPUT));

CoInitialize(NULL);

IMMDeviceEnumerator *deviceEnumerator = NULL;

CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);

IMMDevice *defaultDevice = NULL;

deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);

deviceEnumerator->Release();

deviceEnumerator = NULL;

IAudioEndpointVolume *endpointVolume = NULL;

defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);

defaultDevice->Release();

defaultDevice = NULL;

endpointVolume->SetMasterVolumeLevelScalar(1, NULL);

endpointVolume->Release();

CoUninitialize();

PlaySound("C:/Windows/Media/tada.wav", NULL, SND_ASYNC);

Sleep(3000);

cout << "Closing Register..." << endl;

mciSendString("set CDAudio door closed", 0, 0, 0);

}

void Register::PrintPizzaToppings() {

vector temp = pizza.GetToppings();

for (unsigned i = 0; i < temp.size(); i++) {

cout << temp[i];

if (i < temp.size() - 1)

cout << ", ";

}

}

void Register::SetMoney(int nickels, int dimes, int quarters, int dollars, int fiveDollars, int tenDollars) {

this->nickels = nickels;

this->dimes = dimes;

this->quarters = quarters;

this->dollars = dollars;

this->fiveDollars = fiveDollars;

this->tenDollars = tenDollars;

}

void Register::Menu() {

int input = GetMenuInput();

switch (input) {

case 1:

MenuPizzaSize();

break;

case 2:

MenuAddToppings();

break;

case 3:

pizza.Reset();

break;

case 4:

CalculateChange();

system("pause");

OpenRegister();

break;

case 5:

exit(EXIT_SUCCESS);

break;

}

cout << endl;

CalculatePizzaPrice();

}

int Register::GetMenuInput() {

int input = -1;

while (input < 0 || input > MENU_SIZE) {

system("cls");

vector temp = pizza.GetToppings();

cout << "Current Pizza:" << endl;

cout << "Price: $" << pizzaPrice << endl;

cout << "Size: " << PIZZA_SIZES[pizza.GetSize()] << "\"" << endl;

cout << "Toppings: ";

if (temp.size() > 0) {

PrintPizzaToppings();

}

else

cout << "None" << endl;

cout << endl;

cout << endl;

cout << "1. Change Pizza Size" << endl;

cout << "2. Add Topping" << endl;

cout << "3. Reset Pizza" << endl;

cout << "4. Checkout" << endl;

cout << "5. Exit" << endl;

cout << ">";

cin >> input;

cout << endl;

}

return input;

}

void Register::MenuPizzaSize() {

int input = -1;

while (input < 0 || input > 3) {

system("cls");

cout << "Select Pizza Size: " << endl;

cout << "1. 12\"" << endl;

cout << "2. 14\"" << endl;

cout << "3. 16\"" << endl;

cout << ">";

cin >> input;

}

pizza.SetSize(input);

}

void Register::MenuAddToppings() {

int input = -2;

while (input != -1) {

system("cls");

cout << "Enter -1 to stop adding toppings" << endl;

cout << "Current Toppings: "; PrintPizzaToppings(); cout << endl << endl;;

for (int i = 0; i < TOPPINGS_AMOUNT; i++) {

cout << i + 1 << ". " << TOPPING_NAMES[i] << endl;

}

cout << endl;

cout << ">";

cin >> input;

input--;

if (input >= 0 && input < TOPPINGS_AMOUNT)

pizza.AddTopping(TOPPING_NAMES[input]);

cin.get();

input++;

}

}

void Register::CalculatePizzaPrice() {

pizzaPrice = float(PIZZA_PRICES[pizza.GetSize()]);

for (unsigned i = 0; i < pizza.GetToppings().size(); i++) {

pizzaPrice += (i + 1 <= HALF_OFF_AFTER_TOPPING) ? TOPPING_PRICES[pizza.GetSize()] : TOPPING_PRICES[pizza.GetSize()] / 2;

}

}

void Register::CalculateChange() {

int input = -1;

system("cls");

float moneyAmount = 0;

cout << "Total Price: $" << pizzaPrice << endl;

cout << "Enter Money From Customer: " << endl;

cout << "Ten Dollar Bills: ";

cin >> input;

moneyAmount += input * 1000;

cout << "Five Dollar Bills: ";

cin >> input;

moneyAmount += input * 500;

cout << "One Dollar Bills: ";

cin >> input;

moneyAmount += input * 100;

cout << "Quarters: ";

cin >> input;

moneyAmount += input * 25;

cout << "Dimes: ";

cin >> input;

moneyAmount += input * 10;

cout << "Nickels: ";

cin >> input;

moneyAmount += input * 5;

moneyAmount /= 100;

float changeAmount = moneyAmount - pizzaPrice;

cout << endl;

cout << "Total Cost: $" << moneyAmount << endl;

cout << "Change back: $" << changeAmount << endl;

cout << endl;

cout << "Amount of ten dollar bills: " << int(changeAmount * 100) / 1000 << endl; //float changed to int, converted to compare to $10.

changeAmount = float(int(changeAmount * 100) % 1000); //changeAmount is modded to figure out what change is left to give to guest.

changeAmount /= 100;

cout << "Change left to give to guest: $" << changeAmount << endl;

cout << "Amount of five dollar bills: " << int(changeAmount * 100) / 500 << endl; //float changed to int, converted to compare to $5.

changeAmount = float(int(changeAmount * 100) % 500); //changeAmount is modded to figure out what change is left to give to guest.

changeAmount /= 100;

cout << "Change left to give to guest: $" << changeAmount << endl;

cout << "Amount of one dollar bills: " << int(changeAmount * 100) / 100 << endl; //float changed to int, converted to compare to $1.

changeAmount = float(int(changeAmount * 100) % 100); //changeAmount is modded to figure out what change is left to give to guest.

changeAmount /= 100;

cout << "Change left to give to guest: $" << changeAmount << endl;

cout << "Amount of quarters: " << int(changeAmount * 100) / 25 << endl; //float changed to int, converted to compare to $0.25.

changeAmount = float(int(changeAmount * 100) % 25); //changeAmount is modded to figure out what change is left to give to guest.

changeAmount /= 100;

cout << "Change left to give to guest: $" << changeAmount << endl;

cout << "Amount of dimes: " << int(changeAmount * 100) / 10 << endl; //float changed to int, converted to compare to $0.10.

changeAmount = float(int(changeAmount * 100) % 10); //changeAmount is modded to figure out what change is left to give to guest.

changeAmount /= 100;

cout << "Change left to give to guest: $" << changeAmount << endl;

cout << "Amount of nickels: " << int(changeAmount * 100) / 5 << endl; //float changed to int, converted to compare to $0.05.

changeAmount = float(int(changeAmount * 100) % 5); //changeAmount is modded to figure out what change is left to give to guest.

changeAmount /= 100;

cout << "Change left to give to guest: $" << changeAmount << endl;

}

int Register::GetNickels()

{

return nickels;

}

int Register::GetDimes()

{

return dimes;

}

int Register::GetQuarters()

{

return quarters;

}

int Register::GetDollars()

{

return dollars;

}

int Register::GetFiveDollars()

{

return fiveDollars;

}

int Register::GetTenDollars()

{

return tenDollars;

}

REGISTER.H

#pragma once

#include

#include

#include

#include

#include "Pizza.h"

using namespace std;

const int TOPPINGS_AMOUNT = 13;

const float PIZZA_SIZES[] = { 0, 12, 14, 16 };

const double PIZZA_PRICES[] = { 0.0, 6.95, 7.95, 8.95 };

const float TOPPING_PRICES[] = { 0, .5, .5, 1 };

const string TOPPING_NAMES[TOPPINGS_AMOUNT] = {"Pepperoni", "Sausage", "Bacon", "Chicken", "Ham", "Green Pepper", "Onions", "Olives", "Extra Cheese", "Extra Sauce", "Pineapple", "Mushrooms", "Spinach"};

const float HALF_OFF_AFTER_TOPPING = 3;

const int MENU_SIZE = 5;

class Register

{

private:

int nickels, dimes, quarters, dollars, fiveDollars, tenDollars;

float pizzaPrice;

Pizza pizza;

public:

Register(int nickels, int dimes, int quarters, int dollars, int fiveDollars, int tenDollars);

void OpenRegister();

void PrintPizzaToppings();

void SetMoney(int nickels, int dimes, int quarters, int dollars, int fiveDollars, int tenDollars);

void Menu();

int GetMenuInput();

void MenuPizzaSize();

void MenuAddToppings();

void CalculatePizzaPrice();

void CalculateChange();

int GetNickels();

int GetDimes();

int GetQuarters();

int GetDollars();

int GetFiveDollars();

int GetTenDollars();

};

END OF CODE

Even any partial help would be greatly appreciated. Thank you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!