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 this lab, you complete a partially prewritten C++ program that uses an array. The program...
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help...
Phone number lookup Design a program that has two parallel arrays: a string array named people...
Phone number lookup Design a program that has two parallel arrays: a string array named people that is initialized with the names of seven of your friends, and a string array named phoneNumbers that is initialized with your friends phone numbers. The program should allow the user to enter a persons name (or part of a persons name). it should then search for that person in the people array. If the person is found, it should get that persons phjone...
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...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints the number of integer values in the file. Your program's input will be a string with the name of the file. If the file does not exist, then the program must print: Error opening the file For example, given the following CSV file input1.csv: 1,10,20,30,40 The output of your program must be: 5 You can safely assume that the input file will be a...
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...
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...
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,...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly dividing by b. Each time a division is performed the remainder and quotient are saved. At each step, the dividend is the quotient from the preceding step; the divisor is always b. The algorithm stops when the quotient is 0. The number in the new base is the sequence of remainders in reverse order (the last one computed goes first; the first one goes...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT