You are ChatGPT, a large language model trained by OpenAI.
- User
System: You are ChatGPT, a large language model trained by OpenAI. User: I will send you a body of text, I will then state what you do next. User: 5 Structured programming LEARNING OBJECTIVESIn this chapter you will learn how to: •use hierarchy/structure charts to plan the design for a program •use fl owcharts to describe a system•write pseudo-code and test it by dry running •use sensible naming conventions for program components•write well-structured commented code. INTRODUCTIONAs we have seen in the fi rst four chapters, there are lots of aspects to consider when creating a program including: •working out the main processes•identifying the data that is needed and how it will be stored •working through the calculations that will be carried out on the data•deciding what type of statements are needed •organising the code into subroutines to create a working program. Timeand effort spent on designing a computer program are always well worth it, and good program design should result in a more effi cient and error-free result. It will also make creating the code easier if you plan ahead. This chapter looks specifi cally at the techniques that can be applied to procedural or imperative programming languages . These languages use sequences of instructions in the form of algorithms and subroutines as described in the previous chapter. A-level students need to be aware of other paradigms including object-oriented and functional programming languages. These are covered in Chapter 6 and Chapters 46 and 47 respectively. SPECIFICATION COVERAGE 3.1.2.1 Structured programming3.3.1.2 Design KEYWORDSProcedural programming languages: languages where the progr ammer specifies the steps that must be carried out in order to achieve a result. Imperative programming langua ges: languages based on giving the computer commands or procedures to follow. 2829FLOWCHARTS ●Hierarchy or structure chartsHierarchy or structure charts use a top-down approach to explain how a program is put together. Starting from the program name, the programmer breaks the problem down into a series of steps. Each step is then broken down into finer steps so that each successivelayer of steps shows the subroutines that make up the program in moredetail. The overall hierarchy of a program might look like this: ●programs are made up of modules●modules are made up of subroutines and functions ●subroutines and functions are made up of algorithms●algorithms are made up of lines of code ●lines of code are made of up statements (instructions) and data.We have come across all of these before apart from the module. In larger programs a module is a self-contained part of the program that can be worked on in isolation from all the other modules. This enables different programmers to work independently on different parts of large programs before they are put together at the end to create the program as a whole. The text in a hierarchy chart at each level consists of only a few words – if you want more detail about what the process involves you need tomove further down the diagram. The component parts for each sectionare organised from left to right to show how the system will work. Figure 5.1 shows just part of a structure diagram of a program showing the program at the top, the modules beneath that and so on. ProgramProcess Input Initialise Output CaptureformValidate Enter data Figure 5.1 A simple hierarchy or structure chart●FlowchartsA flowchart uses a set of recognised symbols to show how the components of a system or a process work together. Some of the more common symbols are shown in Figure 5.2.KEYWORDS Hierarchy chart: a diagram that shows the design of a system from the top down. Structure chart: similar to a hierarchy ch art with the addition of showing how data are passed around the system. Top-down approach: when designing s ystems it means that you start at the top of the process and work your way down into smaller and smaller sub-processes. KEYWORDFlowchart: a diagram using standard symbols that describes a process or system.30 5 Structured programmingA system flowchart shows the tasks to be completed, the files that will be used and the hardware that will be needed but only as an overview. It is normally possible to create just one flowchart that shows the whole system, but this is not always a good idea as modern programs can be very large and cramming every process on to one flowchart might make it too complex to be of any real use. It might be more advantageous to create a separate systems flowchart for each section of the project. The systems flowchart in Figure 5.3 shows the first few processes that are used when a person starts to use an ATM (Automated Teller Machine) at a bank.KEYWORD System flowchart: a diagram that shows in dividual processes within a system.Process Start/stopInput/ outputPrinted output Decision DiskTapeConnector Figure 5.2 Flowchart symbolsEnterPIN Is PIN correct? DisplaymenuRead details from chipDisplay error messagePut cardin machineScreen ScreenNY Figure 5.3 An example of system flowchart for an ATM31NAMING CONVENTIONS ●Pseudo-codeSo far we have looked at diagrammatic ways of organising a program, but the code that a programmer creates does not use diagrams, it uses linesof code. Pseudo-code is a way of writing code without having to worry toomuch ab out using the correct syntax or constructs. It consists of a seriesof commands that show the purpose of the program without getting bogged down with the intricacies of the chosen high-level language. Theprogrammer will need to convert the pseudo-code into high-level code at alater date. Pseudo-code is not a true programming language though it may well usesome of the constructs and language of a high-level language. There is onlyone rule that needs to be adhered to if pseudo-code is to be of any use andthat is that the language used needs to be consistent. Using the command‘Save to File’ in one place then ‘Write to File’ in another will only make thejob of converting to a true high-level language harder. Pseudo-code can be used at many levels. The line: Sort NameFile by surnamedoes exactly the same as these lines: Repeat Compare adjacent values, swap if necessaryUntil No more swaps are neededIt will be up to the programmer to decide how far down they need to break their pseudo-code before they can start to actually write the code. Pseudo-code is very useful in that it allows a programmer to sort out the overall structure of the program as it will eventually appear. The fact that it can be used at many levels means the programmer does not have to work out all the fine detail from the start. The process of turning pseudo-code into programming code is covered in more detail in Chapter 17. ●Naming conventionsAdding variables to a program as you go along is a recipe for disasterand it shows a serious lack of planning. Before you start your actualcode you should draw up a list of all the variables you intend to use,including details of the data types and whether they are going to be localor global variables.KEYWORD Pseudo-code: a method of writ ing code that does not require knowledge of a particular programming language. KEYWORDNaming conventions: the process of giving meaningful names to subroutines, functions, variables and other user-defined features in a program.32 5 Structured programmingThese are some variables that are being declared so they can be used in a Visual Basic program: Dim LoadFileName As StringDim Counter As IntegerDim AverageScore as SingleDim RejectFlag As BooleanGiving the variables, constants, modules, functions and subroutines in a program meaningful names is good practice. It makes a lot more sense to call a variable that stores the number of pupils in a group GroupSize than to call it Size or C3 .In the same way that programmers should sort out the variables, they should also draw up a list of the functions and subroutines they intend to use along with details of what each will do, what it will be called, and what parameters it will need to have assigned to it. ●Code layout and comments The final step to good program construction is to use the features of theprogramming language to make the code itself as programmer-friendly aspossible. This might include adding suitable comments, especially to morecomplex or unusual sections of code, and using gaps and indents to show theoverall structure of a program. Indenting loops can help to identify where aloop begins and ends. It also helps when you are trying to debug a program. The following two sets of code do the same thing – they place the first 12values from the two times table in an array. This first example provides no support for the programmer at all.For X = 1 To 12W(X) = 2 * XNextThis second example has made use of a number of features: ‘routine to place multiples of 2 in array TwoTimes()For Count = 1 To 12 ‘counter counts from 1-12 TwoTimes(Count) = 2 * Count ‘result in array TwoTimesNext Count ‘end loopThe helpful features are: ●comments to show the purpose of the algorithm itself●comments to show the purpose of each line ●sensible variable names such as Count and TwoTimes●the contents of the loop have been indented.DRY RUNS AND TRACE TABLES 33●Dry runs and trace tablesNo matter how careful a programmer is, even the simplest programs are likelyto contain bugs. These come in a number of guises and some are trappedwhen the program is compiled, and others are trapped by the operatingsystem. However some bugs can remain elusive and the programmer mighthave to resort to dry running the appropriate section of code. Dry run ning is the process of following code through on paper. The variablesthat are used are written down in a trace table . Note that dry running canbe done on ps eudo-code or actual programming code. It is useful to dry run pseudo-code as any errors in the overall design of the algorithm can beidentified before too much time has been spent programming it. This is a simple example of a dry run: For Counter = 1 To 3 If StoreName(Counter) > StoreName(Counter + 1)_Then TempName StoreName(Counter) StoreName(Counter) StoreName(Counter + 1) StoreName(Counter + 1) TempNameEnd IfNext CounterThe array called StoreName has four elements. The initial values for StoreName and the other variables are shown in the trace table below. Counter TempName StoreName 0 Kevin Jane Beth Linda1234 The program is now dry run. Counter is set to 1 and the contents of StoreName(1) are compared with the contents of StoreName(2). Because “Kevin” is greater than “Jane” (alphabetically speaking) TempName takes the value “Kevin”, StoreName(1) takes the value “Jane” and finally StoreName(2) takes the value held in TempName – “Kevin”. Counter TempName StoreNameKevin Jane Beth Linda12341 Kevin Jane Kevin Counter now increments to 2 and StoreName(2) is compared to StoreName(3). “Kevin” is greater than “Beth” so TempName becomes “Kevin”. Even though TempName already contains “Kevin” it is important to realise that this is overwritten by the same name. Counter TempName StoreName Kevin Jane Beth Linda12341 Kevin Jane Kevin Kevin 2 Kevin BethKEYWORDSDry run: the process of stepping through each line of code to see what will happen before the program is run. Trace table: a method of recordin g the result of each step that takes place when dry running code.34 5 Structured programmingTASKS1 Draw a systems flowchart that shows how the computer system at a supermarket handles the sale of goods at the POS (point of sale terminal).2 The customers at a supermarket have the option of paying for their goods by credit or debit card. Draw a systems flowchart to show how this process works.3 A programmer might choose to use both a flowchart and pseudo-code when developing a program. Describe the benefits and drawbacks of using each of these systems.4 High-level languages support ‘user-defined variable names ’. Explain what is meant by this term.5 What steps can a programmer take to make the code they write easier for another programmer to follow? STUDY / RESEARCH TASKS1 Why is it considered bad practice to use the GoTo statement when programming?2 An alternative programming paradigm to procedural languages is logic programming, for example Prolog. In what way does this paradigm differ and what are the implications for the way in which programs might be designed? 3 ‘All programs can be structured using only decisions, sequences and loops.’ Explain whether you think this is true.4 In what way do Pascal, Algol and some other programming languages enforce structured design?Counter now increases to 3, and “Kevin” is compared to “Linda”. “Kevin” is less than “Linda” so the program jumps to the End If statement. Counter TempName StoreNameKevin Jane Beth Linda12341 Kevin Jane Kevin Kevin 2 Kevin Beth3 Counter has now reached the end value of the loop so the program moves on to whatever comes next. You have probably realised by now that this algorithm is part of a simple sort routine. Whilst a program is being developed a programmer might also use techniques such as single stepping, where the program is executed one line a time. The programmer can see the values of the variables being used and may choose to insert breakpoints. A breakpoint stops the execution of a program either so the programmer can check the variables at that point or possibly just to show that a program has executed a particular section of code. Practice questions can be found at the end of the section on pages 46 and 47. KEY POINTS•Hierarchy or structure charts use a top-down approach to explain how a program is put together.•A flowchart uses a set ofrecognised symbols to show how the components of asystem or a process worktogether. •Pseudo-code is a way of writingcode without having to worry too much about using thecorrect syntax or constructs. •All the variables you intendto use including details of the data types and whether theyare going to be local or globalvariables should be identifiedat the start. •Good program constructionis to use the features of the program to make the codeitself as programmer-friendlyas possible. •Dry running is the processof following code through on paper. The variables that areused are written down in atrace table. User: Make the following text more clear. Format it properly. Do NOT change the meaning of the words or methods used to obtain the answer or anything like that. This is for AQA A(S)-Level Computer Science. I repeat, do not alter the words as it could have an effect on the marks acquired from the marking scheme. However, remove any redundant information or USELESS examples that are not needed for a student to know, or simplify unnecessary information (if it has a definition or keywords, it is not unnecessary). If you can, use different values for the examples. For things that will not score a mark or are generally useless, for example, "we will cover" or a fun fact, change the wording. This is for AS Level, do not include information about topics that are ONLY A-Level Content (if it says it is) Link the 'sections' of your answer to the following spec-points (by title): e.g. "Topic (Spec Points: a.b.c. Whatever) 3.3.1.2 Design Content Additional information Be aware that before constructing a solution, the solution should be designed and specificed, for example planning data structures for the data model, designing algorithms, designing an appropriate modular structure for the solution and designing the human user interface. Students should have sufficient experience of successfully structuring programs into modular parts with clear documented interfaces to enable them to design appropriate modular structures for solutions.
3.1.2.1 Structured programming Content Additional information Understand the structured approach to program design and construction. Be able to construct and use hierarchy charts when designing programs. Be able to explain the advantages of the structured approach.
You MUST make sure they are ALL met. Everything it says on there you should meet. SOMETIMES the specification does not always mention everything. If you encounter something from the body of text that is not necessarily mentioned on the specification point, still try to include it but condense it. Do not make the notes unecessary or useless.
I already provided the available exam questions you MAY choose to add on to the notes, with 'des' explaining what it's about, and 'fil' meaning the Question ID. The content, too. Delivered in the form 'fil', JSON Ignore exam questions that contain 'Skeleton Program'. Do not only put like 2 exam questions, try to put more! For the exam questions, in the original text, there is a label named 'Tasks'. Those (usually) six questions are NOT the exa questions. The exam questions are the ones that were given in JSON form to you, do NOT do the 'Tasks'. Do the exam questions that contain HTML in JSON!
In the markscheme, a ';' typically means that a mark was gained. When mentioning exam questions, you must answer them, according to the markscheme, scoring full marks. No 'do it yourself'.
Include ALL definitions (KEYWORDS) from the original text I sent in your notes. When I mean all, I mean ALL.
If necessary for scoring marks, try to embed the exam-questions into your notes, sometimes without even referencing the fact that it is an exam question. For example, if an exam question is a definition or benefits, use the answer in your notes. Remember. DO NOT ADD USELESS STUFF. Your task is to create the MOST EFFICIENT (SHORTEST [for an explanation] BUT STILL SCORES ALL MARKS) possible notes resource, which will score all marks easily, so its wording has to be mostly like that of the exam questions. By any means, if necessary, please include examples and exam questions! At the end you can have a 'try these exam questions' thing. At the end of your answer, you will give a 'breakdown'/'summary' of each thing you covered which will tell the most concise FULLY MARK-SCORING explanation possible.
In summary, your answer must:
- Be efficient, useful
- For topics in an exam that may require some form of mathematical working, always show an example of a question.
- Be clear – provide clear, step-by-step examples/instructions when needed.
- Follow the entire specification and everything it says.
- Link your section to a spec point. E.g. Topic (Spec Points: a.b.c Whatever)
- Score ALL marks.
- Include ALL exam questions S at the end (except ones that contain 'Skeleton Program'), with the same wording as the original ones in the JSONs sent to you – and INCLUDE THE QUESTION CONTENT, AND THE ANSWERS/MARK SCHEME. Only the ones that I provided to you, include Question IDs.
- Remove redundant, unnecessary and useless information that would not be brought up in an exam answer.
- Be helpful to the reader
- Provide the full notes, covering ALL spec-points (and showing the spec-points covered in each section).
- Include ALL definitions (KEYWORDS, usually represented explicitly and specifically in the original text as Keyword: Definition), do not change the wording (unless that definition is an exam question). MAKE ALL THE DEFINITIONS FULL (yet consice, as they can sometimes even be 2 marks). Incorporate the definitons into the notes.
- Include a seperate section named 'Definitions' that covers the keywords and their simplest definition that scores all marks. These are (usually) found in the original text.
- Include a summary at the end (after definitions) that goes through everything you need to score all marks.
At the end of the formatted text, after everything is done, fill out the JSON: Remove the type clarification. { "chapter": (int), "page": (int), "chapter_name": (str), "topics": (list) }
User: And these are the available exam questions, with 'des' explaining what it's about, and 'fil' meaning the Question ID. {None: [], 'S1.2.a': [{'index1': '|D.A|K|', 'index3': '2.2.a', 'index5': '|19|', 'index6': 'Q22S1B11p4', 'qid': 'Q22S1B11p4', 'des': 'Complete hierarchy chart for skeleton program', 'index7': '', 'marks': '2 marks', 'time': '3', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q22S1B11P4', 'year': 2023, 'res': '/RESOURCES/AA_COM/RESOURCES/2022_AS_SectionB_resources.html', 'flag1': None}, {'index1': '|D.A|K|', 'index3': '3.2.a', 'index5': '|12|', 'index6': 'Q20S1B08', 'qid': 'Q20S1B08', 'des': 'Complete hierarchy chart for part of Skeleton Program', 'index7': '', 'marks': '3 marks', 'time': '4', 'ttext': 'Programming concepts | Preliminary material', 'fld': 'AA_COM', 'fil': 'Q20S1B08', 'year': 2020, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Section_B_Summer2020.html', 'flag1': None}, {'index1': '|H|K|', 'index2': '|1', 'index4': 'S1|', 'index6': 'QS19S1B09', 'qid': 'QS19S1B09', 'des': 'Complete a hierarchy chart', 'index7': '', 'marks': '3 marks', 'time': '4', 'ttext': 'Systems development | Preliminary material', 'fld': 'AA_COM', 'fil': 'QS19S1B09', 'year': 2019, 'res': '/RESOURCES/AA_COM/RESOURCES/AS_P1_Summer2019.html', 'flag1': 1}]}
User: These are the content of said exam questions, these are the ONLY exam questions, you will use these later, delivered in form 'fil', JSON: {'Q22S1B11P4': {'question': '<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>The chart below shows an incomplete hierarchy chart for part of the Skeleton Program.\r\n <h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>Complete the table below by writing the labels that should appear in each of the boxes (a) to (d) in the chart above.\r\n \r\n\r\n\t\r\n\t\tBox\r\n\t\tLabel\r\n\t\r\n\t\r\n\t\tcp(a)\r\n\t\t \r\n\t\r\n\t\r\n\t\t(b)\r\n\t\t \r\n\t\r\n\t\r\n\t\t(c)\r\n\t\t \r\n\t\r\n\t\r\n\t\t(d)\r\n\t\t \r\n\t\r\n\r\n(Total 2 marks)', 'markscheme': '<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>2 marks for AO2 (analyse)\r\n \r\n\r\n\t\r\n\t\tBox\r\n\t\tLabel\r\n\t\r\n\t\r\n\t\t(a)\r\n\t\tResetDataStructures\r\n\t\r\n\t\r\n\t\t(b)\r\n\t\tLoadPuzzleFile\r\n\t\r\n\t\r\n\t\t(c)\r\n\t\tLoadSolution\r\n\t\r\n\t\r\n\t\t(d)\r\n\t\tTransferPuzzleIntoGrid\r\n\t\r\n\r\n1 mark for 2 correct labels\r\n2 marks for 4 correct labels\r\nA. labels written in different order\r\nI. case and spacing\r\nR. if any additional code\r\nR. if spelt incorrectly\r\n[2]', 'examinerreport': '<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>Both marks of this question were secured by the majority of students. The most common reason for dropped marks was giving more than just the subroutine’s name. For example, ResetDataStructures was creditworthy, whereas ResetDataStructures() was not.', 'notes': '', 'resources': ''}, 'Q20S1B08': {'question': '<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>The diagram below shows an incomplete hierarchy chart for part of the Skeleton Program.\r\n<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(a) What is the purpose of a hierarchy chart?\r\n\r\n\r\n(1)<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(b) What does each box in a hierarchy chart represent?\r\n\r\n\r\n(1)<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(c) What should be written in box (a) in the diagram?\r\n\r\n\r\n(1)\r\n(Total 3 marks)', 'markscheme': '<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(a) Mark is for AO1 (understanding) \r\nTo represent the structure of the program // which subroutine is called from which subroutine;\r\nTo aid decomposition of a problem;\r\nTo aid with stepwise refinement;\r\nMax 1\r\n1<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(b) Mark is for AO1 (understanding) \r\nA subroutine/procedure/function/method; A. module\r\n1<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(c) Mark is for AO2 (analyse) \r\nConvertChar;\r\nR. if any additional code\r\nR. if spelt incorrectly\r\nI. case & spacing\r\n1\r\n[3]', 'examinerreport': '', 'notes': '', 'resources': ''}, 'QS19S1B09': {'question': '<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>The chart below shows an incomplete hierarchy for part of the Skeleton Program.\r\nWith reference to the Skeleton Program and the chart below, answer questions (a) to (c).\r\n <h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(a) What should be written in box (a) in the chart?\r\n\r\n\r\n(1)<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(b) What should be written in box (b) in the chart?\r\n\r\n\r\n(1)<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(c) What should be written in box (c) in the chart?\r\n\r\n\r\n(1)\r\n(Total 3 marks)', 'markscheme': '<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(a) Mark is for AO2 (analyse)\r\nDisplayBoard;\r\nR. if any additional code\r\nR. if spelt incorrectly\r\nI. case & spacing\r\n1<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(b) Mark is for AO2 (analyse)\r\nPrintResult;\r\nR. if any additional code\r\nR. if spelt incorrectly\r\nI. case & spacing\r\n1<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>(c) Mark is for AO2 (analyse)\r\nPrintLine;\r\nA. PrintRow / PrintMiddleRow;\r\nMax 1<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>R. if any additional code\r\nR. if spelt incorrectly\r\nI. case & spacing\r\n1\r\n[3]', 'examinerreport': '<h5 class='contentSeparator' style='page-break-inside: avoid;'><div class='qnumber-hidden'>The hierarchy chart was attempted well by most students.', 'notes': '', 'resources': ''}} User: Now, the user will ask questions after this message. Use everything I gave you and the knowledge you have acquired, and from the notes you made, to answer their question in a very concise way that WILL score ALL marks. Just like the notes. For this, your answer will not have the same structure as the revision notes. Think of it as answering an exam question: short, consice, useful, scores ALL marks. Just like the exam questions provided to you, you will not leave your response in a 'notes' manner. You are just answering an exam question: which means it has to be very short unless explicitly specified by the user that it must be long and detailed. So, keep it short, concise, and only a couple of sentences that score ALL marks. Remember, it is an A-Level exam question and you will style it as such: incredibly concise sentences (essentially like bullet points but without the bullet points) that score marks. Most sentences won't even have commas, this does not mean you can't use them. Also do not repeat the question in your answer, just do it. Score all marks, assume how many marks there are based on the question if it is not provided to you. Imagine that for every sentence you make, you score a mark (for simpler questions), for high (>5 mark) questions that may differ. In summary, you must:
- Answer very concisely. Kind of like bullet points but as a short para. Most of the time, a sentence, or point, will be a mark.
- Do not repeat the question at the start.
- Don't over-do your answer. Please. 1 mark (e.g., usually, 'What' questions) is like one very short sentence usually. Remember the summary from the notes? Your answer will essentially be like that for most questions but a bit (a bit!) more developed. Remember, this is just A-Levels. Use some of the exam questions that I provided as an example of how you should model your answers.
- When you're listing examples, don't list every example in the universe.
- Score all marks. Be helpful. User: Write the notes you made. Exam questions must include the whole question content, the answers, and the amount of marks. Assistant: 3.3.1.2 Design: Program Design and Specification
- Before constructing a program, design and specify solutions. Plan data structures, algorithms, and an appropriate modular structure.
- Hierarchy (or structure) charts help in designing the program by illustrating top-down system composition, representing program structure, and aiding decomposition and stepwise refinement.
- Each box in a hierarchy chart represents a subroutine/procedure/function/method.
- Flowcharts use standard symbols to depict the process, showing steps and data paths. They help visualize the overall system operation but may not show all the details due to complexity.
- Systems Flowchart: A diagram showing individual processes within a system, focusing on tasks, files, and hardware.
- Flowcharts and structure charts help organize a system but can be limited in showing every detail of a large program.
3.1.2.1 Structured Programming: Understanding and Use
- Structured programming involves a methodological approach using procedures, hierarchy charts, and modular programming.
- Hierarchy charts help construct well-structured programs by using a top-down approach to break down processes into modules.
- Modules consist of subroutines or functions; these make up algorithms, which are further broken down into lines of code with instructions and data.
- Pseudo-code: A method of writing code without syntax worries; useful for organizing thoughts and structural planning. Ensure consistency in terminology.
- Naming Conventions: Use meaningful names for program elements to ease understanding and maintenance.
- Good code practices include comments, clear layout, and indentation to enhance readability and debuggability.
Key Definitions:
- Hierarchy Chart: A top-down diagram showing system design.
- Structure Chart: Similar to a hierarchy chart, shows data passage in a system.
- Flowchart: A diagram with standard symbols describing a process/system.
- Pseudo-code: Writing code without specific language syntax knowledge.
- Naming Conventions: Meaningful names for program components.
Exam Questions:
-
Q22S1B11P4 (2 marks)
- Question: Complete the table by writing the labels for each box (a) to (d) in the chart.
- Answer: (a) ResetDataStructures; (b) LoadPuzzleFile; (c) LoadSolution; (d) TransferPuzzleIntoGrid.
-
Q20S1B08 (3 marks)
- Question: (a) Purpose of a hierarchy chart? (b) What does each box represent? (c) What should be in box (a)?
- Answer:
- (a) Represents program structure/subroutine call hierarchy; aids decomposition/stepwise refinement.
- (b) A subroutine, procedure, or function.
- (c) ConvertChar.
-
QS19S1B09 (3 marks)
- Question: What should be written in boxes (a), (b), and (c)?
- Answer:
- (a) DisplayBoard;
- (b) PrintResult;
- (c) PrintLine/PrintRow/PrintMiddleRow.
Summary:
- Design involves planning data structures, algorithms, and user interfaces.
- Use hierarchy and flowcharts for organizing and decomposing programs.
- Understand pseudo-code and naming conventions for clear code.
- Exam questions require understanding of hierarchy charts and structured programming concepts. User: Thanks but this does not include examples and all content like trace tables Assistant: Certainly! Here are the reformulated notes, incorporating examples like trace tables while ensuring all content from the original text is included:
3.3.1.2 Design: Program Design and Specification
- Design and Specification: Before constructing a program, plan data structures, algorithms, and a modular structure.
- Hierarchy/Structure Charts: Use a top-down approach to design programs, breaking them into modules, which consist of subroutines/functions. Each box represents a subroutine, aiding decomposition and stepwise refinement.
- Example: A program structure may begin with the main program at the top, followed by modules like 'Input', 'Process', and 'Output'.
- Flowcharts: Use standard symbols to depict processes and data flow, helping visualize operations but potentially omitting details due to complexity.
- Example Symbols: Ovals for start/stop, parallelograms for input/output, diamonds for decisions.
- System Flowcharts: Show individual processes within a system. Useful when designing systems such as ATM operations.
- Usefulness & Drawbacks: Flowcharts provide clarity but can become cumbersome.
3.1.2.1 Structured Programming: Understanding and Use
- Structured Approach: Methodical programming using procedures, hierarchy charts, and modules.
- Pseudo-code: Write code logically without syntax details, aiding in logical structuring and transition to actual code.
- Consistency in terminology is key (e.g., always use "Save to File" rather than switching terms).
- Naming Conventions: Use descriptive names for variables/constants/functions, preventing confusion and aiding maintenance.
- Example: Use 'GroupSize' instead of 'Size' or 'C3'.
- Good Practices: Comments enhance code understanding and debugging. Use clear layout and indentation.
- Example: Indent loops for clarity.
- Dry Runs and Trace Tables: Dry running is following code on paper; trace tables help track variable states and logic errors.
- Example: Dry run shows swapping elements in a sorting algorithm; trace table captures variable changes step-by-step.
Key Definitions:
- Hierarchy Chart: Diagram showing system design top-down.
- Structure Chart: Similar to hierarchy chart, includes data passage.
- Flowchart: Diagram using symbols to describe a process/system.
- System Flowchart: Diagram showing processes within a system.
- Pseudo-code: Writing code logically without language syntax.
- Naming Conventions: Meaningful names for program elements.
- Dry Run: Manual simulation of code execution.
- Trace Table: Record of variable changes during dry running.
Exam Questions:
-
Q22S1B11P4 (2 marks)
- Question: Complete the table by writing the labels for boxes (a) to (d) in the chart.
- Answer: (a) ResetDataStructures; (b) LoadPuzzleFile; (c) LoadSolution; (d) TransferPuzzleIntoGrid.
-
Q20S1B08 (3 marks)
- Question: (a) Purpose of a hierarchy chart? (b) Box representation? (c) Box (a) content?
- Answer:
- (a) Represents program structure; aids decomposition.
- (b) Represents a subroutine/function.
- (c) ConvertChar.
-
QS19S1B09 (3 marks)
- Question: What should be written in boxes (a), (b), and (c)?
- Answer:
- (a) DisplayBoard;
- (b) PrintResult;
- (c) PrintLine/PrintRow/PrintMiddleRow.
Summary:
- Design involves planning and specifying program elements.
- Use hierarchy and flowcharts for organizing and visualizing systems.
- Pseudo-code helps in program logic structuring.
- Naming conventions ensure clarity.
- Dry runs and trace tables are crucial for debugging.
- Exam questions focus on hierarchy charts and structured programming understanding.
This should include everything required, with examples and explanations related to concepts like trace tables. User: This still does not include examples of like e.g. trace tables or code examples etc or flowcharts Assistant:
- Assistant
Certainly! Let's enrich the notes with practical examples like trace tables, code snippets, and flowcharts while covering all specified content:
3.3.1.2 Design: Program Design and Specification
-
Design and Specification: Plan data structures, algorithms, and modular solutions before coding. Structure programs into modular parts with clear interfaces.
-
Hierarchy/Structure Charts: Use top-down design to break programs into modules, subroutines, and functions.
- Example: A basic hierarchy chart for a data processing program might show:
- Main Module
- Data Input
- Data Processing
- Data Output
- Main Module
- Example: A basic hierarchy chart for a data processing program might show:
-
Flowcharts: Visualize processes using standard symbols like rectangles for processes, diamonds for decisions, and arrows for data flow.
- Example Symbols:
- Start/Stop: Oval
- Process: Rectangle
- Decision: Diamond
- Flow Line: Arrow
- Example Symbols:
-
System Flowcharts: Illustrate processes within a system for tasks, files, and hardware, such as ATM operations.
- Example: ATM System Flowchart
- Start → InsertCard → EnterPIN → Verify → Transaction Menu
- Example: ATM System Flowchart
3.1.2.1 Structured Programming: Understanding and Use
-
Structured Approach: Utilize procedures and hierarchy charts for methodical programming. Emphasize modular design.
-
Pseudo-code: Draft code logically, ignoring syntactic details, focusing on logic and structure.
- Example:
Initialize Total to 0 For each Number in List If Number > 0 Add Number to Total Print Total
- Example:
-
Naming Conventions: Adopt meaningful, consistent names for variables and functions to improve code readability.
- Example: Use 'TotalStudents' instead of 'T' or 'Num1'.
-
Good Practices: Use comments, layout, and indentation for clear code.
- Example:
# Calculate factorial Factorial = 1 For Count from 1 to N Factorial = Factorial * Count # Increment count End For
- Example:
-
Dry Runs and Trace Tables: Dry run code on paper to detect logical errors. Use trace tables to track variable values.
- Example: Sorting Algorithm Dry Run
List: [4, 2, 7] Trace Table: | Step | List | Temp | |------|----------|-------| | 1 | [4, 2, 7]| None | | 2 | [2, 4, 7]| 4 | | 3 | [2, 4, 7]| None |
- Example: Sorting Algorithm Dry Run
Key Definitions:
- Hierarchy Chart: Diagram showing top-down system design.
- Structure Chart: Similar to a hierarchy chart, includes data passage.
- Flowchart: Diagram with symbols for process/system description.
- System Flowchart: Diagram for processes within a system.
- Pseudo-code: Logical code writing without syntax specifics.
- Naming Conventions: Clear, meaningful names for code elements.
- Dry Run: Manual code execution simulation.
- Trace Table: Record of variable changes in code.
Exam Questions:
-
Q22S1B11P4 (2 marks)
- Question: Complete the table by writing labels for boxes (a) to (d).
- Answer: (a) ResetDataStructures; (b) LoadPuzzleFile; (c) LoadSolution; (d) TransferPuzzleIntoGrid.
-
Q20S1B08 (3 marks)
- Question: (a) Purpose of a hierarchy chart? (b) Box representation? (c) Box (a) content?
- Answer:
- (a) Represents program structure; aids decomposition.
- (b) Represents a subroutine/function.
- (c) ConvertChar.
-
QS19S1B09 (3 marks)
- Question: What should be written in boxes (a), (b), and (c)?
- Answer:
- (a) DisplayBoard;
- (b) PrintResult;
- (c) PrintLine/PrintRow/PrintMiddleRow.
Summary:
- Design involves planning program elements carefully.
- Use hierarchy and flowcharts for system organization and visualization.
- Pseudo-code facilitates logical structuring.
- Naming conventions ensure clarity.
- Dry runs and trace tables help identify bugs.
- Exam questions focus on hierarchy charts and structured programming clarity.
This should provide a comprehensive guide with the requested examples and supplemental explanations.
-