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 #include #include #include #include #include #include using namespace std;

// Function prototypes

void split(const string&, char, vector&); void getMappings(map &); void quiz(map, int);

int main() {

const int NUM_QUESTIONS = 5; map capitals;

// 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& tokens) { }

//**************************************************************

// 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 &capitals) }

void quiz(map capitals, int numQuestions){}

* * *

*

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!