C++ Help ASAP!! assignment detail: Complete the following in your code: *Provide
ID: 3729538 • Letter: C
Question
C++ Help ASAP!!
assignment detail:
Complete the following in your code:
*Provide a list of available products
*Ask the customer to select products and quantities
*Save the provided details in arrays
*Read from the arrays to print the order summary; that is, the products, quantities, and the total price for each product
*Calculate and print the total price for the order
Please look through my code and help where it is commented I am having a great deal of trouble with this assignment and I am out of time please assist. I changed it completely based on feedback I can also sent my original code if needed.
[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
{
std::cout << "Name" << custName << " "
"Address" << custAddress << " " << std::endl;
}
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),
Beverage("Soda", 2.98),
Beverage("Ice Tea", 3.29)
};
typedef int Quantities[AVAILABLE_PRODUCTS_COUNT];
double totalCost(Quantities);
void orderSummary(Quantities);
std::string getStringFromUser(const std::string &prompt);
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)//NOT SURE IF IT IS CORRECT
{
double totalCost = 0;
for (int i = 0; i < AVAILABLE_PRODUCTS_COUNT; i++) {
totalCost += (AVAILABLE_PRODUCTS_COUNT*AVAILABLE_PRODUCTS_COUNT);
}
return totalCost;
}
void loadProductQuantity(const Beverage &, Quantities)//NEED HELP FIGURING OUT WHAT DO DO
{
}
void doneShowOrder(const Customer &, Quantities)//NEED HELP FIGURING OUT WHAT DO DO
{
}
void displayMenu(const Customer &prompt)//NOT SURE IF IT IS CORRECT
{
std::cout << std::endl << std::endl
<< &prompt
<< ", 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;
}
void getStringFromUser(std::string &prompt)//NEED HELP FIGURING OUT WHAT DO DO
{
}
char getCharFromUser(std::string &prompt)//NEED HELP FIGURING OUT WHAT DO DO
{
}
Customer getCustomerFromUser()//NOT SURE IF IT IS CORRECT
{
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) {
Quantities ordered = { 0 };
Customer patron = getCustomerFromUser();
patron.custInfo(std::cout);
bool done = false;
while (!done) {
displayMenu(patron);
switch (getCharFromUser("Your selection: ")) {
case '1':
loadProductQuantity(AVAILABLE_PRODUCTS[0], ordered);
break;
case '2':
loadProductQuantity(AVAILABLE_PRODUCTS[1], ordered);
break;
case '3':
loadProductQuantity(AVAILABLE_PRODUCTS[2], ordered);
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);
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 selcted: " << std::endl;// print something for AVAILABLE_PRODUCTS[i] NOT SURE IF THIS IS CORRECT
}
}
}
[/code]
I need assistance with figuring this out. I am stuck If someone can review this code I would be very grateful It is due today and I am at a standstill.
Explanation / Answer
for (int i = 0; i < AVAILABLE_PRODUCTS_COUNT; i++) {
totalCost += (AVAILABLE_PRODUCTS_COUNT*AVAILABLE_PRODUCTS_COUNT);
}
// this loop is wrong. The logic which you have given here calculates the sum of the square of products which is not required. the logic should be rather
for (int i = 0; i < AVAILABLE_PRODUCTS_COUNT; i++) {
totalCost += (Quantities*Beverage.bevprice);
}
also.... the following loop are not required
void getStringFromUser(std::string &prompt)//NEED HELP FIGURING OUT WHAT DO DO
{
}
i do not see any particular significance of them. It is not required.
char getCharFromUser(std::string &prompt)//NEED HELP FIGURING OUT WHAT DO DO
{
}
for this function you have two options either remove this function and create a variable, take the input from user and use it in a contitional statement of the switch statement which is actually a better and simpler way. example
int key;
std::cout << enter the quantity of the product or press X if done;
std::cin>> key;
switch(key)
{...........}
Else, the other way would be to use your way and use the function. Example:
char getCharFromUser(std::string &prompt)
{
char key;
std:: cout << ENTER THE QUANTITY OF THE PRODUCT OR PRESS X TO EXIT;
std:: cin >> key;
return key
}
this would do the job.
for the below fuction
void loadProductQuantity(const Beverage &, Quantities)//NEED HELP FIGURING OUT WHAT DO DO
{
int Product;
Product= beverage * quantities;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.