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

C++ calling need help ASAP!!!! So I am trying to figure out how to call line 41

ID: 3730382 • Letter: C

Question

C++ calling need help ASAP!!!!

So I am trying to figure out how to call line 41 to function on line 105 after you make your selection it should display Selection: name, price per unit: $price

I need to know how to do this so each time you select it to display this so, for example, hit 1 for water Selection: Water, price per unit: $1.45 then it should ask for quantity. i should ask display this each choice you make until you end the loop for the summary.

This shoud look like:

vs.

Code:

#include <iostream>

#include <string>

#include <iomanip>

#include <sstream> // stringstream

#include <cctype> // isalph, isdigit

class Customer {

const std::string custName, custAddress;

public:

void custInfo(std::ostream &) const

{

}

void custWelcome(std::ostream &) const

{

std::cout << " Hello " << custName << " Address: " << custAddress << std::endl;

}

std::string custValue() const

{

return custName;

}

Customer(const std::string &inputCustName, const std::string &inputCustAddress)

: custName(inputCustName), custAddress(inputCustAddress)

{

}

};

struct Beverage {

const std::string name;

double price;

void bevInfo(std::ostream &) const

{

std::cout << "Name" << name << " "

<< "Price" << "$" << price << " "

<< "Total" << "$" << std::endl;

}

void bevSelect(std::ostream &) const

{

std::cout << "Selection: " << name << ", price per unit: $" << price << std::endl;

}

Beverage(const std::string &bevName, double bevPrice)

: name(bevName), price(bevPrice)

{

}

};

const int AVAILABLE_PRODUCTS_COUNT = 3;

const Beverage AVAILABLE_PRODUCTS[AVAILABLE_PRODUCTS_COUNT] = {

Beverage("Water", 1.45), // Element 0

Beverage("Soda", 2.98), // Element 1

Beverage("Ice Tea", 3.29) // Element 2

};

typedef int Quantities[AVAILABLE_PRODUCTS_COUNT];

Quantities ordered = { 0 };

double totalCost(Quantities);

void orderSummary(Quantities);

char getCharFromUser(const std::string &prompt);

Customer getCustomerFromUser();

void displayMenu(const Customer &);

void loadProductQuantity(const Beverage &, Quantities);

void doneShowOrder(const Customer &, Quantities);

double totalCost(Quantities beverageCount)//Cost loop

{

double totalCost = 0;

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

totalCost += (beverageCount[i] * AVAILABLE_PRODUCTS[i].price);

}

return totalCost;

}

void loadProductQuantity(int beverageNumber, int quantity)

{

ordered[beverageNumber] = quantity;

}

void doneShowOrder(const Customer &, Quantities)

{

orderSummary(ordered);

}

void displayMenu(const Customer &prompt)

{

std::cout << std::endl << std::endl

<< prompt.custValue()

<< ", Please select the beverage you would like to purchase from the menu: "

<< std::endl;

std::cout << "Drink Menu" << std::endl;

std::cout << "========" << std::endl;

std::cout << "1 - Water $1.45" << std::endl;

std::cout << "2 - Soda $2.98" << std::endl;

std::cout << "3 - Iced Tea $3.29" << std::endl;

std::cout << "X - Exit " << std::endl << std::endl;

}

char getCharFromUser(const std::string &prompt)

{

char key;

std::cout << "Selection: ";

std::cin >> key;

return key;

}

Customer getCustomerFromUser()

{

std::string custName;

std::string custAddress;

std::cout << "Please enter your name ==> ";

std::getline(std::cin, custName);

std::cout << "Please enter your address ==> ";

std::getline(std::cin, custAddress);

return Customer(custName, custAddress);

}

int main(void) {

Customer patron = getCustomerFromUser();

patron.custWelcome(std::cout);

patron.custInfo(std::cout);

bool done = false;

while (!done) {

int amountOrdered = 0;

displayMenu(patron);

switch (getCharFromUser("Your selection: ")) {

case '1':

std::cout << "Please chose a quantiy: ";

std::cin >> amountOrdered;

loadProductQuantity(0, amountOrdered);

break;

case '2':

std::cout << "Please chose a quantiy: ";

std::cin >> amountOrdered;

loadProductQuantity(1, amountOrdered);

break;

case '3':

std::cout << "Please chose a quantiy: ";

std::cin >> amountOrdered;

loadProductQuantity(2, amountOrdered);

break;

case 'X': case 'x':

done = true;

break;

default:

std::cout << "Invalid selection. Please try again";

std::cin.get();

// no break in the default case

}

}

doneShowOrder(patron, ordered);

std::cout << "Press any key to exit." << std::endl;

char blah;

std::cin >> blah;

return 0;

}

