Question

In: Computer Science

Parallel Arrays This question is in MindTap Cengage Summary In this lab, you use what you...

Parallel Arrays

This question is in MindTap Cengage

Summary

In 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

Study the prewritten code to make sure you understand it.

Write the code that searches the array for the name of the add-in ordered by the customer.

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.

Execute the program by clicking the "Run Code" button at the bottom of the screen. Use the following data:

Cream

Caramel

Whiskey

chocolate

Chocolate

Cinnamon

Vanilla

-----------------------------

This is what i have so far:

// 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
   int findItem();
   // Get user input
   cout << "Enter coffee add-in or XXX to quit: ";
   cin >> addIn;
  
   // Write the rest of the program here.
    findItem();
        foundIt = false
        x = 0
        while(x < NUM_ITEMS)
            if addIn = addIns[x]
                foundIt = true
                orderTotal = addInPrices[x]
            endif
            x = x + 1
        endwhile
        if(foundIt = true)
        {
            cout << "The price of" << addIns[x] << "is" << addInPrices[x] << "." << endl;
        }
        else
        {
            cout << "Sorry, we do not carry that." << endl;
        }
   return 0;
} // End of main()

Solutions

Expert Solution

Please look at my code and in case of indentation issues check the screenshots.

------------JumpinJava.cpp----------------

// 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.
   while(addIn != "XXX")   //loop until user enters XXX
   {
       bool foundIt = false;   //before searching intializes foundIt as False
       x = 0;
       while (x < NUM_ITEMS){   //search the array for the addIn user entered
           if (addIn == addIns[x]){
               foundIt = true;           //if match is found
               orderTotal = orderTotal + addInPrices[x];   //add price of the item to the total
               cout << "The price of " << addIns[x] << " is " << addInPrices[x] << "." << endl;   //price item name, price
           }
           x++;
       }
       if(!foundIt){       //if item not found
           cout << "Sorry, we do not carry that." << endl;
       }
       cout << "Enter coffee add-in or XXX to quit: ";   //read next item
       cin >> addIn;
   }
   cout << "Order total: " << orderTotal << endl;   //print order total
   cout << "Bye!" << endl;
   return 0;
}   // End of main()

--------------Screenshots-------------------

------------Output----------------------

------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.

Thankyou


Related Solutions

You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with //comments . Please include a screen shot of the output Part 4: Calorie Counting Specifications: Write a program that allows the user to enter the number of calories consumed per day. Store these calories in an integer vector. The user should be prompted to enter the calories over the course of one week (7 days). Your program should display the total calories consumed over...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with //comments . Please include a screen shot of the output Part 1: Largest and Smallest Vector Values Specifications: Write a program that generates 10 random integers between 50 and 100 (inclusive) and puts them into a vector. The program should display the largest and smallest values stored in the vector. Create 3 functions in addition to your main function. One function should generate the...
Searching an Array for an Exact Match in Java Summary In this lab, you use what...
Searching an Array for an Exact Match in Java Summary In this lab, you use what you have learned about searching an array to find an exact match to complete a partially prewritten Java program. The program uses an array that contains valid names for 10 cities in Michigan. You ask the user of the program to enter a city name; your program then searches the array for that city name. If it is not found, the program should print...
Objectives In this lab you will review passing arrays to methods and partially filled arrays. Requirements...
Objectives In this lab you will review passing arrays to methods and partially filled arrays. Requirements 1. Fill an array with data from an input file sampledata-io.txt (Attached) a. Assume no more than 100 data items, terminated by -1 for sentinel b. Note that the sample data file has other information after the sentinel; it should cause no problem c. Read and store data d. Print the number of data stored in the array e. Add a method to reverse...
1) a) Give short code example of parallel arrays. b) Explain how parallel arrays work. 2)...
1) a) Give short code example of parallel arrays. b) Explain how parallel arrays work. 2) a) How would you compare two arrays to check if they have the same values? b) Assume array1 and array2 are int arrays with 10 elements in each. if(array1 == array2) What is this comparing? 3 a) Can you encounter memory violation using an array? b) If yes explain. If no, explain why not.
MATLAB NEEDED. This lab will use functions and arrays.   The task within is to Add, Sub,...
MATLAB NEEDED. This lab will use functions and arrays.   The task within is to Add, Sub, or Multiply 2 Matrix. See Manipulate Matrix doc for the methods. My reference to matrix below is because we are doing matrix math. The matrix are arrays. Matlab built-in functions not allowed You will write 3 functions (call those functions): 1. ADD two matrix,   2. SUBTRACT two matrix, and 3. MULTIPLY two matrix. Requirements: Write the script to cycle until user chooses to stop....
Read and print parallel array - How can this be made to read parallel arrays and...
Read and print parallel array - How can this be made to read parallel arrays and then print them? The program presented here is intended to read from the text file and build parallel arrays. Then it will print as shown. The first line will not be stored in the array. The second line will be stored in firstArray[] and the third line will then be stored in secondArray[] and the arrays will repeat until the file is read. begin...
Summary In this lab, you use a counter-controlled while loop in a Java program provided for...
Summary In this lab, you use a counter-controlled while loop in a Java program provided for you. When completed, the program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. The data file contains the necessary variable declarations and some output statements. Instructions Ensure the file named Multiply.java is open. Write a counter-controlled while loop that uses the loop control variable to take on the values 0 through 10. Remember to initialize...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to hold 5 items in each In the main(), load the arrays with data Then output the entire contents of the arrays Create a method called find1() and pass the 2 arrays to that method. problem 2 In the find1() method, ask the user to enter a value to search for Write logic to search the first array and then output the related data from...
Question: What is the significance of a lab value's half-life? How would you use that information...
Question: What is the significance of a lab value's half-life? How would you use that information to assess the lab value? For example, albumin has a half life of 18-21 days, can someone explain the significance of this and how I would use that information to assess the lab value?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT