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

Answers

Answer 1

Answer:

Replace the comments with:

for(x = 0; x < NUM_CITIES; x++){

      if(inCity == citiesInMichigan[x]){           foundIt = true;}

  }

  if(foundIt){ cout<<"Exists";}

  else{cout<<"Does not exists";}  

 

Explanation:

This iterates through the cities

[tex]for(x = 0; x < NUM\_CITIES; x++)\{[/tex]

This checks if current city in the array matches the city input by the user

[tex]if(inCity == citie sIn Michigan[x])\{[/tex]           foundIt = true; If yes, foundIt is set to true}

  }

If foundIt is true, print "Exists"

if(foundIt){ cout<<"Exists";}

If foundIt is false, print "Does not Exists"

  else{cout<<"Does not exists";}  

See attachment for complete program


Related Questions

8. What's the output of this code?
1
def sum(x, y):
return(x+y)
print(sum (sum(1,2), sum(3,4)))

Answers

Answer:

10

Explanation:

[tex]sum(1,2) = 3\\sum(3,4) = 7\\sum(3,7) = 10\\[/tex]

Basically, sum((1+2) + (3+4)) = sum(3,7) = (3+7) = 10

Suppose a byte-addressable computer using set-associative cache has 2 16 bytes of main memory and a cache size of 32 blocks and each cache block contains 8 bytes. a) If this cache is 2-way set associative, what is the format of a memory address as seen by the cache; that is, what are the size of the tag, set, and offset fields

Answers

Answer:

Following are the responses to these question:

Explanation:

The cache size is 2n words whenever the address bit number is n then So, because cache size is 216 words, its number of address bits required for that  cache is 16 because the recollection is relational 2, there is 2 type for each set. Its cache has 32 blocks, so overall sets are as follows:

[tex]\text{Total Number of sets raluired}= \frac{\text{Number of blocks}}{Associativity}[/tex]

                                               [tex]=\frac{32}{2}\\\\ =16\\\\= 2^4 \ sets[/tex]

The set bits required also are 4. Therefore.

Every other block has 8 words, 23 words, so the field of the word requires 3 bits.

For both the tag field, the remaining portion bits are essential. The bytes in the tag field are calculated as follows:

Bits number in the field tag =Address Bits Total number-Set bits number number-Number of bits of words

=16-4-3

= 9 bit

The number of bits inside the individual fields is therefore as follows:

Tag field: 8 bits Tag field

Fieldset: 4 bits

Field Word:3 bits

Describe a problem you’ve solved or a problem you’d like to solve. It can be an intellectual challenge, a research query, an ethical dilemma — anything of personal importance, no matter the scale. Explain its significance to you and what steps you took or could be taken to identify a solution.

Answers

Answer:

Explanation:

I run an online e-commerce store and lately its been very difficult keeping track of customer detail, incoming orders, keyword generation etc. One solution that I thought about would be an application that controls all of that for me. In order to accomplish this I would first need to design and create a GUI that contains all of the necessary buttons and displays for the information. Then I would need to code a webscraper using Python to grab all of the data from e-commerce store as soon as it becomes available, organize it, and display it within the GUI.

10.11 LAB: Pet information (derived classes) The base class Pet has private data members petName, and petAge. The derived class Dog extends the Pet class and includes a private data member for dogBreed. Complete main() to: create a generic pet and print information using PrintInfo(). create a Dog pet, use PrintInfo() to print information, and add a statement to print the dog's breed using the GetBreed() function.

Answers

Answer:

Answered below.

Explanation:

//Program in Java

Class Test{

public static void main (String[] args){

//create a pet object

Pet pet = new Pet();

//call pet object's printInfo method

pet.printInfo();

//create a new Dog object

Dog dog = new Dog();

//dog can access the printInfo method of the Pet class because it derives from it

dog.printInfo();

//dog can also call it's private method.

dog.getBreed();

}

}

. Which responsibility belongs to the marketing function?

Answers

Answer:

The marketing functions involves various responsibilities of the business organization, these functions are responsible for the growth of company. The key roles and responsibilities of marketing functions are market research, finance, product development, communication, distribution, planning, promotion, selling etc.

Other Questions
Which line shown appears to have a Y-intercept of 3? A. IB. II C. III D. IV E. none of the above Rachel received a monthly raise of $105.25. If this represented a 5.5% increase, what is her monthly salary after the raise?A. $1,913.64B. $1,964.13. $2,018.89 D. $2.089.18 2 What is the correct way to write sentence 9?F)People feel safe when confiding in their pets;without being judgmental. A pet will often sitcompassionately by its owner's side for as longas is needed.G)People feel safe when confiding in their pets;without being judgmental, a pet will often sitcompassionately by its owner's side for as longas is needed.H)People feel safe when confiding in their pets.Without being judgmental, a pet will often sitcompassionately; by its owner's side, for as longas is needed.1) Let f(-x) = 5x 2 and g(x) = 2x + 3 and find f(x) f(0) 9(x) = 7x 1f(.2) 9(x) = 7x + 1f(x) 9(2) = 3x 5f(x) 9(x) = -3x +5 how many triangles can you make with two side lengths of 6 inches that meet at a 50 degree angle. How was life different from plantation to plantation? The coordinates of the vertices of triangle QRS are Q (1,-2), R (1,9),S (6,-4). What is the length, in units, of the line segment that connectsvertex Q to vertex R? Please look at picture The authors of a paper concluded that more boys than girls listen to music at high volumes. This conclusion was based on data from independent random samples of 768 boys and 745 girls from a country, age 12 to 19. Of the boys, 397 reported that they almost always listen to music at a high volume setting. Of the girls, 331 reported listening to music at a high volume setting.Do the sample data support the authors' conclusion that the proportion of the country's boys who listen to music at high volume is greater than this proportion for the country's girls? Test the relevant hypotheses using a 0.01 significance level. (Use a statistical computer package to calculate the P-value. Use boys girls. Round your test statistic to two decimal places and your P-value to four decimal places.) Which resource is renewable? im almost done with this hw. plz help!!! give explanation if you actually know the answer so ik u dont just want points What is the intermediate step in the form (x+a)^2=b(x+a) 2 =b as a result of completing the square for the following equation?6x^2+48x+207=15 Explain what he is watching based on what it says in the poem star spangled bannerHeres the poem..The Star-Spangled BannerO say can you see, by the dawns early light,What so proudly we haild at the twilights last gleaming,Whose broad stripes and bright stars through the perilous fightOer the ramparts we watchd were so gallantly streaming?And the rockets red glare, the bombs bursting in air,Gave proof through the night that our flag was still there,O say does that star-spangled banner yet waveOer the land of the free and the home of the brave?On the shore dimly seen through the mists of the deepWhere the foes haughty host in dread silence reposes,What is that which the breeze, oer the towering steep,As it fitfully blows, half conceals, half discloses?Now it catches the gleam of the mornings first beam,In full glory reflected now shines in the stream,Tis the star-spangled banner - O long may it waveOer the land of the free and the home of the brave!And where is that band who so vauntingly swore,That the havoc of war and the battles confusionA home and a Country should leave us no more?Their blood has washd out their foul footsteps pollution.No refuge could save the hireling and slaveFrom the terror of flight or the gloom of the grave,And the star-spangled banner in triumph doth waveOer the land of the free and the home of the brave.O thus be it ever when freemen shall standBetween their lovd home and the wars desolation!Blest with victry and peace may the heavn rescued landPraise the power that hath made and preservd us a nation!Then conquer we must, when our cause it is just,And this be our motto - In God is our trust, And the star-spangled banner in triumph shall waveOer the land of the free and the home of the brave. can someone help my lil sis again. Fossil fuels were made from organisms that lived long ago. True or false______. Because ___________ ZABD and ZDBC are supplementary angles.What is the measure of x?X = [?]7D110%AK>CC BAngles are not drawn to scale.Enter What did the ballet of the right of spring depict? Welcoming flowers and sun and spring time. Amphibians during spring and prehistoric times. An old Slovak legend. Ancient Pagan Russian peasant rights Two matchsticks have the same length as three bottle tops. How many bottle tops will have the same length as 50 matchsticks? For which reason is the executive branch considered the largest branch in the Georgia state government? A. due to the bicameral nature of the executive branch B. due to the large number of committees of which the branch is comprised C. due to the amount of cabinet-level positions in the branch D. due to the large number of state agencies under the branch's jurisdiction What is the main difference between the intertidal zone and the neritic zone?the amount of exposure to sunlightthe amount of salt in the waterthe amount of time covered by waterthe presence of plants and animals