// MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing
// MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
// MichiganCities.cpp - This program prints a message for invalid 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()
![**Title:** Searching an Array for an Exact Match in C++
---
**Summary**
In this lab, you will apply your knowledge of searching an array to find an exact match. The goal is to complete a partially prewritten C++ program. This program utilizes an array containing names of 10 cities in Michigan. You’ll prompt the user to input a city name, and the program will search the array for an exact match. If the city is not found, the program will display a message indicating that the city name isn't in the list of valid cities in Michigan.
The provided file includes input statements and necessary variable declarations. Your task is to use a loop to review all array items and determine a match. You'll also set a flag to indicate if a match occurs, which will help decide if the message "Not a city in Michigan" should be displayed. Comments in the code provide guidance on where to insert your statements. You can refer to the previous Mail Order program as a guide.
**Instructions**
0. Ensure the code file named `MichiganCities.cpp` is open.
1. Study the prewritten code to ensure understanding.
2. Write a loop statement that examines the names... (incomplete text)
---
The image shows a C++ code snippet next to the lab description, with parts of the code visible alongside the instructions. The code is set up with headers and a main function designed to handle the city name input and validation.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4bfbb203-4399-4804-a6b8-bbfebafe4401%2F88fc85f1-b2ac-4fa0-8a58-2a8cbdc26918%2F8hslgrn_processed.jpeg&w=3840&q=75)
Transcribed Image Text:**Title:** Searching an Array for an Exact Match in C++
---
**Summary**
In this lab, you will apply your knowledge of searching an array to find an exact match. The goal is to complete a partially prewritten C++ program. This program utilizes an array containing names of 10 cities in Michigan. You’ll prompt the user to input a city name, and the program will search the array for an exact match. If the city is not found, the program will display a message indicating that the city name isn't in the list of valid cities in Michigan.
The provided file includes input statements and necessary variable declarations. Your task is to use a loop to review all array items and determine a match. You'll also set a flag to indicate if a match occurs, which will help decide if the message "Not a city in Michigan" should be displayed. Comments in the code provide guidance on where to insert your statements. You can refer to the previous Mail Order program as a guide.
**Instructions**
0. Ensure the code file named `MichiganCities.cpp` is open.
1. Study the prewritten code to ensure understanding.
2. Write a loop statement that examines the names... (incomplete text)
---
The image shows a C++ code snippet next to the lab description, with parts of the code visible alongside the instructions. The code is set up with headers and a main function designed to handle the city name input and validation.
![# Searching an Array for an Exact Match
This guide will help you search through an array in C++ for an exact match. You'll use the provided code file `MichiganCities.cpp` to find whether a city name is in Michigan.
## Instructions
0. **Ensure the provided code file named `MichiganCities.cpp` is open.**
1. **Study the prewritten code to make sure you understand it.**
2. **Write a loop statement that examines the names of cities stored in the array.**
3. **Write code that tests for a match.**
4. **Write code that, when appropriate, prints the message `Not a city in Michigan`.**
5. **Execute the program by clicking the Run button at the bottom of the screen. Use the following as input:**
- Chicago
- Brooklyn
- Watervliet
- Acme
## Grading
When you have completed your program, click the Submit button to record your score.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4bfbb203-4399-4804-a6b8-bbfebafe4401%2F88fc85f1-b2ac-4fa0-8a58-2a8cbdc26918%2Faonqj3q_processed.jpeg&w=3840&q=75)
Transcribed Image Text:# Searching an Array for an Exact Match
This guide will help you search through an array in C++ for an exact match. You'll use the provided code file `MichiganCities.cpp` to find whether a city name is in Michigan.
## Instructions
0. **Ensure the provided code file named `MichiganCities.cpp` is open.**
1. **Study the prewritten code to make sure you understand it.**
2. **Write a loop statement that examines the names of cities stored in the array.**
3. **Write code that tests for a match.**
4. **Write code that, when appropriate, prints the message `Not a city in Michigan`.**
5. **Execute the program by clicking the Run button at the bottom of the screen. Use the following as input:**
- Chicago
- Brooklyn
- Watervliet
- Acme
## Grading
When you have completed your program, click the Submit button to record your score.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education