Search CSNewbs
304 results found with an empty search
- 4.7 - Sound Representation - Eduqas GCSE (2020 Spec) | CSNewbs
Learn about how sounds are represented in a computer system including how analogue sound waves are converted into binary. Also, learn about sample rate, bit depth and metadata. Based on the 2020 Eduqas (WJEC) GCSE specification. 4.7: Sound Representation Exam Board: Eduqas / WJEC Specification: 2020 + Converting Analog Sound to Binary To store sound on a computer analog sound waves must be converted in to digital data ( binary ). The sound is sampled using an ADC (Analog to Digital Convertor) and stored as a binary value (such as 01010011) called a sample . 0010 1011 0101 0101 Analog sound wave ADC (Analog to Digital Converter) Binary sample Sampling an Analog Sound Wave Digital sampling is discrete (separate) and not continuous like analog waves. To get the highest quality sound, many samples are taken to recreate the analog wave as closely as possible . Sample Rate The sample rate is the number of samples taken per second . It is measured in kilohertz (kHz), for example CD quality is 44.1kHz (44,100 samples per second). The higher the sample rate , the better the audio quality as the digital data more closely resembles an analog wave . However, higher sample rates result in larger file sizes because more data is stored for each individual sample. A low sample rate will result in a low-quality sound because the digital data does not closely resemble the original analog wave . A higher sample rate will result in a higher-quality sound because the digital data more closely resembles the original analog wave . Improving Audio Quality Bit Depth Bit Rate The bit rate is defined as the amount of audio data processed per second . It is measured in kilobytes per second (kbps ). The bit rate is calculated by multiplying the sample rate and bit depth . Because the bit rate is the measure of the sample rate and bit depth multiplied together, the higher the bit rate the higher the quality of the sound . The bit depth is the number of bits available to represent each sample . For example, a sample with a bit depth of 4 could be 0101 or 0111 or 1010. A sample with a bit depth of 8 could be 01010110 or 1010110 or 11001111. A common bit depth is 16 bits . The higher the bit depth , the more bits are available to be used for each sample. Therefore the quality is often higher as the wave more closely resembles an analog wave . The file size will also be larger if the bit depth is higher, as each sample stores additional bits . Example: A short audio sample has a bit depth of 4 and a sample rate of 10 samples per second . The clip is 15 seconds long . Calculate the bit rate by multiplying the sample rate and bit depth : 4 bits x 10 = 40 bits . Now that is the correct data for one second. Multiply the bit rate by the number of seconds in the file: 40 x 15 = 600 bits . To convert the answer from bits to bytes , divide by 8 . 600 bits ÷ 8 = 75 bytes . Calculating File Size Metadata for Sound Files Music libraries such as Apple Music or Spotify store a huge amount of metadata on each song. Metadata is additional data about a file such as: Artist Title / Track Title Product / Album Title Track Number Date Created / Year Genre Comments Copyright Software Type Duration File size Bit rate Sampling rate Channels Volume Q uesto's Q uestions 4.7 - Sound Representation: 1. Explain how an analog sound wave is converted into a binary sample . [ 2 ] 2a. What is a sample rate ? [1 ] 2b. Explain two ways an audio file will be affected if the sample rate is increased . [4 ] 3a. What is bit depth ? [2 ] 3b. Explain two ways an audio file will be affected if the bit depth is increased . [4 ] 3c. Explain what the bit rate is. [ 2 ] 4 . An audio sample has a bit depth of 8 , a sample rate of 10 and it is 12 seconds long . What is the file size in bytes ? [ 2 ] 5a. What is metadata ? [ 2 ] 5b. State four different types of metadata for audio files . [4 ] low bit rate = lower quality high bit rate = higher quality Converting Analog Sound to Binary 1 4.6 Graphical Representation Theory Topics 4.8 - Compression
- 8.4 - Validation & Verification - Eduqas GCSE (2020 Spec) | CSNewbs
Learn about the six main validation checks - range, type, length, format, lookup table and presence. Also, discover three verification checks - double entry, proof-reading and check digits. Based on the 2020 Eduqas (WJEC) GCSE specification. 8.5: Validation & Verification Exam Board: Eduqas / WJEC Specification: 2020 + What are validation and verification checks? Validation is a process to check that data is reasonable or sensible before it is accepted . Verification is the process of checking that data is correct after it has been entered. Validation Checks Range Check Checks data is within a certain range . Age: 34 203 Type Check Checks data is a certain data type . Height (in cm): 182 Two metres Format Check Checks data is entered in a certain way . Date of Birth (DD/MM/YYYY) 25/03/2001 25th March 01 Presence Check Checks that data has actually been entered and not left blank . Password: fluffythecat123 Lookup Table A table of acceptable entries , also known as a list . Length Check Checks the length of the input is within a certain amount. Telephone Number 08323877319 07383 Verification Checks Double Entry Typing in the data twice to make sure there were no spelling errors the first time. Password: fluffythecat123 flufythecat123 Proofreading Checking two copies of data to ensure they are exactly the same . Check Digit Similar to a checksum in a data packet, a check digit is calculated on barcodes to ensure the rest of the numbers are correct . Address: 11 Cherry Lane 11 Cherry Road Confirm Q uesto's Q uestions 8.4 - Validation & Verification: 1. Describe each type of validation check and give an example . a. Range Check [ 3 ] b. Type Check [ 3 ] c. Format Check [ 3 ] d. Presence Check [ 3 ] e. Lookup Table (List) [ 3 ] f. Length Check [ 3 ] 2. For the following data, suggest which validation check would be most suitable and why : a. Password [ 3 ] b. Country of Birth [ 3 ] c. Number of Tickets [ 3 ] d. Weight (in kilograms) [ 3 ] 3. Describe three types of verification check and give an example : a. Double Entry [ 3 ] b. Proofreading [ 3 ] c. Check Digit [ 2 ] 8.4 - Sorting & Searching Theory Topics 9.1 - IDE Tools
- 3.5 - Protocols - Eduqas GCSE (2020 spec) | CSNewbs
Learn about the different protocols used on networks - HTTP, HTTPS, TCP, IP, Ethernet, WiFi, FTP and SMTP. Based on the 2020 Eduqas (WJEC) GCSE specification. 3.5: Protocols Exam Board: Eduqas / WJEC Specification: 2020 + What is a protocol? A protocol is a set of rules that allow devices on a network to communicate with each other . TCP / IP is actually two separate protocols that combine together. TCP / IP (Transmission Control Protocol / Internet Protocol) TCP is a protocol that allows packets to be sent and received between computer systems. It breaks the data into packets and reassembles them back into the original data at the destination. IP is a protocol in charge of routing and addressing data packets . This ensures data packets are sent across networks to the correct destination . It is also an addressing system - every device on a network is given a unique IP address so data packets can be sent to the correct computer system. HTTP is used to transfer web pages over the Internet so that users can view them in a web browser . All URLs start with either HTTP or HTTPS (e.g. https://www.csnewbs.com). HTTPS is a more secure version of HTTP that works with another protocol called SSL ( Secure Sockets Layer ) to transfer encrypted data . You should see a padlock symbol in the URL bar if your connection to that website is secure. HTTP/HTTPS (Hypertext Transfer Protocol) Ethernet is a protocol for wired connections . Ethernet is used at both the data link and physical layers to describe how network devices can format data packets for transmission. WiFi is the main standard for wireless connections . WiFi is actually a brand name that uses a protocol called IEEE 802.11 . Another wireless standard is Bluetooth , for short-range data transfer. Connection Protocols Transfer Protocols FTP ( File Transfer Protocol ) is used to transfer files across a network. It is commonly used to upload or download files to/from a web server . SMTP ( Simple Mail Transfer Protocol ) is a protocol used to send emails to a mail server and between mail servers . Q uesto's Q uestions 3.5 - Protocols: 1. Describe each of the following protocols . It might be helpful to also draw an icon or small diagram for each one: a. TCP [ 2 ] b. IP [ 2 ] c. HTTP & HTTPS [ 3 ] d. WiFi (802.11) [ 1 ] e. Ethernet [ 2 ] f. FTP [ 2 ] g. SMTP [ 2 ] 2. State which protocol would be used in the following scenarios : a. Transferring a music file to a friend over the internet. [ 1 ] b. Sending an email to a family member in America. [ 1 ] c. Using a wireless connection to play a mobile game. [ 1 ] d. Using a webpage to enter a password securely. [ 1 ] e. Watching a video on YouTube. [1 ] 3.4 Network Hardware & Routing Theory Topics 3.6 - 7 Layer OSI Model
- Greenfoot | CSNewbs
The Greenfoot homepage on CSNewbs with links to creating your own Greenfoot game from scratch, as well as key code and how to solve common errors. This section is aimed at the Eduqas GCSE 2016 specification. Links: Installing Greenfoot Greenfoot Game Tutorial Glossary of Key Code Help with Errors I'm Greta the Gecko and I'm here to teach you Greenfoot.
- 5.1.1 - Human Computer Interaction | F160 | Cambridge Advanced National in Computing AAQ
Learn about different types of human computer interaction (HCI) such as audio, movement / gesture, touch and visual (command line and graphical user interface (GUI)). Based on Unit F160 (Fundamentals of Application Development) for the OCR Cambridge Advanced National in Computing (H029 / H129) (AAQ - Alternative Academic Qualification). Qualification: Cambridge Advanced National in Computing (AAQ) Unit: F160: Fundamentals of Application Development Certificate: Computing: Application Development (H029 / H129) 5.1.1 - Types of Human-Computer Interaction Watch on YouTube : Human-Computer Interaction Human-computer interaction (HCI) refers to the ways in which users engage with computers and is an important factor that must be considered when designing and developing an application . For each type of HCI you need to know its purpose , devices on which it is used , its advantages and disadvantages and how client requirements may affect its use . Human-Computer Interaction Types of User Interaction Audio allows users to interact with a system using voice commands . Body movements or gestures (e.g. hand waves or head turns ) can control or interact with applications . Touch allows users to interact by tapping , swiping , dragging or pinching directly on a screen . Graphical user interfaces ( GUIs ) provide a visual interface using windows , icons , buttons and menus . Command-line interfaces ( CLIs ) only allow interaction with the system by typing text commands into a terminal or shell . Q uesto's Q uestions 5.1.1 - Types of Human-Computer Interaction: 1. A company selling toys wants to create an app to advertise its latest products . Justify the suitability of each user interaction type for the company's app . [5 ] 2. Compare the GUI and CLI visual interaction methods, including their advantages and disadvantages . [8 ] 3. Explain when the audio interaction method would be appropriate . [ 3 ] In 2012 Milwaukee County Zoo started giving iPads to orangutans so they could use the touchscreen to draw pictures . D id Y ou K now? 4.3 - Decomposition Methods Topic List 5.1.2 - Types of Device
- Python | Extended Task 4 | CSNewbs
Test your ability to create a more complex program in Python based on a given scenario. Perfect for students learning GCSE Computer Science in UK schools. Extended Task 4 Hi, Jacob Mortimer here from Cats & Dogs Veterinary Surgery . There was a flood last week, and our computer systems were totally destroyed . I need you to create a program , using a file , that allows my receptionist to: Add new animals to the file . Search through the file and print the details of a specific animal . Allow a specific animal to be removed from the file . Vet Surgery For this task, you will need to create a document and include the following sections (with screenshots where appropriate): An introduction to explain the Purpose of your program . A List of Requirements for a successful program. Screenshots of your code (with comments in your code to show understanding). Testing – Create a plan to show how you will test your program and then explanations of any errors that you found and how they were fixed . An Evaluation of what worked, what didn’t, and how you met each of your requirements from your original list. Also, discuss further improvements that you could have made to improve your program. Reminders for this task: You will need to create a selection of options for the user to choose from. Subroutines and a while true loop may help. Section 10 will help you to open, write and read from files . Section 10c shows how to edit data in a file. You will need to adapt this code and not write the line that has been selected, instead of writing a modified version of it. There are multiple ways to approach this program, and your solution might look different from the example. Break the problem down and focus on one part at a time. Example solution: Entering 1 allows the user to enter the details of a new animal which is saved into the file . Entering 4 will stop the loop and ends the program. Entering 2 allows the user to enter the details of an animal to search for . If the animal is in the file, their details are printed clearly on a new line. Entering 3 allows the user to enter the details of an animal to remove from the file . If the animal is in the file, all lines are transferred into a temporary file except for the line to be removed . ⬅ Extended Task 3 (Blackjack) Extended Task 5 (Colour Collection) ➡
- 5.3 - Policies | F161 | Cambridge Advanced National in Computing | AAQ
Learn about policies related to application development, including a user guide, acceptable use policy (AUP), backup, codes of practice, staying safe online and the use of information. Resources based on Unit F161 (Developing Application Software) for the OCR Cambridge Advanced Nationals in Computing (H029 / H129) AAQ (Alternative Academic Qualification). Qualification: Cambridge Advanced Nationals in Computing (AAQ) Certificate: Computing: Application Development (H029 / H129) Unit: F161: Developing Application Software 5.3 - Policies Watch on YouTube : Policies You need to know the purpose , content and application of each policy to be considered when related to developing application platforms . What You Need to Know Policies ? YouTube video uploading soon Q uesto's Q uestions 5.3 - Policies: 1. What? [2 ] 2. What? [1 ] 3. What? [1 ] 4. What? [1 ] ? D id Y ou K now? 5.2 - Application Installation Topic List 6.1 - Legal Considerations
- 1.2 - Operating Systems | F160 | Cambridge Advanced National in Computing | AAQ
Learn about network operating systems, open source operating systems and proprietary operating systems. Resources based on Unit F160 (Fundamentals of Application Development) for the OCR Cambridge Advanced Nationals in Computing (H029 / H129) AAQ (Alternative Academic Qualification). Qualification: Cambridge Advanced National in Computing (AAQ) Unit: F160: Fundamentals of Application Development Certificate: Computing: Application Development (H029 / H129) 1.2 - Operating Systems Watch on YouTube : Network Operating System Open Operating System Proprietary Operating System An operating system is software that manages the resources of a computer system , such as memory , users and files . It also provides a user interface so that humans can interact with the device's hardware . An operating system allows application software to be opened and run . There are three types of operating system that you need to know - network , open and proprietary . Operating Systems Network Operating System (NOS) A network operating system (NOS ) is software that manages network resources and allows computers to communicate over a network . Windows Server , developed by Microsoft , is an example of a network operating system . Characteristics of a Network Operating System Allows for the centralised management of users , data and security across multiple devices on a network . Enables resources such as files , applications and printers to be shared over the network . Manages user authentication and permissions control . Oversees remote access and system monitoring tools . The main type of device that uses a NOS is a server . Other devices, such as desktops or laptops , connect to the server to access shared resources . Windows Server is an example of a popular NOS . Advantages of a Network Operating System Administrators can manage users , files and security on a network from one central location . Resources such as files , printer access and applications can be shared across the network . Access levels can be controlled and user authentication helps protect data . An NOS is scalable - more devices and users can be added as needed . Central servers managed by a NOS make it easier to back up and restore important files . Disadvantages of a Network Operating System Purchasing a NOS and maintaining the servers it runs on can be expensive . Setup and management is complex and may require skilled administrators . If the main server running the NOS fails , connected computers may lose access to resources . Heavy traffic or poor configuration could slow the network down . Who uses a Network Operating System? Application developers can use a NOS to build , test and manage apps that work across networks , such as web applications , multiplayer games or cloud tools . This type of operating system is also used by organisations that need to manage multiple devices , users and resources efficiently across a network , such as a small business or a school . Open Operating System An open operating system is open-source , meaning its source code is freely available for anyone to view , modify and distribute . Source code is the original set of instructions written by a programmer using a high-level language such as Python , Java or C++ . Characteristics of an Open Operating System Users have access to the source code and can see how the OS works . The source code can be modified to suit the specific needs of the user . Development and maintenance may be led by an online community . An open OS is usually free with no licensing costs for most versions. Linux is an example of an open operating system . Android is technically an open-source OS , but most commercial Android devices (like Google Pixel phones ) include proprietary components (like Google Docs or Gmail ), which makes the full system not completely open source . Advantages of an Open Operating System It is usually free to use , modify and distribute the source code . Because the source code can be seen and modified , this type of OS is flexible and customisable . There may be updates from an online community maintaining and improving the software . Promotes experimentation to learn how systems work and try new ideas . Disadvantages of an Open Operating System Programming knowledge and skills are required to modify the source code . There may be security risks if someone edits the source code and redistributes it with malicious code . There will be less official support compared to a proprietary operating system . Some proprietary applications (like Microsoft Access for databases) will only work on a proprietary OS (like Windows ). Who uses an Open Operating System? App developers would use an open OS when the device their application will be used on is not tied to a specific proprietary system (like Windows or MacOS ). For example, a charity making a free educational app for developing countries would choose an open OS so it can run on low-cost , older smartphones . It can be customised and tested on a range of devices . Applications for specific single-purpose systems would also use an open OS , such as an information terminal in a museum . Linux could be used to develop a simple user interface and remove unnecessary features . Proprietary Operating System A proprietary operating system is software that is owned by a company or individual and the source code is not accessible for users to view , modify or distribute . Users must typically buy a licence or agree to the terms of use . Characteristics of a Proprietary Operating System The source code is hidden from the user and cannot be legally modified . A paid licence or subscription is usually required to use the software . It may be maintained and updated by the developer(s) who own it . Only the developer controls updates and the features that are added or fixed . Examples include Microsoft Windows (e.g. Windows 11 ), macOS (for Apple desktops and MacBooks ), iOS (for iPhones ) and iPadOS for iPads ). Advantages of a Proprietary Operating System There is an expectation that it is user-friendly and has been well tested . There may be official support and regular updates for improvements and bug removal . A proprietary OS has a high compatibility with proprietary software such as Microsoft Office or Adobe editing apps . The OS is expected to be stable and secure , with access restricted to system files . Disadvantages of a Proprietary Operating System A paid licence to use the OS is often required , which may be expensive . There is limited customisation for users as the source code cannot be seen or modified . Users rely on the vendor (developer ) for updates and bug fixes . Some proprietary OS are designed to only work on specific hardware (such as iOS only working on iPhones ). Who uses a Proprietary Operating System? App developers will need to use a proprietary OS if they are developing applications for a device that requires a specific proprietary OS , for example if they are creating a game for iPhones , they will need to use iOS . A company designing a finance application on desktops with Microsoft Access and Microsoft Excel must use a proprietary OS like Windows so that it can be integrated with these other types of proprietary applications . Q uesto's Q uestions 1.2 - Operating Systems: 1. What is an operating system ? [2 ] 2. For each of the three types of operating systems , create a poster , information sheet or factfile which includes the following information : Characteristics Advantages Disadvantages Example of how it could be used [10 per OS ] Windows 11 is Microsoft's current operating system . Windows 1.0 was their first release, introduced in 1985 and included basic versions of Calculator , Notepad and Paint . D id Y ou K now? 1.1 - Programs & Applications Topic List 1.3.1 - Application Types
- Key Stage 3 Python | Turtle | CSNewbs
The final part of a quick guide to the basics of Python aimed at Key Stage 3 students. Learn about importing turtle to command a moving object. Python - Iteration For Loops Editor Execute A for loop is a count controlled loop. It repeats for a certain number of times as stated in the range brackets. The first number (1) states the number to start on . The second number is an exclusive end . This means it actually finishes on the number before . (11 will end on 10). You need a colon at the end of the loop line . Each line to be repeated must be indented (press the tab key). You can use the loop number within the loop itself. 1. Write a for loop to print your name 8 times . (Count it to double-check it prints eight times.) 2. Use a for loop to print each number between 10 and 50 . 3. Use a for loop from 1 to 10 . Print the 3 times table by multiplying number by 3 underneath the loop. 4. Ask the user to input a whole number (call it num1 ). Write num1 in your range brackets to repeat any message that many times. 5. Ask the user to input a whole number (call it num1 ) and then input a word . Print the word by the number they entered . (Hint: Use num1 in the range.) 6. Delete your code and copy these 3 lines: #Delete the space after the colon for number in range(0,21,2): print(number) What happens when you run this code? 7. Use Q6 to help you print 0 to 100 , going up in 5s . Think about the 3 values you need in the range brackets. 8. Use Q6 to help you print 100 down to 0 , backwards by 1 . Think about the 3 values you need in the range brackets. Tasks While Loops Editor Execute A while loop is a condition controlled loop . While loops repeat as long as the condition is true . As soon as the condition becomes false , the loop will end . 1. Change the program in the editor to repeat the loop while a number is not equal to 33 . 2. Make a new while loop that asks the user to enter a whole number . While the number is less than or equal to 1000 , keep repeating. 3. Make a new while loop for while a colour is not equal to purple (or any colour you want). Ask the user to enter a colour inside of the loop . Don't forget to set colour to "" before you start. 4. Edit your colour program to count how many guesses were made. Make a new variable called count and set it to 0 at the start of the program. Increase it by 1 in the loop, using count = count + 1 . 5. While a total is less than 100 , ask the user to input a decimal number . When it is over 100 , print ‘COMPUTER OVERLOAD’ . You need a variable called total . Increase the total each time with total = total + number . Don't forget to start it at 0 . Tasks != means ‘not equal to ’. The loop below will repeat as long as the password is not equal to “abc123” . Any variable you use in your condition must have a value first . You can’t check for your password if it doesn’t exist. That’s why I have written password = “” , to give password a value before we check it .
- Motherboard | Key Stage 3 | CSNewbs
Learn about the motherboard and the components that are connected to this important piece of computer hardware. The Motherboard What is a motherboard? The motherboard is the main circuit board of a computer that links all other components together. Components can communicate by sending signals and data across pathways called buses . Some components, like the CPU and RAM , are directly installed in special sockets on the motherboard . There are expansion slots for further components like a graphics card . What is connected to the motherboard? Central Processing Unit Random Access Memory Graphics Processing Unit Read Only Memory Cache Memory Sound Card Hard Disk Drive Power Supply Unit What is a motherboard's form factor? Form factor relates to the motherboard's size , shape and how many components it can fit . The three most common form factors are compared below: ATX Micro ATX Mini ITX Standard Small Very Small 32 GB 64 GB 128 GB 7 4 1 Size Max RAM Expansion Card Slots GB stands for gigabytes What ports does a motherboard have? The motherboard contains several ports on the back panel , allowing cables to be connected to input or output data . Below are some of the common ports : USB (Type-A) Connects input devices like keyboards and mice or storage devices like a USB memory stick. USB (Type-C) A newer type of USB that is faster and commonly used to charge devices or transfer data. Ethernet Allows a device to connect to a wired network, most commonly to a router, for internet access. HDMI Connects to a monitor or TV to show the computer's audio and visual output. KS3 Home
- OCR A-Level | CSNewbs
Navigate between all topics in the OCR A-Level Computer Science H446 specification. Includes all topics from Component 1 (Computer Systems) and Component 2 (Algorithms and Programming). OCR Computer Science A-Level These pages are based on content from the OCR H446 Computer Science specification . This website is in no way affiliated with OCR . Component 1: Computer Systems Paper 1 Playlist on YouTube This content is under active development. Check here for the latest progress update. OCR A-Level Key Term Generator 1. Hardware 1.1 - Structure & Function of the Processor (The CPU) 1.2 - Types of Processor 1.3 - Input, Output & Storage 2. Software 2.1 - Systems Software 2.2 - Applications Generation 2.3 - Software Development 2.4 - Types of Programming Language 3. Networks & Databases 3.1 - Compression, Encryption & Hashing 3.2 - Databases 3.3 - Networks 3.4 - Web Technologies 4. Data & Logic 4.1 - Data Types 4.2 - Data Structures 4.3 - Boolean Algebra 5. Laws 5.1 - Computing-Related Legislation 5.2 - Moral & Ethical Issues Component 2: Algorithms & Programming 1. Computational Thinking 1.1 - 1.5 - Computational Thinking 2. Problem Solving & Programming 2.1 - Programming Techniques 2.2 - Computational Methods 3. Algorithms 3.1a - 3.1d - Algorithm Complexity 3.1e - Data Structure Algorithms 3.1f - Standard Algorithms
- 2.3 - Additional Programming Techniques - OCR GCSE (J277 Spec) | CSNewbs
Learn about arrays, records and SQL (structured query language) including the SELECT, FROM and WHERE commands. Based on the J277 OCR GCSE Computer Science specification (first taught from 2020 onwards). Exam Board: OCR Specification: J277 2.3: Additional Programming Techniques Watch on YouTube : String Manipulation File Handling Arrays Subprograms Random Numbers SQL 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 to try a self-marking quiz (Google Form) about records and SQL. Q uesto's Q uestions 2.3 - 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






