Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions