Question

n this lab, you use what you have learned about parallel arrays to complete a partially...

n this lab, you use what you have learned about parallel arrays to complete a partially completed C++ program. The program should:

  • Either print the name and price for a coffee add-in from the Jumpin’ Jive Coffee Shop
  • Or it should print the message Sorry, we do not carry that.

Read the problem description carefully before you begin. The file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the program that searches for the name of the coffee add-in(s) and either prints the name and price of the add-in or prints the error message if the add-in is not found. Comments in the code tell you where to write your statements.

Instructions

  1. Study the prewritten code to make sure you understand it.
  2. Write the code that searches the array for the name of the add-in ordered by the customer.
  3. Write the code that prints the name and price of the add-in or the error message, and then write the code that prints the cost of the total order.
  4. Execute the program by clicking the Run button at the bottom of the screen. Use the following data:

    Cream

    Caramel

    Whiskey

    chocolate

    Chocolate

    Cinnamon

    Vanilla

GIVEN CODE

// JumpinJava.cpp - This program looks up and prints the names and prices of coffee orders.  

// Input:  Interactive

// Output:  Name and price of coffee orders or error message if add-in is not found

#include <iostream>

#include <string>

using namespace std;

int main()

{

   // Declare variables.

   string addIn;     // Add-in ordered

   const int NUM_ITEMS = 5; // Named constant

   // Initialized array of add-ins

   string addIns[] = {"Cream", "Cinnamon", "Chocolate", "Amaretto", "Whiskey"};

   // Initialized array of add-in prices

   double addInPrices[] = {.89, .25, .59, 1.50, 1.75};

   bool foundIt = false;     // Flag variable

   int x;            // Loop control variable

   double orderTotal = 2.00; // All orders start with a 2.00 charge

   // Get user input

   cout << "Enter coffee add-in or XXX to quit: ";

   cin >> addIn;

    

   // Write the rest of the program here.

   return 0;

} // End of main()

Homework Answers

Answer #1

#include <iostream>

#include <string>

using namespace std;

int main()

{

// Declare variables.
  
string addIn; // Add-in ordered
  
const int NUM_ITEMS = 5; // Named constant
  
// Initialized array of add-ins
  
string addIns[] = {"Cream", "Cinnamon", "Chocolate", "Amaretto", "Whiskey"};
  
// Initialized array of add-in prices
  
double addInPrices[] = {.89, .25, .59, 1.50, 1.75};
  
int x; // Loop control variable
double orderTotal = 2.00; // All orders start with a 2.00 charge
  
double total=0;
  
while(addIn!="XXX"){// loop till XXX is not entered
bool foundIt = false; // Flag variable
// Get user input
cout << "Enter coffee add-in or XXX to quit: ";
cin >> addIn;
if(addIn=="XXX"){// if XXX is entered then break
break;
}
for(x=0;x<NUM_ITEMS;x++){// traverse the array
if(addIns[x]==addIn){// if add-in found in array
cout<<"Name of coffee add-in: "<<addIn<<", price: "<<addInPrices[x]<<endl;// print name,price
foundIt=true;
total+=addInPrices[x];// add cost of add-in to total order
break;
}
}
if(foundIt==false){// if add-in not found
cout<<"Sorry, we do not carry that."<<endl;
}
}

cout<<"Cost of total order: "<<total; // print cost of total order

  
return 0;

} // End of main()

Know the answer?
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
Similar Questions
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
C# Lab 7A: Thank you, Grace Hopper. You may have heard the story, but the programming...
C# Lab 7A: Thank you, Grace Hopper. You may have heard the story, but the programming term “bug” is attributed to the computer legend Grace Hopper who, after diagnosing the problem with a program, determined it was because a bug (in this case, a moth) physically wedged itself under a vacuum tube – causing the machine to no longer work. We’ve come a long way since then... For this part of the lab, you are going to write a program,...
Part 1 - LIST Create an unsorted LIST class ( You should already have this code...
Part 1 - LIST Create an unsorted LIST class ( You should already have this code from a prior assignment ). Each list should be able to store 100 names. Part 2 - Create a Class ArrayListClass It will contain an array of 27 "list" classes. Next, create a Class in which is composed a array of 27 list classes. Ignore index 0... Indexes 1...26 correspond to the first letter of a Last name. Again - ignore index 0. index...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
WITH JAVA Follow the instructions in the attached to complete Task#2 and submit work along with...
WITH JAVA Follow the instructions in the attached to complete Task#2 and submit work along with screenshots of your output. I have attached the class code for Task#1 that you can use while completing Task#2. Task#1 CODE /** SocSecException exception class */ public class SocSecException extends Exception { public SocSecException(String error) { super("Invalid the social security number, " + error); } } Task #2 Writing Code to Handle an Exception 1. In the main method: a. The main method should...
TrackMinMax For this lab, you will create a generic version of the IntTrackMinMax class you wrote...
TrackMinMax For this lab, you will create a generic version of the IntTrackMinMax class you wrote in a previous lab, called TrackMinMax. The API is: Function Signature Description constructor TrackMinMax() constructor check void check(T i) compares i to the current minimum and maximum values and updates them accordingly getMin T getMin() returns the minimum value provided to check() so far getMax T getMax() returns the maximum value provided to check() so far toString String toString() returns the string "[min,max]" As...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
The code I have written runs but I need it us UDP not TCP. Also I...
The code I have written runs but I need it us UDP not TCP. Also I just need someone to check my work and make sure that it works properly. The python code needs to be run with command line so you can add more than one client. The directions: 1. The chat is performed between 2 clients and not the server. 2. The server will first start up and choose a port number. Then the server prints out its...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will be filled with Car objects. It will call the displayMenu method to display the menu. Use a sentinel-controlled loop to read the user’s choice from stdin, call the appropriate method based on their choice, and redisplay the menu by calling displayMenu. Be sure to use the most appropriate statement for this type of repetition. displayMenu Parameters:             none Return value:          none Be sure to use...