Comp 1312 Programming 1 Flashcards

1
Q

What does an f string do?

A

An f string tells python to sub in all the variables, placed inside the curly brackets into the string

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

What are the concepts for quality code?

A

Duplication
Coupling
Cohesion

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

What is duplication?

A

An indicator of bad design where code has been copied, harder to maintain.

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

What is coupling?

A

Links between separate modules of a program
We aim for loose coupling.

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

What is loose coupling?

A

Understanding one item without reading another so we can change one function without changing another.

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

What is the Noun/Verb method?

A

Identifying nouns to reveal potential identifiers.

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

What is C?

A

Imperative procedural programming language, compiled, statically typed with low-level access.

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

What is a header file?

A

How extra modules are imported in C

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

List some default types in C

A

INT
FLOAT
DOUBLE
CHAR
_Bool

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

What are type specifiers?

A

Keywords that change the amount of data associated with a type

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

What happens if we initialise a variable at it’s highest value and then add one?

A

An overflow

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

What is implicit type conversion?

A

When a type can be converted to another without specific instructions to do so, e.g integer to float.

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

What does the Const keyword do?

A

Makes the variable constant and thus read only

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

What is the difference between ++n and n++?

A

Pre-increment and post-increment

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

What are strings really?

A

Arrays of chars

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

What is the placeholder symbol for a string?

A

%s

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

What is a structure?

A

Group elements of different types into one object

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

What can a structure be considered to be?

A

A data template

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

How can a structure be accessed?

A

structure_name.structure_item;

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

What does typedef do?

A

Assigns a new name to existing types and new data types, including structures

typedef int counter;
counter x,y;

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

T/F A function can return an array.

A

False

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

T/F A function can return an structure.

A

True

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

T/F You can have nested structures

A

True

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

What is a pointer?

A

A variable that stores a memory address

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

What could be an issue when memory is not cleared correctly?

A

Any variables declared get whatever value is at the location they are assigned

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

What does the sizeof function return?

A

The number of bytes taken up by the type submitted as it’s operand.

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

How can you calculate the length of an array?

A

sizeof(array)/sizeof(type)

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

What is the symbol for the address operator?

A

&

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

What would &var return?

A

The address the var variable is being stored at.

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

How can a pointer be declared?

A

double *p = &var;

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

Why is a type declared with a pointer?

A

So the pointer knows how many bytes belong to the variable.

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

What is the dereference operator?

A

*p
This is the same as just accessing a variable

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

Why can a pointer be incremented?

A

To access multiple elements in an array.

34
Q

What does the malloc function do?

A

Allocate a specific amount of bytes in memory and returns the base address of these bytes.

35
Q

What does the free function do?

A

Returns the pointer and associated memory back to the heap

36
Q

What does the realloc function do?

A

Changes the size of previous allocated memory by inputting a pointer and a new size

37
Q

What does the calloc function do?

A

Allocates a certain amount of blocks to the size specified

calloc(n_blocks,sizeof(int))

38
Q

When do memory leaks occur?

A

When memory isn’t correctly returned to the heap.
Or when a pointer is reinitialised without freeing the original memory

39
Q

How can we output to a file?

A

./myfile > data

40
Q

How can we input from a file?

A

./myfile < data

41
Q

What does EOF stand for?

A

End of File
Returned by getchar and scanf when the reach the end of their inputs?

42
Q

What are the f functions?

A

Function for reading and writing to files, such as:
fopen
fclose
fprint
fscanf
fgets

43
Q

How are preprocessor statements indicated?

A

#

44
Q

What does #define do?

A

define PI 3.14159268

Replaces every instance of PI with constant 3.14

45
Q

What happens if you place a hash in front of of the parameter in a preprocessor statement?

A

It will create a constant string out of the macro-argument
#define str(x) # x

46
Q

What is a local variable?

A

Variables only accessible from the scope they are defined in.

47
Q

T/F Does python support multiple return arguments?

A

True

48
Q

What does the global keyword do?

A

Tells python to look for a global variable and make it accessible from this function

49
Q

How can list comprehension be accomplished?

A

[expression for item in collection if condition]

squares = [x**2 for x in range(5)]
[0,1,4,9,16]

50
Q

What is aliasing?

A

When two or more variables refer to the same object within memory, instead of copying the list another variable is given the memory address for the list

The copy method solves this problem

51
Q

What is a ragged list?

A

A multidimensional list where the sublists have varying lengths

52
Q

What is a dictionary?

A

A collection of key-value pairs where each key is unique

53
Q

How is a file opened in python?

A

with open(file,mode) as file:
content=file.read()

54
Q

List some of the possible file access modes

A

r - read
w - write
a - append
r+ - read and write, file starts at beginning
w+ - read and write, create file if not exists
x - exclusive creation
b - binary file
t - text file

55
Q

What does the strip function do?

A

Removes any leading or trailing whitespace characters

56
Q

How can a csv file be opened?

A

Using the csv module and csv.reader
csv.dictreader
csv.writer

57
Q

What are the characteristics of an algorithm?

A

Performance
Efficiency
Understandability
Scalability
Reusability
Reliability
Elegance

58
Q

What happens if the specification for a program is inadequate?

A

Assumptions

59
Q

What is UML?

A

Unified Modelling Language

60
Q

What is a synchronous message?

A

Requires a response before the interaction can continue?

61
Q

What is a reflexive message?

A

A message an object sends to itself

62
Q

What is an alternative fragment?

A

When a choice needs to be made between two or more message sequences

63
Q

What is a loop fragment?

A

Represents a repetitive sequence

64
Q

What is an IDE?

A

Integrated Development Environment.

65
Q

What could an IDE contain?

A

A code editor
Build automation
A debugger
Version control

66
Q

What are common features of a source code editor?

A

Syntax highlighting
Code completion
Refactoring
Version control
Code search

67
Q

What are the coding styles for python?

A

PEP8
PEP257

68
Q

Give some general good practise coding points

A

Avoid over doing whitespace
Documentation strings

69
Q

What are the testing strategies?

A

Blackbox
Equivalence classes
Boundary value
Cause-effect
Error guessing
Whitebox
Statement coverage

70
Q

What are some human-based testing methods?

A

Walkthroughs
Code inspections
User testing

71
Q

What are some computer-based testing methods?

A

Print statements
Logging
Pytest

72
Q

What are the error-locating principles?

A

Review your code
Describe your problem to others
Debugging tools
Avoid code experimentation

73
Q

What are the fundamental software engineering activities?

A

Specification: Define the functionality
Development: Produce the software
Validation: Validate it does as client expected
Evolutions: Meet the client’s changing needs

74
Q

What is DevOps?

A

Developers write software
Operators maintain it
DevOps is combining these teams to improve efficiency

A set of processes, ideas and technologies to make software delivery more efficient.

75
Q

What is continuous integration?

A

Frequently committing code to a central repository, automate building and testing

76
Q

What is continuous delivery?

A

Release software update to end users using automation
Follow continuous integration

77
Q

What is continuous deployment?

A

Automates the deployment of code releases

78
Q

How does Github support continuous integration?

A

Through github actions
Adding actions that run on every push for testing and other

79
Q

What are equivalence classes?

A

The set of input values that have the same result.

80
Q

What is cohesion?

A

The degree of which elements of a module are related to each other