VCE Applied Computing Units 3&4 Software Development - Introduction to Programming PDF

Summary

This document introduces fundamental programming concepts, including data types (numeric, text, boolean), data structures (arrays, records), and explains their practical applications. The presentation also includes illustrative examples in Python.

Full Transcript

VCE APPLIED COMPUTING UNITS 3&4 SOFTWARE DEVELOPMENT UNIT 3 SOFTWARE DEVELOPMENT AREA OF STUDY 1 – SOFTWARE DEVELOPMENT: PROGRAMMING CHAPTER 1 – INTRODUCTION TO PROGRAMMING KEY KNOWLEDGE KK3.1.2: characteristics of functional and non-functional requirements, constraints and scope KK...

VCE APPLIED COMPUTING UNITS 3&4 SOFTWARE DEVELOPMENT UNIT 3 SOFTWARE DEVELOPMENT AREA OF STUDY 1 – SOFTWARE DEVELOPMENT: PROGRAMMING CHAPTER 1 – INTRODUCTION TO PROGRAMMING KEY KNOWLEDGE KK3.1.2: characteristics of functional and non-functional requirements, constraints and scope KK3.1.3: design tools for representing modules, including data dictionaries, mock-ups, object descriptions, input–process–output (IPO) charts and pseudocode KK3.1.4: characteristics of data types, including text, numeric and Boolean KK3.1.5: types of data structures, including one- and two-dimensional arrays and records (varying data types, field index) KK3.1.6: characteristics of data sources, including plain text (TXT), delimited (CSV) and XML files KK3.1.9: purposes and features of naming conventions for solution elements KK3.1.11: purposes of internal documentation. DATA TYPES Definition: A data type classifies a variable to determine the kind of data it can store and how it can be manipulated. Consistency: Data types are consistent across all programming languages, even though languages vary widely. Importance: Choosing an appropriate and efficient data type is critical when creating variables in programming. Efficiency Example: Using a numeric data type with decimal support for whole numbers is inefficient. Storing numbers as strings is less efficient than using numeric data types, even if conversion is possible. NUMERIC Numeric Data Type: Includes integers, floating points (decimals), and date/time values (stored as integers). Integers: Unsigned: Stores only positive whole numbers. Signed: Stores both positive and negative whole numbers. Operations: All numeric data types support mathematical operations, with fundamental ones being the most commonly used. When more than one operation appears within a line of code, the order of operations follows the same rules as BODMAS in mathematics: brackets, orders, division, multiplication, addition and subtraction. If two operators have the same precedence, they are evaluated from left to right. QUESTION Which of the following data types is most suitable for storing a person’s age? A. Boolean B. Text C. Integer D. Floating point (Correct answer: C) Discussion: Explain why it is inefficient to store whole numbers using a floating- point data type. TEXT AND CHARACTER Character Data Type: Represents single meaningful units like letters, numbers, symbols, punctuation, or spaces. Character Encoding: Translates binary data into characters, with schemes like: ASCII: For English characters, punctuation, and numbers. UTF-8: Supports diverse languages and symbols (e.g., € and ¥). Text/Strings: A sequence of characters, often implemented as arrays in programming languages. QUESTION What is a null-terminated string, and why is it used in programming A. It ends with a special character (\0) for efficient storage and handling of strings. B. It is a sequence of random characters stored in memory. C. It is a text string with no characters. D. It uses numeric values to represent text. (Correct answer: A) YOU DO DISCUSSION QUESTION You may come across the term ‘null terminated string’ when looking at programming language reference manuals and computer science texts. AWhat is a null string null-terminated terminated string? is a sequence of characters in programming that ends with a special character called the null character (\0), which signifies the end of the string. This approach is commonly used in languages like C and C++ for handling strings.  Definition: A string with characters stored in memory, followed by a null character (\0) to mark its termination.  Purpose: Indicates where the string ends, allowing functions to determine the length of the string without additional metadata.  Example:  String "hello" in memory would be stored as: h, e, l, l, o, \0.  Usage: Common in low-level programming for efficient string handling.  Limitation: The null character itself cannot be part of the string's data, as it is reserved for termination. BOOLEAN Boolean Data Type: Has two values, 0 (False) and 1 (True), often used for decision-making and logical operations. Origin: Named after George Boole, who developed an algebraic system of logic. Mathematical Operations: Supports comparison operators (e.g., ==, ) and logical operators (and, or, not). Applications: Used in conditions to make decisions, such as checking if a room is dark and the light is off before turning it on. DATA STRUCTURES Data Structure: A method of organizing data to enable efficient operations, more complex than data types. Types: Commonly used data structures include one-dimensional arrays, two-dimensional arrays, and records. ARRAYS: Contain grouped data of the same type (e.g., character, numeric, Boolean). Can store other data structures like fields, records, or arrays. Useful for efficiently organising and ordering related data, enabling faster sorting and searching. Example: A teacher storing student heights in a one-dimensional array is more efficient than using separate variables. TWO DIMENSIONAL ARRAYS A two-dimensional array is a data structure where elements are stored in a table-like format, consisting of rows and columns. It can be thought of as an array of arrays. While a one-dimensional array is akin to a single row or a single column of data, a two-dimensional array represents a grid of data. This requires accessing elements using two indices rather than one. PYTHON EXAMPLE # Defining a 2-dimensional array # Modifying an element students_scores = [ students_scores = 95 # Changing Student 3's score in subject 3 [85, 90, 88], # Scores for Student 1 print("Updated scores for Student 3:", [78, 85, 92], # Scores for Student 2 students_scores) [90, 88, 84] # Scores for Student 3 ] # Iterating through the array # Accessing elements print("All scores:") print("Score of Student 1 in subject 2:", students_scores) # Output: 90 for student in students_scores: Output Score of Student 1 in subject 2: 90 print(student) Updated scores for Student 3: [90, 88, 95] All scores: [85, 90, 88] [78, 85, 92] [90, 88, 95] RECORD AND FIELD A record is a basic data structure for collections of related elements. These elements may or may not be of the same data type. A record consists of a number of fields that are typically fixed – that is, the fields do not tend to change once the record is defined and used. Each field has a name and each has its own data type. For example, a customer record may contain fields such as firstName, lastName and dateOfBirth. EXAMPLE 1: USING A DICTIONARY A dictionary can represent a record where each key is a field name, # Modifying a field and the corresponding value is the field's data. student_record["age"] = 18 # Defining a record for a student using a dictionary print("Updated age:", student_record["age"]) # Output: 18 student_record = { "name": "Alice", # Adding a new field "age": 17, student_record["graduated"] = False "scores": [85, 90, 88], print("Updated record:", student_record) "grade": "A" } # Accessing fields print("Student's name:", student_record["name"]) # Output: Alice Output Student's name: Alice print("Student's scores:", student_record["scores"]) # Output: [85, 90, 88] Student's scores: [85, 90, 88] Updated age: 18 Updated record: {'name': 'Alice', 'age': 18, 'scores': [85, 90, 88], 'grade': 'A' 'graduated': False} EXAMPLE 2: USING A CLASS A class is a more structured way to define records, especially # Creating a student record when multiple instances (records) are needed. student = Student("Bob", 18, [78, 85, 92], "B") # Defining a Student class class Student: # Accessing fields def __init__(self, name, age, scores, grade): print("Student's name:", student.name) # Output: Bob self.name = name # Field: name print("Student's grade:", student.grade) # Output: B self.age = age # Field: age self.scores = scores # Field: scores # Modifying a field self.grade = grade # Field: grade student.grade = "A" print("Updated grade:", student.grade) # Output: A Student's name: Bob Student's grade: B Updated grade: A YOUR TURN Complete the following textbook questions in your exercise book Page 23 – Q1-4 Work through Chapter 1 Booklet

Use Quizgecko on...
Browser
Browser