Computer Lab. Week 4 - An Introduction to Visual Basic


Home


*** This tutorial contains Assessable Tutorial B ***

The following questions are based on the exercises from the last tutorial.

Question 1

Type the program for Question 1 (GST problem) from the last tutorial. Type the program exactly as shown. The problem is described again below.

Problem Description

A shop owner requires a program to calculate the GST payable on items purchased. The GST is one-tenth of the pre GST price. For example, if the pre-GST price was $100 then the GST is $10 and the price including GST is $110. The user is to input the pre-GST price and the program is to display the GST and the final price including GST.

Example Program Runs

Run
Pre GST Price ($) ? 100
GST = $10.00
Price Including GST = $110.00
Run
Pre GST Price ($) ? 5.50
GST = $0.55
Price Including GST = $6.05

Type in the Program

Type this program exactly as shown below (except for the author - use your name instead)



Question 2

Write a Visual Basic program for the following problem.

Problem Description

An athlete is interested in their average speed over a distance. The user is to input the distance (in km) and time taken (in seconds) and the average speed in kilometres per hour is to be displayed. Firstly, as the speed is in kilometres per hour,  the time taken in seconds needs to be converted to hours; there are 3600 seconds in an hour, so dividing the time in seconds by 3600 gives the time taken in hours, so 1800 seconds = 1800 ÷ 3600 = 0.5 hours. For example if the athlete travelled 5.2km in 1800 seconds, then their average speed is calculated as follows: 1800 seconds is 1800 ÷ 3600 hours = 0.5 hours. The average speed is the distance travelled (in km) divided by the time taken (in hours) = 5.2 km ÷ 0.5 hours = 10.4kph.

Example Runs

Run
Distance (km) ? 15
Time taken (sec) ? 3600
Average speed = 15kph
Run
Distance (km) ? 5.2
Time taken (sec) ? 1800
Average speed = 10.4kph

Pseudo Code

calcAverageSpeed()
    Input distance, timeInSeconds
    timeInHours = timeInSeconds / 3600
    averageSpeed = distance / timeInHours
    Display averageSpeed
STOP

Data Dictionary

Name Data Type Description
averageSpeed Double The average speed over the distance in kph (Kilometres per hour)
distance Double Distance travelled in kilometres
timeInHours Double The time taken to travel the distance in hours and fractions of hours
timeInSeconds Integer The time taken to travel the distance (in seconds) to the nearest whole second

Assessable Tutorial B

Due Date: Computer Lab. Week 5
Marks: 2%

Question 2 above is Assessable Tutorial B. Hand in a title page as specified in Assessable Tutorial A, and a printout of the code for question 2 . The printout of the code should be done from within Access (e.g. File->Print when the code is displayed).


Written by Tim Whitfort.