1.2.4 Types of Programming Language Flashcards

(139 cards)

1
Q

What is a programming paradigm?

A

A programming paradigm is an example or pattern of a way of doing things in programming. It refers to the style or approach of programming a language follows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why do we need different programming paradigms?

A

Different paradigms are better suited to different types of problems, even though most are Turing complete and can solve any computational problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two broad categories of programming languages?

A

Low-level and high-level languages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is machine code?

A

The lowest-level programming language written in binary (1s and 0s), representing direct electrical signals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is assembly language?

A

A low-level programming language using mnemonics to represent machine code instructions, translated by an assembler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a high-level language?

A

A programming language with a one-to-many relationship with machine code, abstracting complexity and allowing for easier human understanding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the two categories of high-level languages?

A

Imperative and declarative languages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an imperative language?

A

A language that uses statements to change a program’s state via sequence, selection, and iteration. It describes how a program operates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a declarative language?

A

A language that focuses on what the program should accomplish rather than how to accomplish it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the two main imperative programming paradigms?

A

Procedural programming and object-oriented programming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is procedural programming?

A

An imperative paradigm where programs are built from procedures or functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is object-oriented programming?

A

An extension of imperative programming focusing on modular programming using objects and classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which languages are examples of the procedural paradigm?

A

Fortran, COBOL, BASIC, and C.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which languages are examples of the object-oriented paradigm?

A

C++, Java, and C#.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the key question after watching the video?

A

What do we mean by the term programming paradigm?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are procedural languages?

A

Procedural languages are a common programming paradigm focused on giving step-by-step instructions to a computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is another name for procedural languages?

A

They are often referred to as imperative languages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does ‘imperative’ mean in programming?

A

Imperative means to give an order or instruction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do procedural languages structure code?

A

They use a series of statements such as sequence, selection, and iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How is code developed in procedural programming?

A

In a modular way using blocks of code for set tasks, achieved through procedures and functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What exam skills are required for procedural languages?

A

You need to be able to read, trace, amend, and write procedural program code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What should you focus on when learning different procedural languages?

A

Focus on understanding the concepts and applying them to your chosen language, as syntax may differ.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Do exam boards specify which procedural language to learn?

A

