Professional Documents
Culture Documents
LAB 1 WEEK 4
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 Graphical presentation Refer to lecture slides for all the symbols Pseudocode Each instruction in a separate line. Preferably start with verb to signify process. Use indentation to present sub task
Jan 2013
Jan 2013
2. Simple Selection (IF-THEN-ELSE) Flowchart 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 Pseudocode
3. Simple Repetition Flowchart 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 Pseudocode
Jan 2013
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 students ID and marks obtained for each test as input. Draw a flowchart and write the pseudocode for the algorithm to calculate the percentage obtained by the student. Print the result along with his students ID. Input Student ID marks1 marks2 marks3 Process Read student ID Read three marks for each test Add three marks Calculate percentage Display student ID and percentage Output Percentage
Flowchart Start
Pseudocode 1.0 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 marks1 marks2 Marks3 1st data set 20 40 50 2nd data set 10 20 30
2. Establish the expected result percentage 1st data set 73 2nd data set 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.
Jan 2013
Statement Line number First pass 2.0 3.0 4.0 5.0 Second pass 2.0 3.0 4.0 5.0
marks1
marks2
Marks3
total
percentage
Display
20
40
50 110 73 73
10
20
30 60 40 40
Or the simplified version: marks1 20 10 marks2 40 20 Marks3 50 30 total 110 60 percentage 73 40 Display 73 40
Activity #1 Write a pseudocode and draw a flowchart to compute the area of a circle. The 2 formula of the area of a circle is r , 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:
Jan 2013