Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

1) In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting

1) 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 you write the remainder of the program.

Instructions

Ensure the source code file named BattingAverage.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 following batting averages: .299, .157, .242, .203, .198, .333, .270, .190. The minimum batting average should be .157, and the maximum batting average should be .333. The average should be .2365.

#include

#include

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 by user

double battingAverage;

// Use these variables to store the minimim and maximum values

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 to array

cout << "Enter a batting average: ";

cin >> battingAverage;

// Assign value to array

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

min = averages[0];

max = averages[0];

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

total = averages[0];

// Write a loop here to access array values starting with averages[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 an array to find an exact match to complete a partially prewritten C++ program. The program uses an array that contains valid names for 10 cities in Michigan. You ask the user to enter a city name; your program then searches the array for that city name. If it is not found, the program should print a message that informs the user the city name is not found in the list of valid cities in Michigan.

The file provided for this lab includes the input statements and the necessary variable declarations. You need to use a loop to examine all the items in the array and test for a match. You also need to set a flag if there is a match and then test the flag variable to determine if you should print the the Not a city in Michigan. message. Comments in the code tell you where to write your statements. You can use the previous Mail Order program as a guide.

Instructions

Ensure the provided code file named MichiganCities.cpp is open.

Study the prewritten code to make sure you understand it.

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

Write code that tests for a match.

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

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

// MichiganCities.cpp - This program prints a message for invalid cities in Michigan.

// Input: Interactive

// Output: Error message or nothing

#include

#include

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 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

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

#include

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions