top of page

Search CSNewbs

286 items found for ""

  • Computer Science Newbies

    C omputer S cience Newb ie s Popular CSNewbs topics: Programming PYTHON GCSE Computer Science OCR GCSE Computer Science EDUQAS OCR Cambridge Technicals Level 3 IT You are viewing the mobile version of CSNewbs. The site will appear better on a desktop or laptop . Programming HTML CSNewbs last updated: Monday 20th January 2025 Over 488,000 visits in the last year! About CSNewbs

  • 2.3 - Units - OCR GCSE (J277 Spec) | CSNewbs

    2.3: Data Units Exam Board: OCR Specification: J277 All computer systems communicate , process and store data using binary . Binary is a number system consisting entirely of 0s and 1s . Why do computers use binary? Computer systems consist of billions of tiny transistors which are switches that only have two values - on (1 ) or off (0 ). Therefore all data must be represented and processed in this way. Everything that a computer needs to process must be converted into a binary format including text , images , videos and audio . 0010 1011 0101 0101 0110 0111 0101 0001 0101 0101 0101 0100 1010 1010 1010 1010 1111 1110 0010 1001 0100 1001 0010 0111 0111 0101 0011 1010 1000 0101 0110 0111 0000 1010 1010 0011 1101 1001 0010 1101 0010 0100 1001 0011 1010 1001 0101 0101 0010 0101 0111 0101 0101 1000 1011 0111 Units of Data Storage 0 / 1 All data in a computer system is made up of bits . A single bit is a 0 or a 1 . 4 bits (such as 0101 or 1101) is called a nibble . 1,000 bytes is called a kilobyte . A kilobyte can store a short email . A 8 bits is called a byte . A byte can store a single character . 1,000 kilobytes is called a megabyte . A megabyte can store about a minute of music . 1,000 megabytes is called a gigabyte . A gigabyte can store about 500 photos . 1,000 terabytes is called a petabyte . A petabyte can store about 1.5 million CDs . 1,000 gigabytes is called a terabyte . A terabyte can store about 500 hours of films . This video shows some real-world examples to help you understand the scale of the different data storage units . Important note - this video was originally made for a different exam board and uses a scale of 1,024 between data units. Technically 1,000 bytes is a kilobyte . 1,024 bytes is a kibibyte . In the OCR GCSE exam you can use either 1,000 or 1,024 but as it is a non-calculator paper it makes sense to use 1,000 for simpler calculations . Calculating Data Capacity Requirements It is important to be able to calculate the required storage capacity for a given set of data . Example: A local DJ has a USB memory stick with a capacity of 32GB . There is currently only 9GB of space remaining . Each song is 6MB . How many songs can be stored on the remaining space of the USB stick? Solution: Because each song is recorded in megabytes but the USB stick capacity is measured in gigabytes , the values must be converted into the same storage unit . 9GB x 1000 = 9000MB 9000MB ÷ 6MB = 1,500 songs Watch on YouTube Q uesto's Q uestions 2.3 - Data Units: 1. Explain why computer systems use binary to represent data. [ 2 ] 2. Put the following data storage units in order from smallest to largest : a . kilobyte - gigabyte - byte - megabyte - nibble - bit [3 ] b. gigabyte - petabyte - kilobyte - byte - terabyte - megabyte [ 3 ] 3. A hard drive contains 25GB of remaining available storage space. Tim is an animator backing up video files. Each file is 200MB . How many files can he fit on the hard drive? [ 2 ] 4. Samantha is a musician. She has compressed each song to 900KB . Her USB memory stick contains 1.2GB of free storage. How many songs can she fit on the USB stick? [ 2 ] 5. A CD has a capacity of 650MB . How many 0.2GB audio files can be stored on the CD? [ 2 ] 0101 2.2 - Secondary Storage Theory Topics 2.4a - Number Storage

  • 2.2 - Secondary Storage - OCR GCSE (J277 Spec) | CSNewbs

    2.2: Secondary Storage Exam Board: OCR Specification: J277 Secondary storage is non-volatile storage used to save and store data that can be accessed repeatedly. Secondary storage is not directly embedded on the motherboard (and possibly even external ) and therefore further away from the CPU so it is slower to access then primary storage . Storage Characteristics you should know: CAPACITY : The maximum amount of data that can be stored on the device. DURABILITY : The strength of the device, to last without breaking . PORTABILITY : How easy it is to carry the device around . ACCESS SPEED : How quickly data on the device can be read or edited . COST : The average price it costs to purchase the storage device. RELIABILITY : The likelihood of the device continuing to perform well over time . Magnetic Storage A magnetic hard disk drive (HDD ) is the most common form of secondary storage within desktop computers. A read/write head moves nanometres above the disk platter and uses the magnetic field of the platter to read or edit data. An obsolete (no longer used) type of magnetic storage is a floppy disk but these have been replaced by solid state devices such as USB sticks which are much faster and have a much higher capacity. Another type of magnetic storage that is still used is magnetic tape . Magnetic tape has a high storage capacity but data has to be accessed in order (serial access ) so it is generally only used by companies to back up or archive large amounts of data . Magnetic Storage Characteristics (Hard Disk Drive): ✓ - Large CAPACITY and cheaper COST per gigabyte than solid state . ✓ - Modern external HDDs are small and well protected so they are DURABLE and PORTABLE , however because of the moving parts, they should not be moved when powered on because it can damage the device. X - Slower ACCESS SPEED than solid state but faster than optical storage . Optical Storage Optical storage uses a laser to project beams of light onto a spinning disc, allowing it to read data from a CD , DVD or Blu-Ray . This makes optical storage the slowest of the four types of secondary storage. Disc drives are traditionally internal but external disc drives can be bought for devices like laptops. Magnetic Disks are spelled with a k and Optical Discs have a c. Optical Storage Characteristics: X - Low CAPACITY : 700 MB (CD ), 4.7 GB (DVD ), 25 GB (Blu-ray ). X - Not DURABLE because discs are very fragile and can break or scratch easily. ✓ - Discs are thin and very PORTABLE . Also very cheap to buy in bulk. X - Optical discs have the Slowest ACCESS SPEED . Solid State Storage There are no moving parts in solid state storage. SSD s (Solid State Drives ) are replacing magnetic HDDs (Hard DIsk Drives) in modern computers and video game consoles because they are generally quieter , faster and use less power . A USB flash drive ( USB stick ) is another type of solid state storage that is used to transport files easily because of its small size. Memory cards , like the SD card in a digital camera or a Micro SD card in a smartphone , are another example of solid state storage. Solid State Characteristics: X - More expensive COST per gigabyte than magnetic . ✓ - Usually DURABLE but cheap USB sticks can snap or break . ✓ - The small size of USB sticks and memory cards mean they are very PORTABLE and can fit easily in a bag or pocket. ✓ - Solid State storage have a high CAPACITY and the fastest ACCESS SPEED because they contain no moving parts . Q uesto's Q uestions 2.2 - Secondary Storage: 1. Rank magnetic , optical and solid-state storage in terms of capacity , durability , portability , speed and cost . For example, magnetic has the highest capacity , then solid-state, then optical. This could be completed in a table . [15 ] 2. Justify which secondary storage should be used in each scenario and why it is the most appropriate: a. Sending videos and pictures to family in Australia through the post . [ 2 ] b. Storing a presentation to take into school . [ 2 ] c. Storing project files with other members of a group to work on together . [ 2 ] d. Backing up an old computer with thousands of files to a storage device. [ 2 ] 2.1 - Primary Storage Theory Topics 2.3 - Data Units

  • 2.4b - Character Storage - OCR GCSE (J277 Spec) | CSNewbs

    2.4b: Character Storage Exam Board: OCR Specification: J277 What is a Character Set? A character set is a table that matches together a character and a binary value . Each character in a character set has a unique binary number matched with it . Character sets are necessary as they allow computers to exchange data and humans to input characters . Two common character sets are ASCII and Unicode : H = 01001000 ASCII Unicode ASCII (American Standard Code for Information Interchange ) is a common character set which does not take up much memory space . It is important to understand that the number of characters that can be stored is limited by the bits available - ASCII uses 1 byte (8 bits ) which only gives 256 possible characters . This is enough for the English language but it can’t be used for other languages or all punctuation symbols. Unicode is a more popular character set because it uses 2 bytes (16 bits ) that allow for 65,536 possible characters . The extra byte allows many different languages to be represented , as well as thousands of symbols and emojis . However Unicode requires more memory to store each character than ASCII as it uses an extra byte . Character sets are logically ordered . For example, the binary code for A is 01000001 , B is 01000010 and C is 01000011 as the code increases by 1 with each character. The file size of a text file is calculated as shown below: bits per character x number of characters Example: A small text file uses the ASCII character set (which uses 8 bits per character ). There are 300 characters in the file . 300 x 8 = 2,400 bits This could be simplified as 300 bytes or 0.3 kilobytes . Q uesto's Q uestions 2.4b - Character Storage: 1. What is a character set and why are they needed ? [ 2 ] 2. Describe 3 differences between ASCII and Unicode . [6 ] 3. The binary code for the character P in ASCII is 01010000 . State what the binary code for the character S would be. [1 ] 4a. A text file uses the ASCII character set and contains 400 characters . What would the file size be in kilobytes ? [ 2 ] 4b. A text file uses the Unicode character set and contains 150 characters . What would the file size be in kilobytes ? [ 2 ] File Size of Text Files 01101010 = 256 possible characters 8 bits (1 byte) 1000101101001111 = 65,536 possible characters 16 bits (2 bytes) 2.4a - Number Storage Theory Topics 2.4c - Image Storage

  • 2.4a - Number Storage - OCR GCSE (J277 Spec) | CSNewbs

    2.4a: Number Storage Exam Board: OCR Specification: J277 What is binary? By now you should know that computer systems process data and communicate entirely in binary . Topic 2.3 explained different binary storage units such as bits (a single 0 or 1), nibbles (4 bits) and bytes (8 bits). Binary is a base 2 number system. This means that it only has 2 possible values - 0 or 1 . What is denary? Denary (also known as decimal ) is the number system that you've been using since primary school. Denary is a base 10 number system. This means that it has 10 possible values - 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 . How to convert from binary to denary: How to convert from denary to binary: Binary & Denary What is hexadecimal? Hexadecimal is a base 16 number system. This means that it has 16 possible values - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F . Hexadecimal is used as a shorthand for binary because it uses fewer characters to write the same value . This makes hexadecimal less prone to errors when reading or writing it , compared to binary. For example, 100111101011 in binary is 9EB in hexadecimal. Hexadecimal only uses single-character values. Double-digit numbers are converted into letters - use the table on the right to help you understand. How to convert from binary to hexadecimal: How to convert from hexadecimal to binary: Hexadecimal Converting from denary to hexadecimal / hexadecimal to denary To convert from denary to hexadecimal or the other way round you must convert to binary first . Denary > Binary > Hexadecimal Hexadecimal > Binary > Denary Use the videos on this page if you need help converting to or from binary. The most common number systems question in exams are from denary to hexadecimal or from hexadecimal to denary so make sure that you practice these conversions. Binary Addition Binary addition is a method of adding binary values without having to convert them into denary. How to add binary numbers: What is an overflow error? An overflow error occurs when a binary value is too large to be stored in the bits available . With a byte (8 bits ) the largest number that can be held is 255 . Therefore any sum of two binary numbers that is greater than 255 will result in an overflow error as it is too large to be held in 8 bits . What is binary shift? Binary shift is used to multiply and divide binary numbers . The effect of shifting left is to multiply a binary number. The effect is doubled by each place that is shifted . x The effect of shifting right is to divide a binary number. ÷ Shifting by 1 has an effect of 2 . Shifting by 2 has an effect of 4 . Shifting by 3 has an effect of 8 . For example, shifting left by 2 places has an effect of multiplying by 4 . Another example: Shifting right by 3 places has an effect of diving by 8 . How to shift a binary number: Q uesto's Q uestions 2.4a - Number Systems: 1. Explain why hexadecimal numbers are used as an alternative to binary . Use an example . [ 3 ] 2. Convert the following values from binary to denary : a. 00101010 b. 11011011 c. 01011101 d. 11101110 e. 01011111 [1 each ] 3. Convert the following values from denary to binary : a. 35 b. 79 c. 101 d. 203 e. 250 [1 each ] 4. Convert the following values from binary to hexadecimal : a. 11110101 b. 01100111 c. 10111010 d. 10010000 e. 11101001 [1 each ] 5. Convert the following values from hexadecimal to binary : a. C2 b. 8A c. DE d. 54 e. F7 [1 each ] 6. Convert the following values from denary to hexadecimal : a. 134 b. 201 c. 57 d. 224 e. 101 [1 each ] 7. Convert the following values from hexadecimal to denary : a. 32 b. A5 c. 88 d. C0 e. BE [1 each ] Binary Addition: 1. Explain what an overflow error is. [ 2 ] 2. Add together the following binary values. If an overflow error occurs you must state one has occurred. a. 010110012 and 010001012 [2 ] b. 110110112 and 010111012 [2 ] c. 001101102 and 011010112 [2 ] d. 110110112 and 010101112 [2 ] e. 011011012 and 110101102 [2 ] Binary Shift: 1a. Draw a diagram to show the effect of multiplying and dividing a binary number . [2 ] 1b. Draw a diagram or table to show the effect a shift has for each place from 1 to 4 . For example, a shift of 1 place has an effect of 2. [4 ] 2. State the effect of the following shifts: a. Shift right by 2 places. b. Shift left by 1 place. c. Shift left 3 places. d. Shift right by 4 places. [ 1 each ] 3. Shift the following binary numbers and state the effect of the shift: a. 10101011 : Shift left by 2 places. b. 11101100 : Shift right by 3 place. c. 00001011 : Shift right by 2 places. d. 01101110 : Shift left by 1 place. [ 2 each ] Binary Shifts Watch on YouTube Watch on YouTube Watch on YouTube Watch on YouTube Watch on YouTube Watch on YouTube Click the banners below to try self-marking quizzes (Google Form) on these topics. Binary to Denary: Binary to Hexadecimal: Denary to Binary: Hexadecimal to Binary: 2.3 - Data Units Theory Topics 2.4b - Character Storage

  • 1.1b - Registers & FE Cycle - OCR GCSE (J277 Spec) | CSNewbs

    1.1b: Registers & The F-E Cycle Exam Board: OCR Specification: J277 The Fetch - Execute (F - E) cycle is performed by the CPU millions of times every second. This cycle is how the CPU processes data and instructions for each program or service that requires its attention. Important Registers A register is a small storage space for temporary data in the CPU . Each register has a specific role . There are three essential registers used in the F-E cycle : Program Counter (PC) A register that tracks the RAM address of the next instruction to be fetched . Memory Address Register (MAR) Stores the RAM address of the current instruction (or data ) the CPU needs to access . Memory Data Register (MDR) The MDR stores the instruction that has been transferred from RAM to the CPU . Current Instruction Register (CIR) A register that stores the instruction that has been fetched from RAM , and is about to be decoded or executed . Accumulator (ACC) The ACC stores the result of mathematical or logical calculations . Fetch - Execute Cycle The essential idea of the F-E cycle is that instructions are fetched from RAM , to be decoded (understood) and executed (processed) by the CPU . 1. The Program Counter (PC ) register displays the address in RAM of the next instruction to be processed . This value is copied into the Memory Address Register (MAR ). 0054 2. The PC register is increased by 1 . This prepares the CPU for the next instruction to be fetched. 0055 3. The CPU checks the address in RAM which matches the address held in the MAR . 0054 4. The instruction in RAM is transferred to the Memory Data Register (MDR ). 5. The instruction in the MDR is copied into the Current Instruction Register (CIR ). MDR MDR CIR 6. The instruction in the CIR is decoded (understood) and executed (processed). Any result of an execution is stored in the Accumulator (ACC ) register. CIR ACC 7. The cycle repeats by returning to the first step and checking the program counter for the address of the next instruction . Q uesto's Q uestions 1.1b - Registers & The F-E Cycle: 1 . What is the purpose of the registers ? [1 ] 2 . Describe the purpose of each register : a. The Program Counter (PC) [ 2 ] b. The Memory Address Register (MAR) [ 2 ] c. The Memory Data Register (MDR) [ 2 ] d. The Current Instruction Register (CIR) [ 2 ] e. The Accumulator (ACC) [ 2 ] 3. Draw a diagram with icons and words to show the steps of the Fetch - Execute cycle . [7 ] 1.1a - The CPU Theory Topics 1.2 - CPU Performance

  • 1.3 - Embedded Systems - OCR GCSE (J277 Spec) | CSNewbs

    1.3 - Embedded Software: 1. What is an embedded system ? [3 ] 2a. Give two examples of an embedded system. [ 2 ] 2b. Research and describe another two examples of an embedded system. [ 4 ] 1.3: Embedded Systems Exam Board: OCR Specification: J277 Example: A washing machine has a control chip that manages the different program cycles. An embedded system is a computer system built into a larger machine to provide a means of control . Embedded systems perform a specific pre-programmed task which is stored in ROM . An embedded system uses a combination of hardware and software . They perform only specific tasks and often have a small amount of storage and low processing power . Example: A traffic light has a control chip that determines when to change to a green or red light. Q uesto's Q uestions 1.2 - CPU Performance 2.1 - Primary Storage Theory Topics

  • 2.1 - Primary Storage - OCR GCSE (J277 Spec) | CSNewbs

    2.1: Primary Storage (Memory) Exam Board: OCR Specification: J277 Primary vs Secondary Storage Storage in a computer system is split into two categories: Primary Storage: Very quick because it is directly accesse d by the CPU . Typically smaller in storage size . Sometimes called ‘main memory’ . Includes RAM and ROM . Volatile vs Non-Volatile Storage Storage is also split into two types - volatile and non-volatile . Volatile storage is temporary - data is lost whenever the power is turned off . Example: RAM Non-volatile storage saves the data even when not being powered . Data can be stored long-term and accessed when the computer is switched on . Example: ROM Why do Computers need Primary Storage? Primary storage is low-capacity , internal storage that can be directly accessed by the CPU . Program instructions and data must be copied from the hard drive into RAM to be processed by the CPU because primary storage access speeds are much faster than secondary storage devices like the hard drive. Types of Primary Storage (Memory) Random Access Memory (RAM) Read-Only Memory (ROM) RAM is volatile (temporary) storage that stores all programs that are currently running . RAM also stores parts of the operating system to be accessed by the CPU. RAM is made up of a large number of storage locations, each can be identified by a unique address . ROM is non-volatile storage that cannot be changed . ROM stores the boot program / BIOS for when the computer is switched on. The BIOS then loads up the operating system to take over managing the computer. RAM ( R andom A ccess M emory) ROM ( R ead O nly M emory) Virtual Memory Programs must be stored in RAM to be processed by the CPU . Even if there is insufficient space in RAM for all programs the computer can use the hard disk drive (HDD ) as an extension of RAM - this is called virtual memory . If new data is needed to be stored in RAM then unused data in RAM is moved to the hard drive so the new data can be transferred into RAM . If the original data is required again, it can be moved back from virtual memory into RAM . Using virtual memory is beneficial because it allows more programs to be run at the same time with less system slow down . Q uesto's Q uestions 2.1 - Primary Storage (Memory): 1. Describe the differences between primary and secondary storage . [ 6 ] 2. Explain the difference between volatile and non-volatile storage . State an example of both types. [ 4 ] 3. Explain why the computer requires primary storage . [ 2 ] 4. For each type of memory below, describe it and state what information is stored within it: a . Random Access Memory (RAM) [3 ] b. Read-Only Memory (ROM) [ 3 ] c. Virtual memory [ 3 ] Secondary Storage: ( Section 2.2 ) Slower because it is not directly accessed by the CPU . Typically larger in storage size . Used for the long-term storage of data and files because it is non-volatile . Includes magnetic , optical and solid state storage. 1.3 - Embedded Systems Theory Topics 2.2 - Secondary Storage

  • OCR GCSE Topic List | CSNewbs

    OCR GCSE Computer Science (J277) These pages are based on the J277 OCR GCSE Computer Science 2020 specification . This website is in no way affiliated with OCR . Component One 1. Systems Architecture 1.1a - The CPU 1.1b - Registers & FE Cycle 1.2 - CPU Performance 1.3 - Embedded Systems 2. Memory & Storage 2.1 - Primary Storage 2.2 - Secondary Storage 2.3 - Units 2.4a - Number Storage 2.4b - Character Storage 2.4c - Image Storage 2.4d - Sound Storage 2.5 - Compression 3. Networks 3.1a - Network Types & Performance 3.1b - Network Hardware & Internet 3.2a - Wired & Wireless networks 3.2b - Protocols & Layers 4. Network Security 4.1 - Network Threats 4.2 - Preventing Vulnerabilities 5. Systems Software 5.1 - Operating Systems 5.2 - Utility Software 6. Impacts 6.1a - Impacts of Technology 6.1b - Legislation Component Two 1. Algorithms 1.1 - Computational Thinking 1.2 - Designing Algorithms 1.3 - Searching & Sorting Algorithms 2. Programming Fundamentals 2.1 - Programming Fundamentals 2.2 - Data Types 2.3 - Additional Programming Techniques 3. Producing Robust Programs 3.1 - Defensive Design 3.2 - Testing 4. Boolean Logic 4.1 - Boolean Logic 5. Languages & IDEs 5.1 - Languages & Translators 5.2 - Integrated Development Environment

  • 1.2 - CPU Performance - OCR GCSE (J277 Spec) | CSNewbs

    1.2: CPU Performance Exam Board: OCR Specification: J277 The performance of a computer system is affected by three main factors: Cache Memory What is cache memory? Cache memory is temporary storage for frequently accessed data . How does cache memory improve performance? Cache memory is closer to the CPU than RAM , meaning that it can provide data and instructions to the CPU at a faster rate . A computer with more cache memory (e.g. 8GB instead of 4GB) should have a higher performance because repeatedly used instructions can be stored and accessed faster . What is the limitation of cache memory? Cache memory is costly, so most computers only have a small amount . Clock Speed What is clock speed? Clock speed is the measure of how quickly a CPU can process instructions . Clock speed is measured in Gigahertz (GHz) . A typical desktop computer might have a clock speed of 3.5 GHz . This means it can perform 3.5 billion cycles a second . How does clock speed improve performance? The faster the clock speed, the faster the computer can perform the FDE cycle resulting in better performance because more instructions can be processed each second . How does overclocking and underclocking affect performance? Default clock speed: 3.5 GHz Underclocking Overclocking 3.9 GHz 3.1 GHz Overclocking is when the computer's clock speed is increased higher than the recommended rate. This will make the computer perform faster, but it can lead to overheating and could damage the machine . Underclocking is when the computer's clock speed is decreased lower than the recommended rate. This will make the computer perform slower but will increase the lifespan of the machine . Number of Cores What is a core? A core is a complete set of CPU components (control unit, ALU and registers). Each core is able to perform its own FDE cycle . A multi-core CPU has more than one set of components within the same CPU. How does the number of cores improve performance? In theory, a single-core processor can execute one instruction at a time , a dual-core processor can execute two instructions, and a quad-core can execute four instructions simultaneously . Therefore, a computer with more cores will have a higher performance because it can process more instructions at once . What are the limitations of having more cores? If one core is waiting for another core to finish processing, performance may not increase at all. Some software is not written to make use of multiple cores , so it will not run any quicker on a multi-core computer. Q uesto's Q uestions 1.2 - CPU Performance: Cache Size & Levels 1a. What is cache memory ? [ 2 ] 1b. Describe two ways that more c ache memory will mean performance is higher . [ 4 ] 1c. Explain why most computers only have a small amount of cache memory. [ 1 ] Clock Speed 2a. What is clock speed ? What is it measured in? [ 2 ] 2b. Explain how a higher clock speed improves performance . [ 2 ] 2c. Explain the terms 'overclocking ' and 'underclocking ' and explain the effects of both on the performance of a computer. [ 4 ] Number of Cores 3a. What is a core ? [ 2 ] 3b. Explain why a quad-core processor should have a higher performance than a dual-core processor . [ 3 ] 3c. Explain two reasons why having more cores doesn't necessarily mean the performance will be better . [ 2 ] 1.1b - Registers & FE Cycle 1.3 - Embedded Systems Theory Topics

  • 2.3 - Additional Programming Techniques - OCR GCSE (J277 Spec) | CSNewbs

    2.3: Additional Programming Techniques Exam Board: OCR Specification: J277 This section of the specification includes programming topics that are outlined in 1.2 (Designing Algorithms). You must have an understanding of more complex programming techniques , such as how to manipulate strings , handle files and use subprograms . The best practice for learning is to try the tasks in the Python pages on this website (see the link to the right). Visit the Python section of CSNewbs ---> Subprograms What is a subprogram? Large programs are often broken down into smaller subprograms (also called subroutines ). Each subprogram focuses on a specific function of the code, helping to decompose a complex problem into more manageable chunks . Defining subprograms A subprogram is defined (identified) using the def command in Python. A program may use many subprograms , which are usually defined at the start of the code . Calling subprograms Running a line of code that includes the name of a subprogram will call (activate) it. When called , the program will run the subprogram code before returning back to the line that called it . Subprograms are only run when called , so depending on decisions made, a program may end without calling every (or any) subroutine. Parameters A parameter is a value that is passed into a subprogram when it is called , allowing the value to be used within the subprogram . A subprogram may not use a parameter , e.g. multiply() , or one parameter , e.g. multiply(num) , or several e.g. multiply(num1,num2) . Any parameters must be identified when the subprogram is defined , e.g. def multiply(num): Return The return command will send a value back to the line the subprogram was called on, allowing it to be used there . For example, the 'quad' subprogram in the example below returns the value of the 'result' variable back to the main program, allowing it to be printed . A subprogram will end either by reaching the last line of code within it, or when it reaches a return command . Subprograms that return a value are called functions . Subprogram example This subprogram is defined using the identifier 'quad ' with a parameter named number . The subprogram is called in the main program, multiplies the number passed in as a parameter by 4 and returns a value back to the main program to be printed. def quad (number): result = number * 4 return result #Main Program number = int ( input ( "Enter a number: " )) print ( "The number quadrupled is" , quad(number)) Enter a number: 5 The number quadrupled is 20 Functions and Procedures There are two types of subprograms . A function is a subprogram that returns a value , using the return command, which allows the value to be used in the line of code the function was called in. The 'divide' function below returns the value of the variable 'total' to the main program to be printed. A procedure is a subprogram that does not return a value . Example of a Procedure def multiply (num): total = num * 2 print ( "The number doubled is" , total) #Main Program num = int ( input ( "Enter a number: " )) multiply(num) Enter a number: 4 The number doubled is 8 Example of a Function def divide (num): total = num / 2 return total #Main Program num = int ( input ( "Enter a number: " )) print ( "The number halved is" , divide(num)) Enter a number: 9 The number halved is 4.5 Advantages of using subprograms Subprograms break a complex program down into smaller parts , making it easier to design and test . Each subroutine can be tested separately and abstraction can be used to simplify a complicated problem . Using subprograms allows code to be easily reused in other programs , as it has already been written , making it quicker to develop new programs or build on existing work. Using subprograms avoids code repetition , as they can be called as many times as necessary . This makes programs shorter and quicker to develop , making them easier to maintain and debug . Work can easily be split up between team members to work on different subprograms at the same time . Array An array is a static data structure that can hold a fixed number of data elements . Each data element must be of the same data type i.e. real, integer, string. The elements in an array are identified by a number that indicates their position in the array. This number is known as the index. The first element in an array always has an index of 0 . You should know how to write pseudo code that manipulates arrays to traverse , add , remove and search for data . The following steps use Python as an example, although Python does not use arrays and uses a similar data structure called a list (that can change in size as the program runs ). See the 8a and 8b Python pages for tasks on how to use lists . What Traversing an Array To traverse (' move through ') an array a for loop can be used to display each data element in order. Example code for traversing: Output: 'Inserting' a value In an array the size is fixed so you cannot insert new values, but you can change the value of elements that already exist. Overwriting the fourth element (Daphne) with a new value (Laura) will change it from Daphne to Laura. Example code for inserting: Output: 'Deleting' a value In an array the size is fixed so you cannot delete values, but you can overwrite them as blank . Overwriting the second element (Shaggy) with a blank space makes it appear deleted. Example code for deleting: Output: Searching an Array For large arrays a for loop is needed to search through each element for a specific value . This example checks each name to see if it is equal to Velma. Example code for searching: Output: Two-Dimensional Array Often the data we want to process comes in the form of a table . The data in a two dimensional array must still all be of the same data type , but can have multiple rows and columns . The two-dimensional array to the right shows the characters from Scooby Doo along with their associated colour and their species. Each value in the array is represented by an index still, but now the index has two values . For example [3] [0] is 'Daphne'. Unless stated in an exam , measure row first , then column . Searching a two-dimensional array: To print a specific data element you can just use the index number like Daphne above. To search for a specific value you will need two for loops , one for the row and another for the values of each row . The example to the right is looking for the value of ' Velma ' and when it is found it prints the associated data from the whole row . Example code for printing: Output: Example code for searching: Output: Records Unlike arrays, records can store data of different data types . Each record is made up of information about one person or thing . Each piece of information in the record is called a field (each row name). Records should have a key field - this is unique data that identifies each record . For example Student ID is a good key field for a record on students as no two students can have the same Student ID. A 2D array may be used to represent database tables of records and fields . SQL SQL (structured query language ) is a language that can be used to search for data in a database . The format of an SQL statement is: SELECT field1, field2, field3… FROM table WHERE criteria Example of an SQL statement using the Cars table: SELECT Make, Colour FROM Cars WHERE Miles > 1000 AND Age > 8 Cars table SQL uses wildcards which are symbols used to substitute characters . The * symbol represents ALL fields . Example: SELECT * FROM Cars WHERE Colour = “blue” Click the banner above to try a self-marking quiz (Google Form) on this topic. Q uesto's Q uestions 2.3a - Additional Programming Techniques: 1a. Describe what the following terms mean: subprogram , parameter , function , procedure . [ 2 each ] 1b. Describe three advantages of using subprograms . [ 6 ] 2. Describe the differences between a 1D array , 2D array and record . [ 3 ] 3. A one-dimensional array looks like this: TigerBreeds("Sumatran","Indian","Malayan,"Amur") Write the code to: a. Print the element with the index of 3. [ 2 ] b. Change Indian to South China. [ 2 ] c. Remove the Amur element. [ 2 ] d. Search through the array for 'Malayan'. [ 2 ] 4a. Use the Cars table above to write the SQL statement to display the make and miles for cars that are grey OR blue . [ 3 ] 4b. Write an SQL statement to display all fields for cars that are 10 years old or less . [ 3 ] 2.2 Data Types Theory Topics 3.1 - Defensive Design

  • 1.1a - The CPU - OCR GCSE (J277 Spec) | CSNewbs

    Exam Board: OCR 1.1a: The CPU Specification: J277 The Central Processing Unit ( CPU ) is the most important component in any computer system. Like many components of a computer, it is attached to the motherboard . The purpose of the CPU is to process data and instructions by constantly repeating the fetch - execute cycle . CPU Components The Control Unit (CU ) sends control signals to direct the operation of the CPU . Control signals and timing signals are sent to the ALU and other components such as RAM . It also decodes instructions as part of the F-E cycle . ALU stands for ‘ Arithmetic and Logic Unit ’. It performs simple calculations and logical operations . A register is a temporary storage space for one instruction or address . Different registers are used during the FE cycle . Cache memory is used to temporarily store data that is frequently accessed . Cache memory is split into different levels . Cache is slower to access than the registers but much faster than RAM . Computer Architecture The way a computer is designed and structured is known as its architecture . The most common type of computer architecture is Von Neumann . Von Neumann Architecture This architecture is named after John von Neumann who developed the concept of a stored program computer in the 1940s. Before being able to store programs in memory , instructions had to be manually input by a human. A computer with Von Neumann architecture stores both program instructions and data in the same memory (RAM ). Other architectures like Harvard have two separate memories - one for program instructions and another for data. Data is transferred between components on pathways called buses . Q uesto's Q uestions 1.1a - The CPU: 1a. What does 'CPU ' stand for ? [1 ] 1b. What is the purpose of the CPU ? [ 2 ] 2. Draw a diagram of the CPU , and l abel the four main components . [ 4 ] 3. Describe the purpose of: a. The Control Unit [ 2 ] b. The ALU [ 2 ] c. The registers [ 2 ] d. Cache memory [ 2 ] 4. Describe the key feature of Von Neumann architecture . [ 2 ] 1.1b - Registers & FE Cycle Theory Topics

bottom of page