Question

I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include...

I need a detailed pseudocode for this code in C ++. Thank you

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

struct Drink
{

   string name;

   double cost;

   int noOfDrinks;

};

void displayMenu(Drink drinks[], int n);

int main() {

   const int size = 5;
  
   Drink drinks[size] = { {"Cola", 0.65, 2},

   {"Root Beer", 0.70, 1},

   {"Grape Soda", 0.75, 5},

   {"Lemon-Lime", 0.85, 20},

   {"Water", 0.90, 20} };

   cout << setprecision(2) << fixed;

   int drink = -1;

   double amount, total_revenue = 0.0;

   displayMenu(drinks, size);

   while (drink <1 || drink > 6)
   {
       cout << "Invalid input. Please enter your choice again:";
       cin >> drink;
   }
   cout << "\nSelect a drink (1-5) or enter 6 to quit: ";

   cin >> drink;

   while (drink != 6) {
      

       cout << "Enter the amount of money you want to insert: ";

       cin >> amount;

       while (amount < 0 || amount > 1.00) {

           cout << "This machine cannot accept values less than 0 or greater than "

               "$1.00"

               << endl;

           cout << "Enter the amount of money you want to insert: ";

           cin >> amount;

       }

       if (amount < drinks[drink - 1].cost)

           cout << "Insufficient Funds" << endl;

       if (drinks[drink - 1].noOfDrinks == 0)

           cout << "SOLD OUT" << endl;


       else {

           drinks[drink - 1].noOfDrinks--;

           cout << "Change: $" << (amount - drinks[drink - 1].cost) << endl;

           total_revenue += drinks[drink - 1].cost;

       }

       displayMenu(drinks, size);

       cout << "\nSelect a drink (1-5) or enter 6 to quit: ";

       cin >> drink;


       }

       cout << "\nTotal Revenue: $" << total_revenue << endl;

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

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

               if (drinks[i].noOfDrinks > drinks[j].noOfDrinks) {

                   Drink temp = drinks[i];

                   drinks[i] = drinks[j];

                   drinks[j] = temp;

               }

           }

       }

       cout << "\nDrink\t\tNumber Left\n" << endl;

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

           cout << setw(15) << left << drinks[i].name << setw(2) << right << drinks[i].noOfDrinks << endl;

       }
  

   return 0;

}

void displayMenu(Drink drinks[], int n) {

   cout << endl;

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

       cout << (i + 1) << ") " << setw(15) << left << drinks[i].name << "$"

           << drinks[i].cost << "\t\t"

           << "Qty: " << setw(2) << right << drinks[i].noOfDrinks << endl;

   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi there !

Happy to answer this question for you.

The above Program is in c++ and we need pseudo code for that.

Pseudo code is an informal way to write algorithmic procedure for any problem.Point here to note that pseudo code only includes the iterations (loops i.e while,for in c++),conditional statements (if/else and switch cases in c++) , sequence of statements ( like variable assignments,etc ) . Usually we do not write any particular statements for structure and classes.

define 'Drink' datatype with datatype fields string 'name',     floating point 'cost' 'noOfdrinks'

main() size <- 5 constant initialize array drink as drinks[size] = { {"Cola", 0.65, 2},{"Root Beer", 0.70, 1},{"Grape Soda", 0.75, 5},{"Lemon-Lime", 0.85, 20},{"Water", 0.90, 20}}; set the precision for floating point numbers to 2 drink <- -1 (note that everywhere <- shows arrow pointing to left ) amount,total_revenue <- 0.0

displayMenu(drinks,size)

while drinks is less than 1 or greater than 6 do print  "Invalid input. Please enter your choice again:" and take input the drink again from user end

print in a new line "Select a drink (1-5) or enter 6 to quit: " and take input the drink again from user

while drink not equal to 6 do print "Enter the amount of money you want to insert: " and take input the amount from user

while amount is less than 0 or greater than 1.00 do print "This machine cannot accept values less than 0 or greater than $1.00 " print "Enter the amount of money you want to insert: " and take input the amount again from user end    if amount is less than drinks[drink - 1].cost    print "Insufficient Funds"     if drinks[drink - 1].noOfDrinks <- 0 print "SOLD OUT"
       else drinks[drink - 1].noOfDrinks <- drinks[drink - 1].noOfDrinks - 1 //( decrease )           print "Change: $ " (amount - drinks[drink - 1].cost) << endl    total_revenue <-drinks[drink - 1].cost + total_revenue

       displayMenu(drinks, size)     print "Select a drink (1-5) or enter 6 to quit: " and take input drink from user end (end of outer while loop)

in a new line print "Total Revenue: $" print  total_revenue

for i <- 0 to size-1 do for j <- i + 1 size-1 do if drinks[i].noOfDrinks is greater than drinks[j].noOfDrinks    Drink temp <- drinks[i] drinks[i] <- drinks[j] drinks[j] <- temp end end   

in a new line print "Drink" with two tab    print "Number Left"

       for i <- 0 to size-1 do   

          print drinks[i].name left side with size width of 15     print drinks[i].noOfDrinks right side with width of 2

end

end (end of main function)

displayMenu ( Drink drinks[],n ) in a new line for i <- 0 to n-1 print i+1 with ")" print drinks[i].name on left side setting width of 15 with "$" print drinks[i].cost with two tab characters and string "Qty:" print drinks[i].noOfdrinks on the right setting width of two with end of line

You should note that in pseudo codes there is no need to mention the white space characters and setw methods.But you mentioned that you need detailed solution , that'ts why i wrote those characters to make you understand properly along with the code.

I hope that it is clear to you !

For any ambiguity and faultness please comment !

Thank you !

Add a comment
Know the answer?
Add Answer to:
I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib>...

    The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...

  • How can I make this compatible with older C++ compilers that DO NOT make use of...

    How can I make this compatible with older C++ compilers that DO NOT make use of stoi and to_string? //Booking system #include <iostream> #include <iomanip> #include <string> using namespace std; string welcome(); void print_seats(string flight[]); void populate_seats(); bool validate_flight(string a); bool validate_seat(string a, int b); bool validate_book(string a); void print_ticket(string passenger[], int i); string flights [5][52]; string passengers [4][250]; int main(){     string seat, flight, book = "y";     int int_flight, p = 0, j = 0;     int seat_number,...

  • I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using...

    I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() {         cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl;      int numOfEmployees = NumOfEmployees();         TotDaysAbsent(numOfEmployees);    return 0; } int NumOfEmployees() {    int numOfEmployees = 0;     cout << "Please enter the number of employees in the company: ";         cin >> numOfEmployees;     while(numOfEmployees <= 0)     {            ...

  • I need help with this code: #include <iostream> #include <cstdlib> #include <string> using namespace std; void...

    I need help with this code: #include <iostream> #include <cstdlib> #include <string> using namespace std; void dump(int ar[], int size) { cout << "\nDUMP [ "; for (int i=0; i<=size; i++) { cout << ar[i] << " "; } cout << "]\n\n"; } void quicksort(int ar[], int start, int end) { cout << "TOP OF SORT ===========================" << endl; dump(ar, start, end); int pivot = ar[end]; int left = start; int right = end - 1; int tmp; cout <<...

  • 1. in this programe i want add some products to be shown after choosing choise (...

    1. in this programe i want add some products to be shown after choosing choise ( show all products ) before i add any products. let say 10 products have added to the program then when the user choose (show all products ) all the 10 products appear and the user going to choose one and that one must has its own name, price,and quantity after that the quantity will be reduce. 2. allow the user to buy products. ===========================================================...

  • Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem...

    Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME             UNIFORM#    AVEPPG Mary                   15     10.50 Jack                   72      8.10 Elizabeth              41      7.50 Joseph                 32      6.20 Vince                  83      4.20 ​ My Code: #include <iostream>...

  • my program wont run on my computer and im not understanding why. please help. #include<iostream> #include<iomanip>...

    my program wont run on my computer and im not understanding why. please help. #include<iostream> #include<iomanip> #include<string> #include "bookdata.h" #include "bookinfo.h" #include "invmenu.h" #include "reports.h" #include "cashier.h" using namespace std; const int ARRAYNUM = 20; BookData bookdata[ARRAYNUM]; int main () { bool userChoice = false; while(userChoice == false) { int userInput = 0; bool trueFalse = false; cout << "\n" << setw(45) << "Serendipity Booksellers\n" << setw(39) << "Main Menu\n\n" << "1.Cashier Module\n" << "2.Inventory Database Module\n" << "3.Report Module\n"...

  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • Need help with my ksmall program. I get an error saying segmentation dump. Thanks #include<iostream> using...

    Need help with my ksmall program. I get an error saying segmentation dump. Thanks #include<iostream> using namespace std; int ksmall(int*, int, int , int); void swap(int*, int*); int main() {     int SIZE = 10;     int target;     int begining=0;     int ending=SIZE-1;     int *array1= new int[SIZE];     cout << "Enter 10 integers: " << endl;     for (int i=0; i<SIZE; i++)     {        cin>>array1[i];     }     cout << " What is the Kth smallest number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT