Question
You've been hired by Utterly Urban to write a C++ console application that prompts the user for city names and writes them to file Cities.txt.
You've been hired by Utterly Urban to write a C++ console application that prompts the user for city names and writes them to file Cities.txt. The file will contain one city per line. It does not have a header line, only detail lines. The file will be written to the default folder of your development tool unless you specify a path to the file. In the app, attempt to create (open) the file. If it doesn't open, print an error message. If it does open, print a file-reading message. Use a sentinel loop to continue prompting the user for city names until they enter the sentinel value (of your choosing). If the sentinel value wasn't entered, prompt for and get from the user a city name and write it to one line of the file. Track the number of cities written and print the count after the loop. Define a constant for the output file name. See sample app TextFileOutput.cpp on Canvas. The output should look like this:
Welcome to Utterly Urban
------------------------
Writing lines to file 'Cities.txt' ...
Enter another city (y/n)? y
Enter a city (no spaces): Trenton
Enter another city (y/n)? y
Enter a city (no spaces): Riverview
Enter another city (y/n)? n
2 cities written to file 'Cities.txt'.
End of Utterly Urban
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started