No, the specific language is usually chosen by your teacher.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Why is it okay if example code looks different from what you're taught?
Because the underlying concepts are the same across procedural languages.
26
What is assembly language?
A low-level programming language using mnemonics that are translated into binary machine code by an assembler.
27
Why were assembly languages developed?
Because early binary machine code languages were difficult to program with.
28
What does an assembler do?
Translates assembly language into binary machine code.
29
What is LMC?
Little Man Computer - a conceptual computer used to teach assembly language.
30
How many instructions are in the LMC instruction set?
11 simple instructions or mnemonics.
31
Why is LMC used in education?
To help students learn, test, and understand the basics of assembly language.
32
What do LMC simulators do?
Allow users to practice writing and running assembly code.
33
How many memory locations are there in LMC RAM?
100 memory locations, numbered 0 to 99.
34
What does the arithmetic logic unit (ALU) do in LMC?
Performs calculations and logic operations.
35
What is the accumulator in LMC?
Stores the result of the last operation or calculation.
36
What does the program counter do?
Stores the address of the next instruction in memory.
37
What is the instruction register?
Holds the first digit (opcode) of the instruction read from memory.
38
What is the address register?
Holds the second and third digits (operand) of the instruction.
39
What is the input tray in LMC for?
Where a number can be typed if needed.
40
What is the output area in LMC for?
Where numbers output by the program are printed.
41
What is the range of the program counter?
00 to 99.
42
What is the range of the accumulator?
-999 to +999.
43
What is a mnemonic in LMC?
A simple code that represents an instruction type.
44
What is a label in LMC?
A name for a memory address used in assembly code.
45
What happens if a word is not recognised as an instruction in LMC?
It is assumed to be a label.
46
What do the input and intermediate output boxes do?
Show the input to the assembler and the label-converted output.
47
How many parts can each line of LMC code have?
Up to three: a label, a mnemonic, and data.
48
What does pressing the Submit button do in the LMC simulator?
Converts the program into intermediate output.
49
What does pressing Run in the LMC simulator do?
Executes the program step-by-step.
50
What happens in each instruction cycle?
Instruction is fetched, decoded, executed, and the program counter is incremented.
51
What does instruction 901 do?
Inputs a number into the accumulator.
52
What does instruction 305 do?
Stores the accumulator value into memory location 5.
53
What does instruction 105 do?
Adds the contents of memory location 5 to the accumulator.
54
What does instruction 902 do?
Outputs the value in the accumulator.
55
What does instruction 000 do?
Halts the program.
56
What does the example program do?
Adds two user-input numbers and outputs the result.
57
What is the purpose of memory addressing in computing?
To identify and access specific locations in main memory where information is stored.
58
What are the four types of memory addressing modes?
Immediate
59
What are the two parts of a binary instruction?
Opcode and Operand.
60
In an 8-bit instruction '0001 1010'
what is the opcode and what is the operand?
61
What does immediate addressing mean?
The operand is the actual value to be used in the instruction.
62
In immediate addressing
what does the instruction ADD 10 mean?
63
What does direct addressing mean?
The operand is the memory address of the value to be used.
64
In direct addressing
what does the instruction ADD 10 mean?
65
What does indirect addressing mean?
The operand is the address of a memory location that holds another address, where the actual value is stored.
66
In indirect addressing
what does the instruction ADD 10 mean?
67
Why is indirect addressing useful?
It allows referencing of more memory locations than the operand size would normally allow.
68
What limitation does indirect addressing help overcome?
The limited number of addresses that can be referenced with a small operand size (e.g., 4 bits).
69
What does indexed addressing mean?
The operand is added to an index register to determine the effective address.
70
How does indexed addressing work with an array?
The base address of the array is in the operand and the index register increments to access each element.
71
In indexed addressing
what happens if the operand is 10 and index register is 3?
72
What does the instruction LDA 8 mean in immediate addressing?
Load the value 8 directly into the accumulator.
73
What does the instruction LDA 8 mean in direct addressing?
Go to memory location 8 and load the value found there into the accumulator.
74
What does the instruction LDA 8 mean in indirect addressing?
Go to memory location 8, get the address stored there, then go to that address and load its value into the accumulator.
75
What does the instruction LDA 8 mean in indexed addressing if the index register is 4?
Calculate 8 + 4 = 12, go to memory location 12 and load its value into the accumulator.
76
What does Object-Oriented Programming (OOP) attempt to do?
Group data and related functionality into structured items called objects.
77
How is the world viewed in OOP?
As a collection of interacting objects.
78
What are examples of objects in OOP?
Animals, cars, people, houses, customer accounts, data structures like stacks or queues.
79
What is each object responsible for in OOP?
Its own data and the operations performed on that data.
80
How do objects interact in OOP?
By sending and receiving messages.
81
What are some characteristics of a lightbulb as an object?
Wattage (e.g. 40W), color (e.g. white), type (e.g. filament), connection type (e.g. screw fixing).
82
What is a class in OOP?
A blueprint or template defining the attributes and methods for objects of a certain type.
83
What are the three main sections of a class?
Name, attributes (data), and methods (functions or subroutines).
84
What is the difference between a class and an object?
A class is a template; an object is an instance created from that class.
85
What is instantiation?
The process of creating an object from a class using the 'new' keyword.
86
What happens when you instantiate an object?
A new object is created in memory with its own copy of the class’s attributes and methods.
87
What is the syntax to start and end a class in exam-style pseudocode?
Start with 'class ClassName' and end with 'end class'.
88
What keyword is used to mark attributes in a class?
private
89
What is a constructor method?
A special method defined with 'procedure new' that runs when an object is instantiated.
90
What does a constructor do?
It initializes the object’s attributes using values passed in when the object is created.
91
How many ToyTank objects were created in the example?
Three: tank1 (blue, Trevor), tank2 (red, Tim), and tank3 (green, Tony).
92
What syntax is used to call a method on an object?
Dot syntax (e.g. tank1.getName()).
93
What is inheritance in Object-Oriented Programming (OOP)?
Inheritance allows a new class to reuse and extend the attributes and methods of an existing class without rewriting code.
94
What is a superclass?
A superclass is the original or parent class from which other classes inherit attributes and methods.
95
What is a subclass?
A subclass (or derived class) is a more specific class that inherits from a superclass and can add new attributes or methods.
96
In the example, which class is the superclass of Employee?
Person is the superclass of Employee.
97
What attributes does the Person class have in the example?
Name and address.
98
How many methods does the Person class have and what do they do?
Four methods: two to get the name and address, and two to set the name and address.
99
What additional attribute does the Employee subclass add?
National insurance number.
100
Can subclasses inherit attributes and methods from all classes up the hierarchy?
Yes, subclasses inherit from all classes higher up the class tree.
101
What is an example of subclasses extending Employee?
HourlyPaidEmployee and SalariedEmployee.
102
What kind of attributes might HourlyPaidEmployee have?
Attributes like hourly rate and hours worked.
103
What kind of attributes might SalariedEmployee have?
Attributes like annual salary and pay grade.
104
What happens when a subclass needs a more specific version of a method it inherited?
The subclass can override the method by defining a new method with the same name.
105
What does overriding do?
It replaces the method from the superclass with the subclass's version when called on an object of the subclass.
106
In the example, how is the getName method overridden?
By prefixing the name with a capital letter and underscore to denote system type (e.g., 'E_' for hourly, 'S_' for salaried).
107
How can you call the original superclass method if it has been overridden?
By using 'super' followed by the method name, e.g., employee4.super.getName().
108
What is the benefit of using inheritance?
It promotes code reuse and reduces duplication by extending existing classes.
109
What does the 'inherits' keyword do in the example pseudocode?
It specifies that a new class derives from an existing superclass.
110
Do you need to rewrite the original class code when creating a subclass?
No, the original class code remains unchanged.
111
How many attributes and methods does an HourlyPaidEmployee object have?
Four attributes (1 new + inherited from Employee and Person) and eight methods (2 new + inherited).
112
What is the purpose of method overriding in OOP?
To provide class-specific behavior for inherited methods while maintaining the interface.
113
Why might you want to override a method like getName?
To customize the output or behavior for different subclasses.
114
Can subclasses inherit from subclasses?
Yes, inheritance can be multi-level (e.g., Person -> Employee -> SalariedEmployee).
115
How do you instantiate an object from a subclass in pseudocode?
Using the 'new' keyword followed by the subclass name and passing initial values, e.g., new Employee(...).
116
What does the term 'class tree' refer to?
The hierarchy structure showing inheritance relationships between classes.
117
How many methods does the Person class have in the original code example?
Four methods.
118
Is overriding automatic when a subclass has a method with the same name as its superclass?
Yes, the subclass method automatically overrides the superclass method.
119
What is the output difference between calling getName and super.getName on an overridden method?
getName calls the subclass's overridden method, super.getName calls the original superclass method.
120
What is encapsulation in object-oriented programming?
Encapsulation means the bundling of data with the methods that operate on it and restrict direct access to it.
121
What is the main purpose of encapsulation?
Encapsulation is used to hide the values of an object's internal state
122
How should encapsulated attributes of an object be accessed or changed?
Encapsulated attributes should only be accessed or changed via the methods provided by that object.
123
How does encapsulation help maintain data integrity?
Encapsulation keeps data safe by preventing it from being accidentally altered by other parts of the program without using the object's provided methods.
124
What happens if you try to access an object's private attributes directly?
Attempting to directly access an object's private attributes will result in an error.
125
How are private attributes similar to local variables?
Private attributes are loosely like local variables in that they cannot be accessed directly from outside the object.
126
If you want to read or change an object's private attributes
what must you do?
127
Why are an object's methods usually public rather than private?
Methods are public because they need to provide controlled access to the object's private attributes
128
What error occurs if you try "person1.name = 't'" given that "name" is private?
An error occurs because "name" is a private attribute and cannot be assigned a value directly.
129
How does the method "set_name" protect the private attribute "name"?
The set_name method checks the input's length and only updates the private attribute if it meets certain criteria (e.g.
130
What would happen if you call person1.set_name("tom")?
The set_name method would validate "tom" as a valid input and update the private attribute "name" to "tom".
131
What is the key question to understand after watching this video?
What is encapsulation and how does it help to create robust programs?
132
What is polymorphism in object-oriented programming?
Polymorphism literally means something that occurs in several different forms and is derived from the Greek word meaning "many forms."
133
What are the two main types of polymorphism in object-oriented programming?
The two main types are static polymorphism and dynamic polymorphism.
134
How does polymorphism appear in Python when using the plus (+) operator?
The plus (+) operator acts differently depending on the context: it concatenates strings if the operands are strings
135
What is static polymorphism?
Static polymorphism allows multiple methods of the same name but with different parameters within the same class
136
What are the ways parameter sets can differ for method overloading to work?
Parameter sets must differ by either the number of parameters
137
Why is changing the order of parameters in method overloading not considered good practice?
Because it can cause confusing programs.
138
What is dynamic polymorphism?
Dynamic polymorphism occurs when a subclass overrides a method of its superclass
139
Give an example of dynamic polymorphism with animals.
A generic bird class has a method make_sound() that outputs "chirp." The duck subclass overrides this to "quack