1 / 105

310201 Fundamental Programming

310201 Fundamental Programming. Tools for Analysis & Design. Review. 5-step SDLC: task analysis and specification algorithm design coding testing maintenance task analysis is important

Download Presentation

310201 Fundamental Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 310201Fundamental Programming Tools for Analysis & Design Fundamental Programming: 2006

  2. Review • 5-step SDLC: • 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: • 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 intoa “whole” • analysts havetools for documentingtheirunderstanding 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, Enrolments CourseCode Enrolment Form Enrolment Student Process Address Enrolment Student Details Advice Fundamental Programming: 2006

  5. Modelling Tools • an ERD describes entities and relationshipsthat will berecoded in a database StudentID Students Name M Address Enrol In FacultyCode M CourseCode Name M 1 Dean Name Offered 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 rightprogram 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 containerson 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 5base statement types • we want you to understand that programming languages are very simple - so, the pseudocode in the Study Guideusesonestatementofeachtype • when you are familiar with these statements, you will understand the basics of programming in all popularprogramming 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 statementscontrolflow of a program • they control whichinput, 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 100 - 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 Number of marks in exam ==> 80 Student’s mark ==> 60 Student’s percentage: 75 (Pass) or… Number of marks in exam ==> 80 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” 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” get student’s mark calculate the student’s percentage display the student’s percentage display “Pass” or “Fail” 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

More Related