# TIK 20P - QBASIC

Document Sample

```					QBASIC PROBLEMS
Assignment:

Solve a Problem using the five steps to problem solving. You may select to do one, two, or
three of the following programs. If you only choose to complete question one, you will
receive a maximum of 75%. If you choose to do question two, you must do both question
one and question two. You will receive a maximum of 85%. If you choose to do question
three, you must do all three questions. You will receive a maximum of 100%. Do each
problem in a separate file.

Notes: all programs must be properly structured; all output must be block centered on the screen; The
screen should be cleared often to avoid scrolling past the end of the screen. Your program(s) will be
marked out of 100.

NOTE 2: To test how well you know your program, a bug will be added to your program. You must find
and correct the bug. Doing so will prove that you understand your program AND prove that you wrote
the program yourself. Anyone unable to correct the bug will lose 15 marks from their program.

For each of the problems below:

1. Define the problem. In a word processing document, provide the input, the processing, and the
output for each program.
2. Develop an algorithm. In the same word processing document, provide the pseudo code to
produce the programs. Print the document and use it to complete the remainder of the exercise.
3. Code the solution. Using QBASIC, write the program.
4. Test the solution. Try as many inputs as necessary to ensure that the program works. Add a
listing of the input to the end of the program using a comment.

Problem 1:

Write a number guessing program. Your program will randomly generate a number between the two
numbers given by the user. Then the user will repeatedly guess the number. Tell the user if the number is
higher or lower than their guess. Exit when the number is guessed or the user decides to quit. (NOTE:
To generate a random number use RND see below) Give the user an appropriate message if their answer
is right.

'Code To Generate a number Between High and Low
'Get the high and low from the user
INPUT "Enter the highest possible number"; high%
INPUT "Enter the lowest possible number"; low%

'Calculate the number of possible random numbers to be generated
quantity% = high% - low% + 1

'Generate a random number
RANDOMIZE TIMER

P. Hislop O.D.C.V.I.
num% = INT (RND * quantity%) + low%

Problem 2:

Write a simple math program. Your program will display a menu as follows:

2.    Subtraction
3.    Division
4.    Multiplication
5.    Quit

When the user selects 1 through 4, the program will display an appropriate math question and ask the
user for an answer. The math question will be composed of two randomly generated numbers between 1
and 10 (see random code below). Your program will tell the user "Correct" if the answer is correct. Your
program will give the correct answer if the answer is incorrect. Exit the program when the user enters 5
to quit.

'Code to generate a number between 1 and 10

randnum% = INT (RND * 10) + 1

Problem 3:

Write a program to play tic tac toe. Display the screen as follows:

!                   !
1        !         2         !         3
!                   !
-------------------------------------------
!                   !
4        !         5         !         6
!                   !
-------------------------------------------
!                   !
7        !         8         !         9
!                   !

============================
INPUT AREA

PLAYER: ___      POSITION: ___
============================

Ask player where they wish to play. They enter 1, 2, ... or 9. Place an X or Y accordingly. Swithc
players and repeat until someone wins or there is a draw.

P. Hislop O.D.C.V.I.

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 33 posted: 2/1/2010 language: English pages: 2
How are you planning on using Docstoc?