Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Searching an Array for an Exact Match in C++ Searching an Array for an Exact Match Summary In this lab, you use what you have

Searching an Array for an Exact Match in C++

Searching an Array for an Exact Match

Summary

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 button at the bottom of the screen. Use the following as input: Chicago Brooklyn Watervliet Acme

Program runs correctly

4

0 out of 4 checks passed. Review the results below for more details.

Checks

Test CaseIncomplete

Test for Chicago; invalid input

Input

Chicago 

Output

Enter name of city: Chicago Not a city in Michigan 

Results

Not a city in Michigan.

Show DetailsTest CaseIncomplete

Test for Acme

Input

Acme 

Output

Enter name of city: Acme City found in Michigan 

Results

City found.

Show DetailsTest CaseIncomplete

Test for Watervliet

Input

Watervliet 

Output

Enter name of city: Watervliet City found in Michigan 

Results

City found.

Show DetailsTest CaseIncomplete

Test for Brooklyn

Input

Brooklyn 

Output

Enter name of city: Brooklyn City found in Michigan 

Results

City found.

Show Details

image text in transcribed

Searching an Array for an Exact Match in C++

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

Was there an effort to involve the appropriate people?

Answered: 1 week ago

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago