(Computer-Assisted Instruction: Reducing Student Fatigue) One problem in CAI environ- ments is student fatigue. This can be reduced by varying the computer’s responses to hold the stu- dent’s attention. Modify the program of Exercise 5.56 so that various comments are displayed for each answer as follows:

Possible responses to a correct answer:
Very good!
Excellent!
Nice work!
Keep up the good work!
Possible responses to an incorrect answer:
No. Please try again.
Wrong. Try once more.
Don't give up!
No. Keep trying.
Use random-number generation to choose a number from 1 to 4 that will be used to select
one of the four appropriate responses to each correct or incorrect answer. Use a switch statement to
issue the responses.


```
// Help user practice multiplication.
#include
#include
#include
using namespace std;

int generateProblem(); // function prototype
void correctMessage(); // function prototype
void incorrectMessage(); // function prototype

int main()
{
int response = 0; // user response for product

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

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

// loop until sentinel value or correct response
while ( response != -1 && response != answer )
{
incorrectMessage();
cin >> response;
} // end while

// correct response
if ( response == answer )
correctMessage();
} // end while

cout << "That's all for now. Bye." << endl;
} // end main
// generates new product and displays prompt
int generateProblem()
{
int x = rand() % 10; // generate 1-digit random number
int y = rand() % 10; // generate 1-digit 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
```

Computer Science & Information Technology

You might also like to view...

It is necessary to use proper capitalization when entering natural language phrases in Outlook.

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

Computer Science & Information Technology

__________ refers to the use of electronics and software within a product.

A) ?TinyOS B) ?General purpose computer C) ?Embedded system ? D) ?Desktop system

Computer Science & Information Technology

With a(n) ________ document, the data can be displayed in a webpage, included in a Word document, analyzed in Excel, imported into a database, or imported into other programs

Fill in the blank(s) with correct word

Computer Science & Information Technology

Which of the following is not true about column headers in a table?

A) They should be in the first row. B) They should identify the contents of the columns. C) They should be equal in size to the subheading. D) They should be formatted differently than the text in the table.

Computer Science & Information Technology