void orderSummary(Quantities ordered) {

std::cout << std::endl;

std::cout << "======= ORDER SUMMARY ====" << std::endl;

std::cout << "Items selected:" << std::endl;

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

// only show beverages that has at least one order

if (ordered[i] > 0) {

std::cout << " You selected: " << ordered[i] << " of " << AVAILABLE_PRODUCTS[i].name << std::endl;

}

}

std::cout << "Total cost: " << "$" << totalCost(ordered) << std::endl;

}

Please help with this!!!

CS5115 P3 Quick Launch (Ctrl-O) n (Running) Microsoft Visual Studio File Edit View Project Build Debug Team Tools Test Analyze Window Help Joe Hotman JH S115 IP3_JosephHoffman.exe - ? Application Insights CAUsersACE istsourcerepostCSS 1 1 5-IP3JosephHo Please enter your address -=> 151 Marie Lane Hello Joseph Proc tic Tools dress: 151 Marie Lane stics session: 16 seconds 10s Joseph, Please select the beverage you would like to purchase from the menu: Drink Menu 1Water $1.45 12 Soda $2.98 13 Iced Tea $3.29 1% of all processors) x - Exit 100 Your selection: 2 Selection: Soda, price per unit : 2.98 Enter quantity [1-100]: ary Events Memory Usage CPU Usage ow Events (0 of 0 ry Usage ke Snapshot 100 % Autos Narme dows Syskow54kernel32.dll'. Cannot fi dowsSysW016KernelBase.dll.. Cannot ndowsSyshOW 41msvcp14ad.dll'. Cannot f CSS115_IP3_JosephHoffman.exe (Win32): Loaded 'C:WindowsSysho64vcruntime14ed.dll'. Cann CSS115_IP3_JosephHoffman.exe' (Win32): Loaded 'C:Windows SyshOW64ucrtbased.dll'. Cannot f .exe (Win32): Autos Locals Watch 1 Call Stack Breakpoints Exception Settings Command Window Immediate Window Output Ln 1 Col 1 Ch 1 INS Add to Source Control dv) ENG 10:49 PM ^

Explanation / Answer

Hi.. I have added single lines of code to display the selection.

#include <iostream>

#include <string>

#include <iomanip>

#include <sstream> // stringstream

#include <cctype> // isalph, isdigit

class Customer {

const std::string custName, custAddress;

public:

void custInfo(std::ostream &) const

{

}

void custWelcome(std::ostream &) const

{

std::cout << " Hello " << custName << " Address: " << custAddress << std::endl;

}

std::string custValue() const

{

return custName;

}

Customer(const std::string &inputCustName, const std::string &inputCustAddress)

: custName(inputCustName), custAddress(inputCustAddress)

{

}

};

struct Beverage {

const std::string name;

double price;

void bevInfo(std::ostream &) const

{

std::cout << "Name" << name << " "

<< "Price" << "$" << price << " "

<< "Total" << "$" << std::endl;

}

void bevSelect(std::ostream &) const

{

std::cout << "Selection: " << name << ", price per unit: $" << price << std::endl;

}

Beverage(const std::string &bevName, double bevPrice)

: name(bevName), price(bevPrice)

{

}

};

const int AVAILABLE_PRODUCTS_COUNT = 3;

const Beverage AVAILABLE_PRODUCTS[AVAILABLE_PRODUCTS_COUNT] = {

Beverage("Water", 1.45), // Element 0

Beverage("Soda", 2.98), // Element 1

Beverage("Ice Tea", 3.29) // Element 2

};

typedef int Quantities[AVAILABLE_PRODUCTS_COUNT];

Quantities ordered = { 0 };

double totalCost(Quantities);

void orderSummary(Quantities);

char getCharFromUser(const std::string &prompt);

Customer getCustomerFromUser();

void displayMenu(const Customer &);

void loadProductQuantity(const Beverage &, Quantities);

void doneShowOrder(const Customer &, Quantities);

double totalCost(Quantities beverageCount)//Cost loop

{

double totalCost = 0;

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

totalCost += (beverageCount[i] * AVAILABLE_PRODUCTS[i].price);

}

return totalCost;

}

