Study guide
home lecture notes lecture notes study guide unit profile Past exams web comp staff details

[ Review questions ] [ Examples ] [ Lecture slides ]

module12

Required reading

---------------------------------------------------------
Textbook Martin 1994
Chs 2 & 3
---------------------------------------------------------


Review questions

REVIEW QUESTION 12-1Do the Chapter review exercises at the end of each chapter.
REVIEW QUESTION 12-2Try some of the example programs given below.
REVIEW QUESTION 12-3Do at least the first three programming problems in each of Chapters 2 and 3.
top of page


Examples

EXAMPLE 12-1

Construct a program which will prompt an operator to input three characters, receive those three characters, and display a welcoming message to the screen such as "Hello xxx! We hope you have a nice day."

(From Robertson, 1993, p. 31)

SOLUTION

REM  Program name: 	EXTEMP.BAS
REM Description: 	Program to input three 
REM characters xxx and display
REM them on the screen with a welcoming message
REM
REM 'Hello xxx! We hope you have a nice day'
PRINT "Enter three characters:"
INPUT aname$
PRINT "Hello "; aname$; "! We hope you have a nice day"
END

Note this program is really too simple, but it will do for now. There is no check that only 3 characters are entered.

EXAMPLE 12-2

A program is required which will receive two integer items from a terminal operator, and display on the screen their sum, difference, product and quotient.
(From Robertson, 1993, p. 31)

SOLUTION

REM Program name:	EXCALC.BAS
REM Program description: Program to input two integers REM and do arithmetic
REM
PRINT
INPUT "Enter first number: ", Num1%
INPUT "Enter second number: ", Num2%
PRINT
PRINT "Sum", Num1% + Num2%
PRINT "Difference", Num1% - Num2%
PRINT "Product", Num1% * Num2%
PRINT "Quotient", Num1% / Num2%
PRINT
PRINT "End program"
END

EXAMPLE 12-3

A program is required to prompt the terminal operator for the maximum and minimum temperature readings on a particular day, accept those readings as integers, calculate and display to the screen the simple average temperature, calculated by (maximum temperature + minimum temperature) / 2.
(From Robertson, 1993, p. 28)

SOLUTION

REM Program name:	EXTEMP.BAS
REM Program description: Average temperature calculation
REM
PRINT "Enter maximum temperature"
INPUT max.temp
PRINT "Enter minimum temperature"
INPUT min.temp
avg.temp = (max.temp + min.temp) / 2
PRINT "Average temperature = "; avg.temp
END

EXAMPLE 12-4

This program shows the difference between arithmetic with integer as opposed to single precision variables.

SOLUTION

REM Program name:	EXARITH.BAS
REM Program description:	input,output, arithmetic
CLS
PRINT "25131 Example program EXARITH"
PRINT
INPUT "Enter your name: ", Aname$
INPUT "Enter your age: ", Age
PRINT
X = Age / 3	'result is single precision
X% = Age / 3	' result is integer
PRINT Aname$; " a third your age is "; X; 
PRINT "or approximately"; X%
PRINT "Your age squared is "; Age ^ 2
PRINT "End program"
END

top of page


[ Home ] [ CQU home ] [ Lecture notes ] [ Study guide ]
[ Unit profile ] [ Past exams ] [ Web comp ] [ Staff details ] [ Email list ]

For errors contact the Webmaster.
These pages were designed by BS Computer Solutions.
Copyright © 1997 Central Queensland University. All rights reserved.