4.1 Fundamentals of programming

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/88

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

89 Terms

1
New cards

data type

a classification that specifies the kind of data that can be stored and manipulated within a program

2
New cards

intiger

Whole numbers (e.g., 5, -12, 0)

3
New cards

real/float

Numbers with decimal points (e.g., 3.14, -7.5)

4
New cards

boolean

True or False value

5
New cards

a character

A single symbol or letter (e.g., 'A', '7', '#')

6
New cards

string

A sequence of characters (e.g., "Hello", "123").

7
New cards

date and time

stores date and time

8
New cards

pointer/reference

Memory address of another variable

9
New cards

records

Groups related data of different types.

10
New cards

arrays

Ordered collections of the same data type

11
New cards

user defined data types

custom data structures created by combining built-in types to represent more complex data.

12
New cards

examples of user defined data types

classes, records, and enumerations.

13
New cards

variable declaration

reserves memory to store a value. eg age = 0

14
New cards

constant declaration

a fixed value that doesn’t change. eg pi =3.142 3.14159

15
New cards

assignment

sets or update the value of a variable

16
New cards

iteration

repeated a block of code. eg loops

17
New cards

selection

executes code based on conditions. eg if statements

18
New cards

subroutine (procedure/function)

a reusable block of code that performs a specific task. eg a def statement

19
New cards

what’s definite iteration

iteration where the number of repetitions is knows before. eg for I in range of 5

20
New cards

what is indefinite iteration

iteration where the number of repetitions depends on a condition. eg while loops

21
New cards

what is a loop with a condition at the start

checks the condition before executing the block. If the condition is false, the loop does not run at all. eg while x >0

22
New cards

what’s a post condition loop

A loop that runs at least once before checking the condition.

23
New cards

Differences between pre-condition and post-condition loops

Pre-condition loops may not execute at all, while post-condition loops always run at least once.

24
New cards

when in definite iteration most useful

When the number of repetitions is known in advance, like iterating through a list.hw

25
New cards

When is indefinite iteration most useful?

When the loop must continue until a specific condition is met, such as user input validation.

26
New cards

Why is understanding the placement of conditions important?

It helps design loops that work correctly for the intended logic, ensuring accurate execution.

27
New cards

nested selection

placing one structure inside another used to handle multiple layers of decision making (eg: if else elif inside a if)

28
New cards

nested iteration

placing one loop inside another. to handle operations like working with multi-dimensional arrays or repeated actions within repeated actions.

29
New cards

strength of nested selection

allows for more complex decision trees

30
New cards

nested iteration

great for working with multi-dimensional data or repeated sub-processes.

31
New cards

exponentiation

raises a number to the power of another number

32
New cards

tuncation

removes the decimal part of a number leaving only the integer part eg using int()

33
New cards

What’s the difference between a variable and a constant

Variables are flexible and can be modified, while constants are fixed values used for things that should remain constant throughout a program.

34
New cards

advantages of using named constants

improved readability - using descriptor names for fixed values rather than raw values

easier matinence - if you have to update a constant value you only need to change it in one place instead of whole prog

reduce errors - minimize risk of accidenltly changing value that should remain fixed

code reusability - increases consistency

better debugging - can track where it is easier

35
New cards

concatenation

combines two or more strings together

36
New cards

character -> character code

Converts a character to its ASCII (or Unicode) code. (ord)

37
New cards

character code → character

converts a character code(into) back to a character (chr)

38
New cards

exception handeling

allows a program to respond to runtime errors or unexpected situations in a controlled way without crashing

39
New cards

exceptions

An event that disrupts the normal flow of a program's execution.

40
New cards

try block

The section of code that might throw an exception.

41
New cards

except block

The section of code that runs if an exception occurs in the try block.

42
New cards

finally block

code that will run after the try-except blocks, regardless of whether an exception occurred.(optional)

43
New cards

benefits of exception handling

prevents program from crashing unexpectedly

allows of more detailed error messages helping debugging

you can take specific actions depending on the type of error

44
New cards

common uses of exception handling

handle errors like file not found and file permission issues

network communications like timeouts and unreachable servers

user inputs validation

45
New cards

subroutine

block of code which performs a specific task can be called and executed from different parts of the code

46
New cards

key characteristics of a subroutine

name

parameters - values can be passed to modify behavior

return value p result which can be returned from the subroutine back to the calling code

execution - executes it when is called in the program

47
New cards

advantages of subroutines

reusability

code organization

abstraction

easier for debugging + testing

48
New cards

parameter

variable used to pass data to and from subroutines

49
New cards

types of parameters

positional parameters - order of them matter

keyword parameters - passed by name not position (allows flexibility)

default parameters - have default values if no value provided when called

variable length parameters- used when you don’t know how nat will be passed on

50
New cards

subroutine with interfaces

defines the name, parameters, and return type of the subroutine. It is the "public" part of the subroutine that shows how it can be used in the program.

51
New cards

advantages of using parameters

data encapsulation - doesntt expose the internal workings of the subroutine. keeps the subroutine "self-contained" and easier to manage

flexibility - avoids hard coding values in subroutine

reusability - you can call it multiple times with different arguments making it more modular and reducing redundancy

improved readability - makes easier to understand

52
New cards

local varables

can only be used in that block of code or subroutine

53
New cards

local vs global variable

Scope:

Local Variable: Only accessible within the function/block where it is defined

Global Variable: Accessible throughout the entire program

Lifetime:

Local Variable: Exists only while the function/block is executing.

Global Variable: Exists for the entire duration of the program.

54
New cards

recursion

