Intended Learning Outcomes of this
Exercise
Upon completion of this tutorial/lab, you
should be able to:
o Identify inputs, outputs, and processing
components from a problem description.
o Work out solution algorithm for the defined problem
with sequence, selection and repetition control structures.
o Write the solution algorithm with
pseudocode.
Task 1: Tutorial
Short Questions.
Task 2: Algorithms Development
Problem 1. A simple problem with only
sequence
Problem 2. A problem with single selection
Problem 3. A problem with multiple
selections
Problem 4. A problem with multiple
selections
Problem 5. A problem with repetition
Problem 6. A challenging problem
References
1. Robertson, L.A. (2006). Simple Program
Design (5 th ed.). Boyd & Fraser Publishing Company, Chapters 1-3.
This
exercise is designed for two 2-hour tutorial/lab sessions!
Task 1. Tutorial
(30%)
Short Questions:
1. List the seven basic steps in computer
program development.
Define the problem
Outline the solution
Develop the outline
into an algorithm
Test the algorithm for
correctness
Code the algorithm
into a targeted programming language
Run the program on the
computer
Document and maintain
the program
2. What are the inputs and outputs of the
following problems?
a. Calculating the area of a triangle
input: the height and the length of the triangle
output: the area of a triangle
b. Calculating the solution(s) of a
quadratic equation in form
input: ax2+bx+c , where input the value of a , b and c.
output: the solution(s) of a
quadratic equation
c. Measuring the distance of two cities on
Earth
input: A’cities
output: the value which is the
distance of two cities on Earth
d. A stop-watch
input: stating time when click ‘start’
output: Cumulative counting time result
e. Generating a random number between
0.0000 to 1.0000
input: 0.0000 and 1.0000
output: A random number drawn between 0.0000 and 1.0000
3. What are the two main advantages in
using meaningful names for variables, e.g.
intStudentAge, dblHeight, strAddress, etc.?
Easy
to editing the code and
4. Determine the most suitable data types
and give good names for the following variables. ( any reasonable answer ?)
a. A student’s English name
Datatype:
VariableName:
stuname
b. The examination mark of a student for
the “Introduction to Programming” module
Datatype:
VariableName:
Itpmarks
c. A student identification card number for
an XYZ's school student
Datatype:
VariableName:
XYZstuid
d. The total number of items in a box
Datatype:
VariableName: totalnuminbox
5. List the major steps in algorithm
development.
Datatype:
VariableName: majstepofalogdev
Task 2. Algorithms Development (70%)
Problem
1. Units Conversion
A program is designed to convert a length
in inches to centimeters (1 inch = 2.54 cm). Design an algorithm in
pseudocode to solve the problem.
DISPLAY
“Please enter the length”
GET
douLength
douLength
← douLength * 2.54
DISPLAY douLength
Problem
2. Direction of a Street in New York City
In New York City (NYC), even numbered
streets are eastbound, odd numbered streets are westbound. Given a
street number of a street in NYC, decide the direction of the street, either eastbound
or westbound. Design an algorithm in pseudocode for the problem.
DISPLAY “Please enter the Street Number”
Get
douStnu
IF
doustnu / 2
Problem
3. Converting a Mark into a Grade
A program is designed to convert an
examination mark (0-100) to a grade (A-F) based on the following table.
Design an algorithm in pseudocode to solve the problem.
Mark 0-59 60-69 70-79 80-89 otherwise
Grade F D C B A
Problem 4. Calculating Parking Fee
A program is used to calculate the parking
fee based on the type of vehicle and the hours a vehicle
spent in a car park. The program should
calculate the parking fee according to the following table.
Design an algorithm in pseudocode to solve
the problem.
Type of vehicle Duration (hours) Charge
rate ($/hour) Parking fee ($)
Car 2.8 15 45
Bus 3.0 30 90
Truck 4.1 40 200
Problem 5. Displaying a Number of ‘*’
A program is used to prompt user a positive
integer number (n) and then display n ‘*’ on the screen
(see below). Design an algorithm in
pseudocode for the program.
Please input a positive integer: 5
*****
Problem 6. Maximizing Photos Printing
Given the width and length of a piece of
rectangular photo paper, determine the maximum number of
small-size rectangular photos can be
printed on it. (Hints: All small-size photos are arranged in
either portrait or landscape).
Portrait arrangement
Landscape arrangement
*** End ***
5,6??
回覆刪除請回覆
回覆刪除