0% found this document useful (0 votes)
47 views

Week 8 Lab

This lab aims to develop a multiplication quiz program using pseudocode and C++. Students are asked to write the necessary variable declarations, code to get user input and repeat the quiz, generate random numbers, check answers and update scores, and convert the paper code to a full C++ program. The program will ask multiplication questions, track the number answered and score, and repeat until the user wants to quit.

Uploaded by

Muhammad Niazi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Week 8 Lab

This lab aims to develop a multiplication quiz program using pseudocode and C++. Students are asked to write the necessary variable declarations, code to get user input and repeat the quiz, generate random numbers, check answers and update scores, and convert the paper code to a full C++ program. The program will ask multiplication questions, track the number answered and score, and repeat until the user wants to quit.

Uploaded by

Muhammad Niazi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS111: Introduction to Computing Science

Lab Week 8
Objective of this lab exercise
1. Using pseudo code
2. Random numbers
3. While loops
4. Using Simple ifs

Before you begin:


  Review last week’s lab.
 Also review week’s 6 and 7’s lectures on simple if, multiple and nested ifs., and loops.

IMPORTANT NOTE
THIS LAB IS A PAPER EXERCISE. THIS MEANS THAT ALL YOUR
ANSWERS HAVE TO BE PREPARED AS HAND WRITTEN NOTES ON
PAPER. FOR THIS LAB YOU SHOULD NOT USE AN IDE.

The purpose of this lab is to develop a program that lets students test their
knowledge of multiplication tables. The program should ask random questions on
multiplying numbers from 1 to 10. It should check the answers and keep the
score. This is the pseudo code of the program.
print welcome message

ask if user wants to answer a question on multiplication or


whether to quit?

repeat the following as long as the answer is 'y' or not 'q'


increment the number of tries
choose number1 randomly between 1 and
10 choose number2 randomly between 1
and 10 compute the expected answer ask
what number1 * number2 is
if the answer is the expected
answer print "well done"
add 1 to the score
otherwise
tell the user what the answer should have been. ask
user if he/she wants to answer another question?
end of the loop

print the score


The purpose of this lab is to develop the final program from the pseudo code step
by step. It will ask you to provide a line of code, or a few lines of code for each line
in the pseudo code.
A screen shot of a working program might look like this:

**************************************************
* CS111 Math tutor *
**************************************************

Do you want to answer a question on multiplication?


Type 'y' for "Yes" and 'Q' to quit: y

What is 7 * 4? 28
Well done.

Do you want to answer a question on multiplication?


Type 'y' for "Yes" and 'Q' to quit: y

What is 9 * 3? 18
Sorry. The answer should have been: 27

Do you want to answer a question on multiplication?


Type 'y' for "Yes" and 'Q' to quit: y

What is 6 * 5? 30
Well done.

Do you want to answer a question on multiplication?


Type 'y' for "Yes" and 'Q' to quit: Q

You answered 2 of 3 questions correctly.

Exercise 1 [1 mark]

For this program you need the following variables.


• A variable of type char to store the answer to the question: Do you want to answer
a question on multiplication?
• A variable of type int to store the answer to the multiplication question.
• A variable of type int to store the expected answer to the multiplication question.
• A variable of type int to store the first random number between 1 and 10.
• A variable of type int to store the second random number between 1 and 10.
• A variable of type int to store the number of questions answered. It is initially 0.
• A variable of type int to store the number of correctly answered questions. It is initially 0.
Task:
Write (on paper) the necessary variable declarations.
Exercise 2 [1 mark]

Write code (on paper) for the following pseudo code:

ask if user wants to answer a question on multiplication or


whether to quit?

repeat the following as long as the answer is 'y' or not 'q'

ask user if he/she wants to answer another question?


end of the loop

Exercise 3 [1 mark]

Please write code (on paper) for the following pseudo code:

choose number1 randomly between 1 and


10 choose number2 randomly between 1
and 10 compute the expected answer

What are the definitions of the additional constant that you need?
Exercise 4 [1 mark]

Please write code (on paper) for the following pseudo code:

if the answer is the expected


answer print "well done"
add 1 to the score
otherwise
tell the user what the answer should have been.
Exercise 5 [1 mark]

Please write code (on paper) for the complete pseudo code on page 1.
Take into account the following:
• Make sure that your code is properly indented.
• Make sure that you haven't forgotten semicolons at the end of statements.
• Make sure that you use the proper Boolean operations and comparisons
• Use brackets.
• Use good variable names.
• Make sure that you do not have undeclared variables.
• Make sure that you do not read uninitialized variables.
• Set the seed of the random generator.

Exercise 6 [1 mark] (Optional Exercise)

Convert all the paper based code that you have written into a fully functional C++
program.

You might also like