(Solved) : 1 Lab Complete Partially Prewritten C Program Uses Array Program Prompts User Interactivel Q26169308 . . .

1) In this lab, you complete a partially prewritten C++ programthat uses an array.

The program prompts the user to interactively enter eightbatting averages, which the program stores in an array. The programshould then find the minimum and maximum batting average stored inthe array as well as the average of the eight batting averages. Thedata file provided for this lab includes the input statement andsome variable declarations. Comments are included in the file tohelp you write the remainder of the program.

Instructions

Ensure the source code file namedBattingAverage.cpp is open in the code editor.

Write the C++ statements as indicated by the comments.

Execute the program by clicking “Run Code.” Enter the followingbatting averages: .299, .157,.242, .203,.198, .333,.270, .190. The minimum battingaverage should be .157, and the maximum batting average should be.333. The average should be .2365.

#include <iostream>

#include <string>

using namespace std;

int main()

{

// Declare a named constant for array size here

// Declare array here

// Use this integer variable as your loop index

int loopIndex;

// Use this variable to store the batting average input byuser

double battingAverage;

// Use these variables to store the minimim and maximumvalues

double min, max;

// Use these variables to store the total and the average

double total, average;

// Write a loop to get batting averages from user and assign toarray

cout << “Enter a batting average: “;

cin >> battingAverage;

// Assign value to array

// Assign the first element in the array to be the minimum andthe maximum

min = averages[0];

max = averages[0];

// Start out your total with the value of the first element inthe array

total = averages[0];

// Write a loop here to access array values starting withaverages[1]

// Within the loop test for minimum and maximum averages.

// Also accumulate a total of all averages

// Calculate the average of the 8 batting averages

// Print the batting averages stored in the averages array

// Print the maximum batting average, minimum batting average,and average batting average

return 0;

}

2)

In this lab, you use what you have learned about searching anarray to find an exact match to complete a partially prewritten C++program. The program uses an array that contains valid names for 10cities in Michigan. You ask the user to enter a city name; yourprogram then searches the array for that city name. If it is notfound, the program should print a message that informs the user thecity name is not found in the list of valid cities in Michigan.

The file provided for this lab includes the input statements andthe necessary variable declarations. You need to use a loop toexamine all the items in the array and test for a match. You alsoneed to set a flag if there is a match and then test the flagvariable to determine if you should print the the Not a city inMichigan. message. Comments in the code tell you where to writeyour statements. You can use the previous Mail Order program as aguide.

Instructions

Ensure the provided code file namedMichiganCities.cpp is open.

Study the prewritten code to make sure you understand it.

Write a loop statement that examines the names of cities storedin the array.

Write code that tests for a match.

Write code that, when appropriate, prints the message Not a cityin Michigan..

Execute the program by clicking the “Run Code” button at thebottom of the screen. Use the following as input:
Chicago
Brooklyn
Watervliet
Acme

// MichiganCities.cpp – This program prints a message forinvalid cities in Michigan.

// Input: Interactive

// Output: Error message or nothing

#include <iostream>

#include <string>

using namespace std;

int main()

{

// Declare variables

string inCity; // name of city to look up in array

const int NUM_CITIES = 10;

// Initialized array of cities

string citiesInMichigan[] = {“Acme”, “Albion”, “Detroit”,”Watervliet”, “Coloma”, “Saginaw”, “Richland”, “Glenn”, “Midland”,”Brooklyn”};

bool foundIt = false; // Flag variable

int x; // Loop control variable

// Get user input

cout << “Enter name of city: “;

cin >> inCity;

// Write your loop here

// Write your test statement here to see if there is

// a match. Set the flag to true if city is found.

// Test to see if city was not found to determine if

// “Not a city in Michigan” message should be printed.

return 0;

} // End of main()

3)

In this lab, you use what you have learned about parallel arraysto complete a partially completed C++ program. The programshould:

Either print the name and price for a coffee add-in from theJumpin’ Jive Coffee Shop

Or it should print the message Sorry, we do not carry that.

Read the problem description carefully before you begin. Thefile provided for this lab includes the necessary variabledeclarations and input statements. You need to write the part ofthe program that searches for the name of the coffee add-in(s) andeither prints the name and price of the add-in or prints the errormessage if the add-in is not found. Comments in the code tell youwhere 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 theadd-in ordered by the customer.

Write the code that prints the name and price of the add-in orthe error message, and then write the code that prints the cost ofthe total order.

Execute the program by clicking the “Run Code” button at thebottom of the screen. Use the following data:

Cream

Caramel

Whiskey

chocolate

Chocolate

Cinnamon

Vanilla

// JumpinJava.cpp – This program looks up and prints the namesand prices of coffee orders.

// Input: Interactive

// Output: Name and price of coffee orders or error message ifadd-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.00charge

// 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()

 

Expert Answer


. . .