









































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Computer Science, 2023-2025,Mr Chuma
Typology: Study notes
1 / 49
This page cannot be seen from the preview
Don't miss anything!










































On special offer
The stages in the program development cycle:
The program development life cycle The program development life cycle is divided into five stages: analysis, design, coding, testing and maintenance. Four stages; » analysis » design » coding » testing Analysis
Methods used to design and construct a solution to a problem Solutions to problems need to be designed and developed rigorously. The use of formal methods enables the process to be clearly shown for others to understand the proposed solution. The methods are: » structure diagrams » flowcharts » pseudocode Structure diagrams - can be used to show top-down design in a diagrammatic form. Structure diagrams are hierarchical, showing how a computer system solution can be divided into sub-systems with each level giving a more detailed breakdown. If necessary, each sub-system can be further divided. Example: Alarm app for a smart phone Activity; Break down the ‘Check time’ sub-system from the smart phone alarm app into further sub- systems Flowcharts A flowchart shows diagrammatically the steps required to complete a task and the order that they are to be performed. These steps, together with the order, are called an algorithm. Flowcharts are an effective way to communicate how the algorithm that makes up a system or sub-system works. Example; Checking for the alarm time Flowchart for check time sub-system
Pseudocode Pseudocode is a simple method of showing an algorithm. It describes what the algorithm does by using English key words that are very similar to those used in a high-level programming language. Data items to be processed by the algorithm are given meaningful names in the same way that variables and constants are in a high-level programming language. However, pseudocode is not bound by the strict syntax rules of a programming language. It does what its name says, it pretends to be programming code! Pseudocode is used to help you understand algorithms easily;
For example: » Comparisons made by using comparison operators, where comparisons are made from left to right, for example: A > B means ‘A is greater than B’ Comparisons can be simple or more complicated, for example:
The algorithm below that checks if a percentage mark is valid and whether it is a pass or a fail. This makes use of two IF statements; the second IF statement is part of the first ELSE path. This is called a nested IF. Activity; Re-write the algorithm to check for a mark between 0 and 20 and a pass mark of 10. CASE OF … OTHERWISE … ENDCASE For a CASE statement the value of the variable decides the path to be taken. Several values are usually specified. OTHERWISE is the path taken for all other values. The end of the statement is shown by ENDCASE. Have a look at the algorithm below that specifies what happens if the value of Choice is 1, 2, 3 or 4. The pseudocode for iteration When some actions performed as part of an algorithm need repeating this is called iteration. Loop structures are used to perform the iteration.
REPEAT … UNTIL loop This loop structure is used when the number of repetitions/iterations is not known and the actions are repeated UNTIL a given condition becomes true. The actions in this loop are always completed at least once. This is a post-condition loop as the test for exiting the loop is at the end of the loop. WHILE … DO … ENDWHILE loop This loop structure is used when the number of repetitions/iterations is not known and the actions are only repeated WHILE a given condition is true. If the WHILE condition is untrue then the actions in this loop are never performed. This is a pre-condition loop as the test for exiting the loop is at the beginning of the loop. The pseudocode for input and output statements INPUT and OUTPUT are used for the entry of data and display of information. Sometimes READ can be used instead of INPUT but this is usually used for reading from files. Also, PRINT can be used instead of OUTPUT if a hard copy is required. INPUT is used for data entry; it is usually followed by a variable where the data input is stored, for example: OUTPUT is used to display information either on a screen or printed on paper; it is usually followed by a single value that is a string or a variable, or a list of values separated by commas, for example:
Explaining the purpose of an algorithm An algorithm sets out the steps to complete a given task. This is usually shown as a flowchart or pseudocode, so that the purpose of the task and the processes needed to complete it are clear to those who study it. You will be able to practice this skill as you become more familiar with writing and finding and correcting errors in algorithms. Example; Output an alarm sound The purpose of the following pseudocode is to output the alarm sound at the appropriate time. The processes are: waiting 10 seconds, getting the current time, checking the current time with the alarm time, and outputting the alarm sound when the times match. Standard methods of solution The ability to repeat existing methods is very important in the design of algorithms; when an algorithm is turned into a program the same methods may be repeated many thousands of times. You need to be able to use and understand these standard methods used in algorithms:
Maximum, minimum and average Finding the largest and smallest values in a list are two standard methods that are frequently found in algorithms, for example, finding the highest and lowest mark awarded to a class of students. If the largest and smallest values are not known, an alternative method is to set the maximum and minimum values to the first item in the list. For example, using this method to find the highest and lowest mark awarded to a class of students. Calculating the average (mean) of all the values in a list is an extension of the totalling method, for example, calculating the average mark for a class of students
Linear search A search is used to check if a value is stored in a list, performed by systematically working through the items in the list. This is called a linear search, which inspects each item in a list in turn to see if the item matches the value searched for. For example, searching for a name in a class list of student names, where all the names stored are different: Bubble sort This method of sorting is called a bubble sort. Each element is compared with the next element and swapped if the elements are in the wrong order, starting from the first element and finishing with next-to-last element. Once it reaches the end of the list, we can be sure that the last element is now in the correct place. However, other items in the list may still be out of order. Each element in the list is compared again apart from the last one because we know the final element is in the correct place. This continues to repeat until there is only one element left to check or no swaps are made.
Range check A range check checks that the value of a number is between an upper value and a lower value. For example, checking that percentage marks are between 0 and 100 inclusive: Length check A length check checks either: that data contains an exact number of characters, for example that a password must be exactly eight characters in length so that passwords with seven or fewer characters or nine or more characters would be rejected, for instance or that the data entered is a reasonable number of characters, for example, a family name could be between two and thirty characters inclusive so that names with one character or thirty-one or more characters would be rejected.
Type check A type check checks that the data entered is of a given data type, for example, that the number of brothers or sisters would be an integer (whole number). Presence check A presence check checks to ensure that some data has been entered and the value has not been left blank, for example, an email address for an online transaction must be completed. Format check and check digit Format check A format check checks that the characters entered conform to a pre-defined pattern Check digit