a function calls itself to solve smaller instances of the same problem. It has a base case to stop the recursive calls and prevent infinite loops.

55
New cards

general case in recursion

part of the recursive function where it calls itself with a simpler or smaller version of the problem, typically moving closer to the base case

56
New cards

base case in recursion

condition under which the recursion stops, returning a value without making further recursive calls. It prevents infinite recursion.

57
New cards

recursion implemented in a program

function calls itself with modified arguments.

Each call adds a new layer to the call stack until the base case is reached, at which point the function returns a result and unravels the recursive calls.

58
New cards

advantage of recursion

simplified code with repetitive subproblems

breaks down complex problems into smaller manageable parts

59
New cards

disadvantage of recursion

can lead to stack overflow

less efficient than iterative solutions

60
New cards

recursion diffrent iteration

Recursion: Function calls itself to solve a problem step-by-step.

Iteration: Uses loops to repeatedly execute code to solve a problem.

61
New cards

procedural programming paradigm

paradigm based on the concept of procedure calls, where the program is structured into procedures (or functions) that operate on data.

62
New cards

key characteristics of procedural programming

Linear Structure: Programs are executed step-by-step.

Modular Design: Code is divided into reusable functions or procedures.

Focus: Emphasizes functions and sequence of actions to manipulate data.

Global State: Data is often stored in global variables, accessed and modified by procedures.

63
New cards

OOP

organizes a program around objects rather than actions, with objects containing both data (attributes) and behavior(methods).

64
New cards

key characteristics

  • Encapsulation: Data and methods are bundled together inside objects.

  • Abstraction: Hides complexity by exposing only essential details.

  • Inheritance: Enables reuse of existing code by creating new classes based on existing ones.

  • Polymorphism: Allows methods or objects to behave differently based on the context.

  • Focus: Focuses on objects and their interactions rather than procedures.

65
New cards

eval for procedural prog and OOP

  • Procedural programming is simpler and better for smaller tasks.

  • Object-oriented programming is more powerful for managing larger, complex systems by organizing code around objects.

66
New cards

what is a structures approach

divides a program into smaller, manageable modules or functions, each with a specific purpose. It uses a top-down design method and focuses on clarity, reusability, and logical flow.

67
New cards

key principles; es of structured programming

  • Modularity: Breaking the program into smaller, independent modules.

  • Top-Down Design: Designing the program starting from the main task, then breaking it into sub-tasks.

  • Sequence, Selection, Iteration: Using these three basic structures to control program flow.

68
New cards

hierarchy chart

a visual diagram that shows the structure of a program. It represents the breakdown of a program into modules and sub-modules, illustrating their relationships.

69
New cards

advantage of structured programming

  1. Easier Debugging: Errors are easier to isolate and fix in small, independent modules.

  2. Improved Clarity: Programs are more readable and maintainable.

  3. Code Reusability: Modules can be reused in other programs.

  4. Better Collaboration: Teams can work on different modules simultaneously.

  5. Logical Flow: Ensures a clear and systematic program flow.

70
New cards

structured vs unstructured programming

  • Structured: Uses modular design, clear control structures, and a top-down approach.

  • Unstructured: Relies on spaghetti code with no clear flow or modularity, making debugging difficult.

71
New cards

steps in structured programming

  1. Identify the main task.

  2. Break the task into smaller sub-tasks (modular design).

  3. Use hierarchy charts to represent the structure.

  4. Write and test code for each module.

72
New cards

modular design

dividing a program into smaller, independent modules, each responsible for a specific task. Modules interact but work independently.

73
New cards

when is structured useful

for large, complex programs where clarity, maintainability, and scalability are important.

74
New cards

what is a class in OOP

a blueprint or template that defines methods and attributes common to all objects of that type.

75
New cards

what’s instantiation

the process of creating an object from a class using a constructor.

76
New cards

what is object in OOP

an instance of a class, representing a specific entity with defined attributes and methods.

77
New cards

encapsulation

e principle of bundling data (attributes) and methods (functions) together and restricting access to some parts using access specifiers (e.g., private, protected, public).

78
New cards

inheritance

allows a class (child) to derive methods and attributes from another class (parent), promoting code reuse.

79
New cards

aggregation

a "has-a" relationship where one class contains a reference to another, but the contained object can exist independently (e.g., a university has departments). Represented by a white diamond in UML.

80
New cards

composition

"part-of" relationship where one class contains another, and the contained object cannot exist independently (e.g., a car has an engine). Represented by a black diamond in UML.

81
New cards

polymorphism

allows methods or objects to behave differently depending on their context, often through method overriding or overloading

82
New cards

what is method overriding

when a subclass provides a specific implementation of a method already defined in its parent class.

83
New cards

What do the symbols +, -, and # represent in UML?

+public

-private

#protected

84
New cards

why OOP

  • Modularity: Easier to maintain and debug.

  • Reusability: Code can be reused via inheritance and polymorphism.

  • Scalability: Better suited for large, complex systems.

  • Real-world modeling: Closely mirrors real-world entities and relationships.

85
New cards

what’s a abstract method

Declared in a base class but implemented in derived classes

86
New cards

whats a virtual method

Defined in a base class and can be overridden in derived classes.

87
New cards

static method

Belongs to the class rather than an instance and does not require an object to be called.

88
New cards

What does single inheritance look like in a class diagram?

A class diagram shows a child class inheriting from a parent class using a solid line with a hollow trianglepointing to the parent.

89
New cards

How are aggregation and composition represented in UML?

  • Aggregation: White diamond (e.g., Library ○— Book).

  • Composition: Black diamond (e.g., Car ◆— Engine).