(Computer-Assisted Instruction: Difficulty Levels) Exercise 5.56 through Exercise 5.58 de- veloped a computer-assisted instruction program to help teach an elementary school student multi- plication. Modify the program to allow the user to enter a difficulty level. At a difficulty level of 1, the program should use only single-digit numbers in the problems; at a difficulty level of 2, numbers as large as two digits, and so on.

What will be an ideal response?


```
// Help user practice multiplication according to grade level;
// check user's progress every 10 responses.
#include
#include
#include
#include
using namespace std;

int generateProblem( int ); // function prototype
void correctMessage(); // function prototype
void incorrectMessage(); // function prototype
bool checkDone( int, int ); // function prototype

int main()
{
int response = 0; // user response for product
int correct = 0; // total number of correct responses
int incorrect = 0; // total number of incorrect responses
int level; // difficulty level

cout << "Enter difficulty level: ";
cin >> level;

srand( time( 0 ) ); // seed random number generator

// loop until sentinel value read from user
while ( response != -1 )
{
int answer = generateProblem( level ); // get product
cin >> response; // read user's guess

// loop until sentinel value or correct response
while ( response != -1 && response != answer )
{
++incorrect; // update total number of incorrect responses

if ( checkDone( correct, incorrect ) ) // check progress
{
// done 10 responses; reset for next person
correct = incorrect = 0;
break;
} // end if

incorrectMessage();
cin >> response;
} // end while
// correct response
if ( response == answer )
{
++correct; // update total number of correct responses

if ( checkDone( correct, incorrect ) ) // check progress
{
// done 10 responses; reset for next person
correct = incorrect = 0;
continue;
} // end if

correctMessage();
} // end if
} // end while

cout << "That's all for now. Bye." << endl;
} // end main

// generates new product and displays prompt
int generateProblem( int level )
{
// maximum value for a particular level
int max = static_cast< int >( pow( 10.0, level ) );
int x = rand() % max; // generate random number
int y = rand() % max; // generate random number

cout << "How much is " << x << " times " << y << " (-1 to End)\n? ";

return x * y; // return product
} // end function generateProblem

// correctMessage randomly chooses response to correct answer
void correctMessage()
{
// generate random number between 0 and 3
switch ( rand() % 4 )
{
case 0:
cout << "Very good!";
break;
case 1:
cout << "Excellent!";
break;
case 2:
cout << "Nice work!";
break;
case 3:
cout << "Keep up the good work!";
break;
} // end switch

cout << endl << endl;
} // end function correctMessage
// incorrectMessage randomly chooses response to incorrect answer
void incorrectMessage()
{
// generate random number between 0 and 3
switch ( rand() % 4 )
{
case 0:
cout << "No. Please try again.";
break;
case 1:
cout << "Wrong. Try once more.";
break;
case 2:
cout << "Don't give up!";
break;
case 3:
cout << "No. Keep trying.";
break;
} // end switch

cout << endl << "? ";
} // end function incorrectMessage

// based on number of correct and incorrect, print
// result and return true if student's turn is over
bool checkDone( int right, int wrong )
{
// if we've reached a total of 10 responses
if ( right + wrong == 10 )
{
// check whether student got 75% correct or not
if ( static_cast< double >( right ) / ( right + wrong ) < .75 )
cout << "Please ask your teacher for extra help.\n\n";
else
cout << "Congratulations, you are ready to go "
<< "to the next level!\n\n";

return true;
} // end if

return false;
} // end function checkDone
```

Computer Science & Information Technology

You might also like to view...

____________________ was the first version of Windows to use a registry, though it was not the source of all its system settings.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

What type of DNS configuration prevents internal zone information from being stored on an Internet-accessible server?

A. read-only zone B. anti-phishing DNS C. caching DNS zone D. split-DNS architecture

Computer Science & Information Technology

UNIX and Linux support file systems compatible with Windows operating systems.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

The ________ is a field property of the table that can be used to limit the values that can be typed into a specific field

A) Primary Key B) Validation Rule C) Field Size D) Required

Computer Science & Information Technology