1 - Fundamentals of programming Flashcards

1
Q

What is SELECTION and nested selection? Give an example of both.

A

Selection - the process of choosing what action to take based on certain criteria, EG If, else and case

Nested selection - the process of placing one set of instructions with another, EG Else If

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

What is ITERATION? Name the different types and give examples.

A

Iteration - repeating the same thing again and again
Definite –> repeats set number of times
EG For loop
Indefinite –> repeats until condition is met
EG Do While
Nested –> for within a for

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

Define variable/ constant declaration

A

Process of defining variables and constants in terms of a name and a data type

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

Define assignment

A

Process of giving a value to a variable or constant

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

Define a subroutine

A

A named block of code carrying out a specific task saving the rewriting of the same code over and over

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

Why is it important to have meaningful identifier names?

A
  • Easier to debug (find and correct errors)
  • Easier to update code when further versions of code are created
  • Easier to understand if several programmers working on it at once
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Advantages of constants:

3

A
  • If you want to change a value, you only have to change it in the constant declaration
  • Reduces likelihood of errors
  • Easier to read and understand (Of named constants_
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define constants :

A

An item of data who’s value doesn’t change

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

Define variables

A

Short term memory used to store temporary values

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

How do you do exponentiation in c#?

A

Math.Pow(3,2)

–> 3^2 = 9

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

Difference between rounding and truncating:

A

Rounding decreases the number of digits while maintaining a value approximately equivalent.
Truncating (Match.Truncate) cuts of numbers after a certain dp.

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

Define exception handling:

A

Process of dealing with events causing the current subroutine to stop (errors). EG division by 0, so use try and catch

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

Name the 3 types of errors and explain:

A

Syntax error –> forgot closing bracket or misspelling
Run - time error –> Works fine but breaks when run
Logic error –> program runs but gives incorrect answer

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

Define local variables:

A

Only accessible within the subroutine and exist only while the subroutine is executing.

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

Define global variables:

A

Accessible from all parts of program

Defined at top in c#

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

Why locals more desirable than global?

A

+ Once subroutine run, removed from memory (FREE UP MEMORY).Whereas global stay in the memory while the program is running
+ Can use same local name in different subroutines but treated as separate
+ Can’t accidentally change local value stored somewhere else in program
- Use global when want to declare variable needed to be accessible by all parts of code

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

Recursion:

A

Defining a subroutine within itself
+ Produce smaller, more natural solutions to a problem
- Take up a large amount of resources storing return addresses and states

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

Stack frames:

A

A collection of data about a subroutine
It stores:
- Return address - point it should go back to once down with call
- Parameters - data passed into a subroutine
- Local variables - variables in current subroutines that it should restore

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

Debug

A

Process of finding and correcting errors in a program

20
Q

Define a subroutine

A

A named block of code designed to carry out a specific task which saves the rewriting of lots of the same code again and again

21
Q

Uses of subroutines

A

Allow for:
Reuse of code
Structure your programming
Easily incorporate other people’s code

22
Q

Subroutines by ref

A

Directly changing the value and anything happening to it within procedure will change the original value

23
Q

What does a parameter do?

A

Allows to pass values to procedures an fucntions that you declare.

24
Q

What are arguments?

A

The piece of data given to a function when called

25
Q

Advantages of subroutines

A
  • Easier to test and debug as each subroutine is self contained
  • Very large projects can be developed by more than 1 programmer
  • Can use top-down approach to develop whole project
26
Q

What is procedural orientated programming?

A

Languages where the programmer specifies the steps needed to carry out to achieve a result
The adding of procedures so a program, especially long, is easier to work with

27
Q

Advantages of procedural orientated programming

A
  • Reuse code without retyping it, reducing time it takes to write
  • Less chance of bugs that would come about from rewriting
  • Clearer of what program does and how, as name of procedure explains what lines of code are for
  • Reduces length of program making it easier and faster to read and debug
  • Allow compilers to make more optimizations as compilers detect re-used code and use this to take shortcuts
28
Q

What is a hierarchy chart?

A

A diagram demonstrating the design of a system from the top down
- Starting from the program name, programmer breaks problem down into a series of steps. Each step then broken down into a series of steps

29
Q

Example of a hierarchy chart

A
  • Programs are made up of modules
  • Modules made up of subroutines
  • Subroutines made up of algorithms
  • Algorithms made up of lines of code
  • Lines of code made up of statements (instructions) and data
30
Q

Define Imperative programming

A

Languages based on giving computer commands and procedures to follow

31
Q

Define OOP

A

Uses objects to make code easier to read and work with

32
Q

What is a class?

A

Defines methods and property/attribute fields that capture the common behaviours and characteristics of objects
IE defines the properties and methods of a group of similar objects
EG car - colour - manufacturer etc

33
Q

What is an object?

A
A specific instance of a class
All have the same methods and properties from same class
Created by using a constructor, implicit or explicit and a reference to the object assigned to a reference variable of a class EG Nissan, blue
34
Q

What is instantiation?

A
Process of creating an object from a class
IE creating an actual instance of an object using the properties and methods described in the class
35
Q

What is encapsulation?

A

Concept of putting properties, methods and data in one object

36
Q

What is inheritance?

A

Concept that properties and methods in one class (base class) can be shared with a subclass

37
Q

What is aggregation?

A
Creating new objects creating existing ones based on how they are related 
EG Care may have passengers, they come and go
Repped by whit diamond line in class diagram
38
Q

What is composition aggregation?

A
Creating an object containing other objects that will cease to exist if the containing object (base class) is destroyed 
EG Every car has an engine 
Repped as black diamond in class diagram
39
Q

What is association aggregation?

A

Where an object is made up of 1 or more objects but isn’t entirely dependent on those objects for its own existence

40
Q

What is polymorphism?

A

Ability of different types of data to be manipulated with the same method

  • Classes inherit methods from base class but data in these new classes are different types
  • Instead of defining new methods, polymorphism enables original method to be redefined so that it will work with new data
41
Q

What is overriding?

A

Where a method described in subclass takes precedence over a method with the same name in the base class

42
Q

Advantages of OOP

A
  • Easy to amend programs as only effected method needs changing (as program written in modules)
  • Easy to add new functionality to a program by adding a new module
  • Groups of programmers can work independently on self-contained modules
  • Objects can inherit attributes and behaviors, making code reusable throughout program
  • Changes to code will not accidentally affect results of another routine
43
Q

What is a method?

A

The code or routines contained within a class

44
Q

What are the behaviours of methods?

A
STATIC - method can be used w/o an object of the class being instantiated 
VIRTUAL - method defined in the base class that can be overridden by method in subclass where it will be used (polymorphism) 
ABSTRACT - method not supplied in base class (hence provided in subclass). Object used as interface between method and data
45
Q

Name the design principles when using OOP

A

-Encapsulation that varies
Everything that varies should be out into its own class, hence methods and properties subdivided into as many classes needed to reflect real-life scenario
-Favour composition over inheritance
Use aggregation/ composition to combine existing objects to make new ones - less error prone and simpler maintenance
-Program to interfaces, not implementation
Programs written as interfaces (defines methods being used) rather than individual implementation of class