void loadProductQuantity(int beverageNumber, int quantity)

{

ordered[beverageNumber] = quantity;

}

void doneShowOrder(const Customer &, Quantities)

{

orderSummary(ordered);

}

void displayMenu(const Customer &prompt)

{

std::cout << std::endl << std::endl

<< prompt.custValue()

<< ", Please select the beverage you would like to purchase from the menu: "

<< std::endl;

std::cout << "Drink Menu" << std::endl;

std::cout << "========" << std::endl;

std::cout << "1 - Water $1.45" << std::endl;

std::cout << "2 - Soda $2.98" << std::endl;

std::cout << "3 - Iced Tea $3.29" << std::endl;

std::cout << "X - Exit " << std::endl << std::endl;

}

char getCharFromUser(const std::string &prompt)

{

char key;

std::cout << "Selection: ";

std::cin >> key;

return key;

}

Customer getCustomerFromUser()

{

std::string custName;

std::string custAddress;

std::cout << "Please enter your name ==> ";

std::getline(std::cin, custName);

std::cout << "Please enter your address ==> ";

std::getline(std::cin, custAddress);

return Customer(custName, custAddress);

}

int main(void) {

Customer patron = getCustomerFromUser();

patron.custWelcome(std::cout);

patron.custInfo(std::cout);

bool done = false;

while (!done) {

int amountOrdered = 0;

displayMenu(patron);

switch (getCharFromUser("Your selection: ")) {

case '1':
std::cout << "You selected water with unit price $1.45 ";
std::cout << "Please chose a quantiy: ";

std::cin >> amountOrdered;

loadProductQuantity(0, amountOrdered);

break;

case '2':
std::cout << "You selected Soda with unit price $2.98 ";
std::cout << "Please chose a quantiy: ";

std::cin >> amountOrdered;

loadProductQuantity(1, amountOrdered);

break;

case '3':
std::cout << "You selected Ice Tea with unit price $3.29 ";
std::cout << "Please chose a quantiy: ";

std::cin >> amountOrdered;

loadProductQuantity(2, amountOrdered);

break;

case 'X': case 'x':

done = true;

break;

default:

std::cout << "Invalid selection. Please try again";

std::cin.get();

// no break in the default case

}

}

doneShowOrder(patron, ordered);

std::cout << "Press any key to exit." << std::endl;

char blah;

std::cin >> blah;

return 0;

}

void orderSummary(Quantities ordered) {

std::cout << std::endl;

std::cout << "======= ORDER SUMMARY ====" << std::endl;

std::cout << "Items selected:" << std::endl;

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

// only show beverages that has at least one order

if (ordered[i] > 0) {

std::cout << " You selected: " << ordered[i] << " of " << AVAILABLE_PRODUCTS[i].name << std::endl;

}

}

std::cout << "Total cost: " << "$" << totalCost(ordered) << std::endl;

}

Output:

Please enter your name ==> Santhosh                                                                                   

Please enter your address ==> Hyd                                                                                     

                                                                                                                      

Hello Santhosh                                                                                                        

Address: Hyd                                                                                                          

                                                                                                                      

  

Santhosh, Please select the beverage you would like to purchase from the menu:                                        

Drink Menu                                                                                                            

========                                                                                                              

1 - Water $1.45                                                                                                       

2 - Soda $2.98                                                                                                        

3 - Iced Tea $3.29  

X - Exit                                                                                                              

                                                                                                                      

Selection: 1                                                                                                          

You selected water with unit price $1.45                                                                              

Please chose a quantiy: 2                                                                                             

  

Santhosh, Please select the beverage you would like to purchase from the menu:                                        

Drink Menu                                                                                                            

========                                                                                                              

1 - Water $1.45                                                                                                       

2 - Soda $2.98                                                                                                        

3 - Iced Tea $3.29  

X - Exit                                                                                                              

                                                                                                                      

Selection: X

======= ORDER SUMMARY ====   

Items selected:

  

You selected: 2 of Water   

Total cost: $2.9

Press any key to exit.

Please check it and let me know any issues. Thank you. All the best.

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