Programming Techniques Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the four main structures used in structured programming

A
  • Sequence - code is executed line-by-line
  • Selection - a certain block of code is run if a specific condition is met
  • Iteration - a block of code is executed a certain number of times or while a condition is met
  • Recursion - the function calls itself from within the function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the Advantages and Disadvantages of Recursion

A

Advantges -

  • Programmers can be written in fewer lines of code
  • Makes code less prone to errors

Disadvantges -

  • Its inefficient use of memory
  • Stack overflow cam occur which is when the call stack runs out of memory. This would cause the program to crash
  • Can be difficult to trace if using many function calls
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the Differences between Iteration and Recursion

A
  • Recursion uses more memory, Iteration uses less memory
  • Recursion uses a new set of variables (previously placed on stack), iteration uses same variables
  • Recursion can run out of memory, Iteration will not run out of memory
  • Recursion can express a problem elegantly (less lines of code), Iteration can take up more lines of code and is harder to follow
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is meant by the term Scope

A

The section of code in which a variable is available

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

What scope does a Local Variable have

A
  • Limited scope
  • They can only be accessed within the block of code in which they were defined.
  • If a local variable is defined within a subroutine, it can only be accessed within that subroutine.
  • Therefore, multiple local variables with the same name can exist in different subroutines and will remain unaffected by each other
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why are using Local Variables a good way to program

A

It ensures subroutines are self-contained, with no danger of variables being affected by code outside of the subroutine

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

What is the Scope of a Global Variable

A
  • Can be accessed across the whole program
  • All variables used in the main body of a program are automatically declared to be global
  • These are useful for values that need to be used by multiple parts of the program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the Disadvantages of using Global Variables

A
  • Global Variables can be unintentionally overwritten and edited (Local Variables take priority)
  • Global variables are not deleted until the program terminates so they require more memory than local variables which are deleted once the subroutine has been completed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Modular Programming

A

A programming technique used to split large, complex programs into smaller, self-contained modules

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

What is the benefit of using Modular Programming

A
  • Makes it easier to divide tasks between a team and manage
  • Simplifys the process of testing and maintenance, as each component can be dealt with individually
  • Improves the reusability of components
  • The Top-Down method is an example of Modular Programming
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Stepwise Refinement

A

Different name from the Top-Down method

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

What are the different between a procedure and function

A
  • Procedures do not have to return a value whilst functions always return a value
  • Procedures can return multiple values whereas a function must return one single value
  • Procedures are typically given data as parameters while functions commonly make use of local variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Passing by Value and Passing by Reference

A

Passing by Value -

  • Sends the actual value being used
  • This data is held in a separate memory location and is only available to the subroutine
  • Even if the value of the parameter is changed within the subroutine, the value of the original argument is unchanged

Passing by Reference -

  • This creates a pointer that contains the memory address of the original variable
  • Therefore, any change to the parameter within the subroutine also affects the value of the original variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an IDE (Integrated Development Enviroment)

A

A program which provides a set of tools to make it easier for programmers to write, develop and debug code

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

What are some examples of IDE tools

A
  • Stepping
  • Variable watch
  • Breakpoint
  • Source code editor
  • Debugging tools
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Stepping

A

This allows you to monitor the effect of each individual line of code by executing a single line at a time

17
Q

What is Variable Watch

A

Sometimes used to pinpoint errors, this is a useful feature to observe how the contents of a variable change in real-time through the execution of a program

18
Q

What is a Breakpoint

A
  • IDEs allow users to set a point in the program at which the program will stop
  • This can either be based on a condition or set to occur at a specific line
  • This can help to pinpoint where an error is occurring.
19
Q

What is a Source Code Editor

A

The editor aims to make the coding process easier by providing features such as autocompletion of words, syntax highlighting and automatic bracket completion

20
Q

What is a Debugger Tool

A

When the IDEs provides a run-time detection of errors with a guide as to where in the code they are likely to have occurred through line numbers and highlighting

21
Q

What is an Object-Oriented Paradigm

A
  • Based on objects formed from classes which have attributes and methods
  • Focuses on making programs that are reusable and easy to update and maintain
  • Suited to problems which can be broken into reusable components with similar characteristics
22
Q

What is a class

A

A template for an object which defines the attributes and methods of the object

23
Q

What are the Components of Object-Oriated Languages

A
  • State - given by attributes which give an object’s properties
  • Behaviour - defined by the methods, which describe the actions it can perform
  • Classes - templet for objects
  • Object - a particular instance of a class
  • Setter - a method that sets the value of a particular attribute
  • Getter - a special method used in object-oriated langauges which retrieves the value of a given attribute
  • Constructor - a method which allows a new object to be created
24
Q

What is the advantage of using Getters and Setters in object-oriented programming

A
  • Getters and setters ensure attributes cannot be directly accessed and edited
  • Attributes can only be accessed by public methods
  • This is called encapsulation
25
Q

What are the two properties of an object-oriented language

A

Inheritance

Polymorphism

26
Q

What is Inheritance and Polymorphism

A
  • Inheritance - a class can inherit from another class The subclass will possess all of the methods and attributes of the superclass (or parent class) and can have its own additional properties. This allows programmers to effectively reuse certain components and properties while making some changes
  • Polymorphism - objects can behave differently depending on their class. This can result in the same method producing different outputs depending on the object involved.
27
Q

What are the two different categories of Polymorphism

A
  • Overriding - when a method is redefined within a subclass so that it functions differently and produces a different output
  • Overloading - passing in different parameters into a method to produce a different output