Question
Chapter 17 Challenge 3 Page 1119 Write a program that creates a map of the U.S. states as keys, and their capitals as values. The
Chapter 17 Challenge 3 Page 1119 Write a program that creates a map of the U.S. states as keys, and their capitals as values.
The program should then randomly quiz the by displaying the name of a state and ask the user to enter the states capital. The program should keep a count of correct and incorrect responses.
Example:
// Capital Quiz
#include
// Function prototypes
void split(const string&, char, vector
int main() {
const int NUM_QUESTIONS = 5; map
// Build the map.
getMappings(capitals);
// Run the quiz.
quiz(capitals, NUM_QUESTIONS);
system("pause");
return 0; }
//************************************************************** // The split function splits s into tokens, using delim as the * // delimiter. The tokens are added to the tokens vector. * // (See Chapter 10 in your textbook for more information about * // this function.) * //************************************************************** void split(const string& s, char delim, vector
//**************************************************************
// The getMappings function reads the states and capitals // from a file named StateCapitals.txt and stores them as // key-value pairs in the capitals parameter, that is passed // by reference. //************************************************************** void getMappings(map
void quiz(map
* * *
*
Example output:
I'm going to ask you for the capitals of 5 states. What is the capital of Oklahoma? Oklahoma City Correct!
What is the capital of Pennsylvania? Helen Sorry, that's incorrect.
What is the capital of Arkansas? little Rock Sorry, that's incorrect.
What is the capital of Georgia? Atlanta Correct!
What is the capital of Vermont? Montpelier Correct!
=======================================
End of the quiz. Correct answers: 3 Incorrect answers: 2 =======================================
Press any key to continue . . .
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