Download presentation
Presentation is loading. Please wait.
1
310201 Fundamental Programming
Tools for Analysis & Design Fundamental Programming: 2006
2
Review 5-step SDLC: task analysis is important
task analysis and specification algorithm design coding testing maintenance task analysis is important to avoid expensive re-design and coding, you must have a clear understanding of the task(s) the program must perform Fundamental Programming: 2006
3
Task Analysis task analysis may include: two important skills are:
interviews with users studying documentation for an existing systems studying other documents that describe requirements for the program two important skills are: analysis – dissect task to expose sub-tasks synthesis – combine different views into a “whole” analysts have tools for documenting their understanding of the requirements Fundamental Programming: 2006
4
Modelling Tools the analyst uses graphical tools to describe the system a program will support a DFD shows the data flows in a system StudentID, CourseCode Enrolments Enrolment Form Enrolment Student Process Address Enrolment Advice Student Details Fundamental Programming: 2006
5
Modelling Tools an ERD describes entities and relationships that will be recoded in a database StudentID Students Name M Address Enrol In FacultyCode CourseCode M Name M 1 Name Offered Dean Course Faculties By Fundamental Programming: 2006
6
Written Specifications
analysts also produce a written specification of the requirements the specification is verified by the client to ensure that the right program is being built this is where we start in this course: we start with written specifications students assume role of designer/programmer however, this does still involve some analysis you will be analysing written specifications Fundamental Programming: 2006
7
Written Specifications
the Study Guide describes a 6-step process to analyse a written specification: (1) read the description fully (2) rewrite the task in your own words (3) mark action, naming and information words and phrases (4) make sure you understand the actions required (5) put the actions in the correct sequence (6) check your work Fundamental Programming: 2006
8
Written Specifications
(1) read the description fully don’t be a dumb hare, be a clever turtle (2) rewrite the task in your own words use pictures and rough notes - whatever works (3) mark action, naming and information words and phrases “…Karen’s job is to transfer the herbs and spices from the pallets to the shelves. The drums always go on the left-hand side of the shelves, the square containers on the right…” Fundamental Programming: 2006
9
Written Specifications
(4) make sure you understand the actions required research any unknown details example: deg F = 32 + (deg C * 1.8) (5) put the actions in the correct sequence (6) check your work if you can, get someone else to check it – ideally, the client, or a colleague (another student?) Fundamental Programming: 2006
10
Program Design with a clear understanding of the task(s) to be performed, we start to design the program in industry the design of a program is often written in pseudocode pseudocode is like to a high-level programming language, but easier to read we will use pseudocode in this course the pseudocode used in the Study Guide is as simple as we can possibly make it... Fundamental Programming: 2006
11
Pseudocode in Study Guide
why a simpler pseudocode? to keep the examples simple, but also… at the core of all programming languages are 5 base statement types we want you to understand that programming languages are very simple - so, the pseudocode in the Study Guide uses one statement of each type when you are familiar with these statements, you will understand the basics of programming in all popular programming languages Fundamental Programming: 2006
12
The Building Blocks the 3 most important statements are:
input statements - read output statements - write assignment statements - set (to store values in memory) other 2 statements control flow of a program they control which input, output and assignment statements are performed by the program they control the number of input, output and assignment statements performed by the program Fundamental Programming: 2006
13
Sample Program Revisited
output “Number of marks in exam ==> “ to display input number from keyboard - store in M1 output “Student’s mark ==> “ to display input number from keyboard - store in M2 divide number in M2 by number in M1 - store in M3 multiply number in M3 by store in M4 output “ Student’s percentage: “ to display output number in M4 to display Fundamental Programming: 2006
14
Example Pseudocode write “Number of marks in exam ==> “ read M1
write “Student’s mark ==> “ read M2 set M3 to M2 / M1 set M4 to 100 * M3 write “ Student’s percentage: “ write M4 Fundamental Programming: 2006
15
Variables instead of using memory locations directly, all modern programming languages use names to refer to memory locations we call these things variables – the values they refer to vary as the program runs using names, instead of memory locations, makes programs easier to read instead of… Fundamental Programming: 2006
16
Example Pseudocode write “Number of marks in exam ==> “ read M1
write “Student’s mark ==> “ read M2 set M3 to M2 / M1 set M4 to 100 * M3 write “ Student’s percentage: “ write M4 Fundamental Programming: 2006
17
Variables write “Number of marks in exam ==> “ read NbrMarks
write “Student’s mark ==> “ read StudentMark set ProportionOfMarks to StudentMark / NbrMarks set Percentage to 100 * ProportionOfMarks write “ Student’s percentage: “ write Percentage 4 variables: NbrMarks, StudentMark, ProportionOfMarks, Percentage Fundamental Programming: 2006
18
Alternative Design write “Number of marks in exam ==> “
read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage 3 variables: NbrMarks, StudentMark,Percentage Fundamental Programming: 2006
19
Branching our example program always performs the exact same actions:
get number of marks in exam get student’s mark calculate the student’s percentage display the student’s percentage in practice, most programs are capable of performing different actions, depending on the inputs provided by the user e.g., we may want to also state if the student passed the exam – so, sometimes the program will need to output “Pass”, otherwise “Fail” Fundamental Programming: 2006
20
Sample Dialogs or… Number of marks in exam ==> 80
Student’s mark ==> 60 Student’s percentage: 75 (Pass) or… Student’s mark ==> 20 Student’s percentage: 25 (Fail) Fundamental Programming: 2006
21
Branching Statements to enable programs to perform different actions (depending on user input) all programming languages include one or more branching or selection statements the branching statement selects between one of more possible paths through the program all programming languages include some form of if-then-else statement Fundamental Programming: 2006
22
Pseudocode Example write “Number of marks in exam ==> “
read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” else write “ (Pass)” Fundamental Programming: 2006
23
Example of if-then-else
=> write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: ? else StudentMark: ? write “ (Pass)” Percentage: ? Fundamental Programming: 2006
24
Example dialog Number of marks in exam ==>
Fundamental Programming: 2006
25
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: ? else StudentMark: ? write “ (Pass)” Percentage: ? => Fundamental Programming: 2006
26
Example dialog Number of marks in exam ==>
Fundamental Programming: 2006
27
Example dialog Number of marks in exam ==> 80
Fundamental Programming: 2006
28
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: ? else StudentMark: ? write “ (Pass)” Percentage: ? => Fundamental Programming: 2006
29
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: ? write “ (Pass)” Percentage: ? => Fundamental Programming: 2006
30
Example dialog Number of marks in exam ==> 80 Student’s mark ==>
Fundamental Programming: 2006
31
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: ? write “ (Pass)” Percentage: ? => Fundamental Programming: 2006
32
Example dialog Number of marks in exam ==> 80 Student’s mark ==>
Fundamental Programming: 2006
33
Example dialog Number of marks in exam ==> 80
Student’s mark ==> 20 Fundamental Programming: 2006
34
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: ? write “ (Pass)” Percentage: ? => Fundamental Programming: 2006
35
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: 20 write “ (Pass)” Percentage: ? => Fundamental Programming: 2006
36
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: 20 write “ (Pass)” Percentage: 25 => Fundamental Programming: 2006
37
Example dialog Number of marks in exam ==> 80
Student’s mark ==> 20 Student’s percentage: Fundamental Programming: 2006
38
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: 20 write “ (Pass)” Percentage: 25 => Fundamental Programming: 2006
39
Example dialog Number of marks in exam ==> 80
Student’s mark ==> 20 Student’s percentage: 25 Fundamental Programming: 2006
40
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: 20 write “ (Pass)” Percentage: 25 => Fundamental Programming: 2006
41
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: 20 write “ (Pass)” Percentage: 25 => Fundamental Programming: 2006
42
Example dialog Number of marks in exam ==> 80
Student’s mark ==> 20 Student’s percentage: 25 (Fail) Fundamental Programming: 2006
43
Example of if-then-else
write “Number of marks in exam ==> “ read NbrMarks write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage if Percentage < 50 then write “ (Fail)” NbrMarks: 80 else StudentMark: 20 write “ (Pass)” Percentage: 25 => Fundamental Programming: 2006
44
Activity What is the value of Number3 at the end of the following pseudocode? set Number1 to 12 set Number2 to 14 set Number3 to 0 if Number1 > Number2 then set Number3 to Number1 * Number2 else set Number3 to (Number1 + Number2)/2 Fundamental Programming: 2006
45
Activity Break Fundamental Programming: 2006
46
Looping our program to calculate the exam percentage for a single student performs the following 5 tasks: get number of marks in exam get student’s mark calculate the student’s percentage display the student’s percentage display “Pass” or “Fail” to calculate the exam percentage for more than one student, a program must perform some of these tasks more than once… Fundamental Programming: 2006
47
Looping to calculate the percentage for 2 students, a program must perform 9 tasks: get number of marks in exam get student’s mark calculate the student’s percentage display the student’s percentage display “Pass” or “Fail” Fundamental Programming: 2006
48
Looping to calculate the percentage for 3 students, a program must perform 13 tasks: get number of marks in exam get student’s mark calculate the student’s percentage display the student’s percentage display “Pass” or “Fail” Fundamental Programming: 2006
49
Looping we could have: one program to handle 2 students, another program to handle 3 students, etc it would be better to have a single program to handle any number of students we would like to design a program to repeat some actions more than once Fundamental Programming: 2006
50
Looping we want our program to:
get the number of marks in exam from user - repeat as required - get student’s mark calculate the student’s percentage display the student’s percentage display “Pass” or “Fail” we will have to ask the user how many repetitions are required one design is… Fundamental Programming: 2006
51
Looping ask user for number of students at start: another design is…
get number of marks in exam get number of students - repeat once for each students - get student’s mark calculate the student’s percentage display the student’s percentage display “Pass” or “Fail” another design is… Fundamental Programming: 2006
52
Looping keep asking if the user has more students:
get number of marks in exam - repeat while user wants has more students - get student’s mark calculate the student’s percentage display the student’s percentage display “Pass” or “Fail” ask user if they have more students Fundamental Programming: 2006
53
Looping Statements to enable programs to perform different numbers of actions (depending on data inputs) all programming languages include one or more looping or repetition statements all programming languages include some form of while statement... Fundamental Programming: 2006
54
Pseudocode Example write “Number of marks in exam ==> “
read NbrMarks write “Number of students ==> “ read NbrStudents set NbrProcessed to 0 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 Fundamental Programming: 2006
55
Example of while => write “Number of marks in exam ==> “ NbrMarks: ? read NbrMarks NbrStudents: ? write “Number of students ==> “ NbrProcessed: ? read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 Fundamental Programming: 2006
56
Example dialog Number of marks in exam ==>
Fundamental Programming: 2006
57
Example of while write “Number of marks in exam ==> “ NbrMarks: ?
read NbrMarks NbrStudents: ? write “Number of students ==> “ NbrProcessed: ? read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
58
Example dialog Number of marks in exam ==>
Fundamental Programming: 2006
59
Example dialog Number of marks in exam ==> 80
Fundamental Programming: 2006
60
Example of while write “Number of marks in exam ==> “ NbrMarks: ?
read NbrMarks NbrStudents: ? write “Number of students ==> “ NbrProcessed: ? read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
61
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: ? write “Number of students ==> “ NbrProcessed: ? read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
62
Example dialog Number of marks in exam ==> 80
Number of students ==> Fundamental Programming: 2006
63
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: ? write “Number of students ==> “ NbrProcessed: ? read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
64
Example dialog Number of marks in exam ==> 80
Number of students ==> Fundamental Programming: 2006
65
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Fundamental Programming: 2006
66
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: ? write “Number of students ==> “ NbrProcessed: ? read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
67
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: ? read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
68
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 0 read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
69
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 0 read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
70
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> Fundamental Programming: 2006
71
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 0 read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
72
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> Fundamental Programming: 2006
73
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> 20 Fundamental Programming: 2006
74
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 0 read NbrStudents StudentMark: ? set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
75
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 0 read NbrStudents StudentMark: 20 set NbrProcessed to Percentage: ? while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
76
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 0 read NbrStudents StudentMark: 20 set NbrProcessed to Percentage: 25 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
77
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> 20 Student’s percentage: Fundamental Programming: 2006
78
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 0 read NbrStudents StudentMark: 20 set NbrProcessed to Percentage: 25 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
79
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> 20 Student’s percentage: 25 Fundamental Programming: 2006
80
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 0 read NbrStudents StudentMark: 20 set NbrProcessed to Percentage: 25 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
81
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 20 set NbrProcessed to Percentage: 25 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
82
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 20 set NbrProcessed to Percentage: 25 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
83
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> 20 Student’s percentage: 25 Student’s mark ==> Fundamental Programming: 2006
84
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 20 set NbrProcessed to Percentage: 25 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
85
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> 20 Student’s percentage: 25 Student’s mark ==> Fundamental Programming: 2006
86
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> 20 Student’s percentage: 25 Student’s mark ==> 40 Fundamental Programming: 2006
87
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 20 set NbrProcessed to Percentage: 25 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => l Fundamental Programming: 2006
88
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 40 set NbrProcessed to Percentage: 25 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
89
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 40 set NbrProcessed to Percentage: 50 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
90
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 40 set NbrProcessed to Percentage: 50 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
91
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> 20 Student’s percentage: 25 Student’s mark ==> 40 Student’s percentage: Fundamental Programming: 2006
92
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 40 set NbrProcessed to Percentage: 50 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
93
Example dialog Number of marks in exam ==> 80
Number of students ==> 2 Student’s mark ==> 20 Student’s percentage: 25 Student’s mark ==> 40 Student’s percentage: 50 Fundamental Programming: 2006
94
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 1 read NbrStudents StudentMark: 40 set NbrProcessed to Percentage: 50 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
95
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 2 read NbrStudents StudentMark: 40 set NbrProcessed to Percentage: 50 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
96
Example of while write “Number of marks in exam ==> “ NbrMarks: 80
read NbrMarks NbrStudents: 2 write “Number of students ==> “ NbrProcessed: 2 read NbrStudents StudentMark: 40 set NbrProcessed to Percentage: 50 while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark set Percentage to 100 * StudentMark / NbrMarks write “ Student’s percentage: “ write Percentage set NbrProcessed to NbrProcessed + 1 => Fundamental Programming: 2006
97
Activity Show the output produced by the following pseudocode.
set TotalCost to 20 set ItemCost to 5 set NumberOfItems to 0 while TotalCost > 0 set TotalCost to TotalCost - ItemCost set NumberOfItems to NumberOfItems + 1 write “Number of items purchased: “ write NumberOfItems Fundamental Programming: 2006
98
Activity Break Fundamental Programming: 2006
99
Pseudocode in Study Guide
one data input statement: read one data output statement: write one assignment statement: set two flow control statements: one selection statement: if-then-else if Percentage < 50 then write “(Fail)” else write “(Pass)” one repetition statement: while while NbrProcessed < NbrStudents write “Student’s mark ==> “ read StudentMark : Fundamental Programming: 2006
100
Flowchart A graphical tools for writing an algorithm Flow lines
Start/Stop Input/Output Processing Fundamental Programming: 2006
101
การเขียนผังงาน (Flowchart)
Decision Connection Predefined Process (Subprogram) Printer output Storage Fundamental Programming: 2006
102
Fundamental Programming: 2006
103
Programming Languages
all programming languages consist of a collection of input, output, assignment, selection and repetition statements most have: only one assignment statement one or more input and output statements several selection and repetition statements sample assignment statements: C++: NbrProcessed = 0 ; Visual Basic: NbrProcessed = 0 Pascal: NbrProcessed := 0 ; COBOL: MOVE 0 TO NBR-PROCESSED. Fundamental Programming: 2006
104
Summary we start from written specifications
a 6-step process has been provided to help with the analysis of written specifications program designs are written in pseudocode Study Guide uses very simple pseudocode five base programming statements are: input, output, assignment, selection, repetition these statements provide a platform for programming in all popular languages Fundamental Programming: 2006
105
Study Guide this week you should read the first three modules in the Study Guide (Book 1) and make a start on Module 4 also, you should read Assignment 1 by the end of this week you will be in a position to make a start on Assignment 1 start Assignment 1 as soon as you can! Fundamental Programming: 2006
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.