0% found this document useful (0 votes)
40 views5 pages

Lab 1 Week 3: Objective

This document outlines the steps in the program development process including understanding the problem, designing a solution, developing an algorithm, testing the algorithm, coding the program, and running it. It introduces algorithms, pseudocode, and flowcharts, and provides examples of each. The document also describes different control structures for algorithms and includes sample problems and activities for writing algorithms to solve problems.

Uploaded by

Permata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views5 pages

Lab 1 Week 3: Objective

This document outlines the steps in the program development process including understanding the problem, designing a solution, developing an algorithm, testing the algorithm, coding the program, and running it. It introduces algorithms, pseudocode, and flowcharts, and provides examples of each. The document also describes different control structures for algorithms and includes sample problems and activities for writing algorithms to solve problems.

Uploaded by

Permata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Fundamental Programming

LAB 1 Week 3

LAB 1 WEEK 3

Objective
1. To describe the steps in the program development process
2. To introduce algorithms and pseudocode
3. To introduce desk checking – manually check the algorithm

Deliverable items
For each of the following activities, you are required to:
1. Determine input, output and process. Provide your assumptions, if any,
2. Develop a complete algorithm, pseudocode, OR flowchart, and
3. Desk checking with some sample data.

Steps in Program Development Process


1. Understand the problem.
 Separate and define three components in the problem :
i. The inputs
ii. The outputs
iii. The processing steps to produce the output (process)
2. Outline the solution
 Design rough draft of the solution that includes :
i. Major processing steps
ii. Major subtasks (if any)
3. Develop the outline into an algorithm
 Transform outline into algorithm
 Algorithm: a set of precise steps that describe exactly the tasks to
be performed in the order in which they are to be carried out.
 Options : Pseudocode or Flowchart
4. Test the algorithm for correctness
 Desk checking – ‘walks’ the test data through each step in the
algorithm
 To identify major logic errors (ex : wrong formula etc)
5. Translate the algorithm into C++ program
 Write the code
6. Compile and run the program

Algorithms
 Must be written in simple English
 Unambiguous, terminating and executable
 Step by step and in order
 Popular methods for representing algorithms are :

Flowchart Pseudocode

 Graphical presentation  Each instruction in a separate line.


 Refer to lecture slides for all the  Preferably start with verb to signify
symbols process.
 Use indentation to present sub task

All programs can be described by combining the following 3 control


structures:

1 Sep 2012
Fundamental Programming
LAB 1 Week 3

Simple Selection
Simple
(IF-THEN-ELSE)
Simple Sequence Repetition
(Loop)
Examples

1. Simple Sequence
Flowchart Pseudocode

1.0 START

2.0 Login to E-learning

3.0 Select the course

4.0 Select the topic

5.0 Select the file

6.0 Print the notes

7.0 Logout

8.0 END

2. Simple Selection

2 Sep 2012
Fundamental Programming
LAB 1 Week 3

(IF-THEN-ELSE)

Flowchart Pseudocode

1.0 START

2.0 Login to E-learning

3.0 Select the course

4.0 Select the topic

5.0 Select the file

5.1 IF download the file THEN

Save File. Go to Step 7.0.

5.2 ELSE. Open File

6.0 Print the notes

7.0 Logout

8.0 END

3. Simple Repetition

Flowchart Pseudocode

1.0 START
2.0 Login to E-learning
2.1 IF password is correct THEN
Go to Step 3.0.
ELSE
Repeat step 2.0.
3.0 Select the course
4.0 Select the topic
5.0 Select the file
5.1 IF download the file THEN
Save File. Go to Step 7.0.
5.2 ELSE. Open File
6.0 Print the notes
7.0 Logout
8.0 END
4. Program with input and output

A student has to take three tests per semester. Each test has maximum marks of
50. By using a system, lecturer can enter a student’s ID and marks obtained for
each test as input. Draw a flowchart and write the pseudocode for the algorithm

3 Sep 2012
Fundamental Programming
LAB 1 Week 3

to calculate the percentage obtained by the student. Print the result along with
his student’s ID.

Input Process Output


Student ID Read student ID Percentage
marks1 Read three marks for each test
marks2 Add three marks
marks3 Calculate percentage
Display student ID and percentage

Flowchart Pseudocode
1.0 START
Start
2.0 Read student ID and Read three marks
(marks1, marks2, marks3).

3.0 Add three marks

total = marks1+marks2+marks3.

4.0 Calculate percentage

Percentage = total/ 150 * 100

5.0 Display the student ID and result.

6.0 END

Desk checking

1. Choose two sets of input test data


1st data set 2nd data set
marks1 20 10
marks2 40 20
Marks3 50 30

2. Establish the expected result


1st data set 2nd data set
percentage 73 40
3. Set up a table of relevant variable names and pass each test data
set through the solution algorithm, statement by statement.
Line numbers have been used to identify each statement within a
program.

Statement marks1 marks2 Marks3 total percentage Display


Line
number
First pass

4 Sep 2012
Fundamental Programming
LAB 1 Week 3

2.0 20 40 50
3.0 110
4.0 73
5.0 73
Second
pass
2.0 10 20 30
3.0 60
4.0 40
5.0 40

Or simplified version :

marks1 marks2 Marks3 total percentage Display


20 40 50 110 73 73
10 20 30 60 40 40

Activity #1
Write a pseudocode and draw a flowchart to compute the area of a circle. The
formula of the area of a circle is ∏r2 , where r is the radius of the circle. The
program accepts the user input for the radius and displays the result on the
standard output.

Activity #2
Write a pseudocode and draw a flowchart to find the sum of first 5 integer
numbers.

Activity #3
Write an algorithm (pseudocode and flowchart) to solve the following problem: A
bank account starts out with RM10000. Interest is compounded monthly at 6%
per year (0.5% per month). Every month, RM800 is withdrawn to meet college
expenses. After how many years is the account depleted?

Activity #4
Draw a flow chart for a program that will display the following output:

References:
Labsheet materials of Structured Programming & Database lab. class,
CIS Dept., University Technology Petronas.

5 Sep 2012

You might also like