Programming And Data Structures Flashcards

1
Q

Difference between switch and if statements

A
  • No condition, just value used
  • input is compared to each of the values in each of the statements until a match is found
  • if no match found, flow goes to default case
  • cannot test fractional values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the ternary operator?

A
  • ‘?’ Condenses whole if statement into 1 line
  • “condition ? Expression1:expression2;
  • first condition must be boolean
  • if statement is true first condition will be met, if its false vise versa
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

1) what does break command do?
2) what does continue command do?
3) what is ‘uint’

A

1) command takes control to the first command after while loop
2) ignores everything in loop on current pass and goes to the top of the loop again
3) unsigned integer that has to be positive (takes up less memory as you know value is always +)

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

How do you generate Random numbers?

A
  • using random class
  • Random rnd = new random() then rnd.next(x,y)
  • lower bound is inclusive, upper bound is exclusive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is command line input?

A
  • Uses the ability of programs to have data passed into them from outside the program
  • all command line input is strings
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the two types of string literals?

A
  • quoted: normal string with speech marks

- @quoted: start with @ as well as speed marks

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

How do we read contents from a file?

A
  • add using system.io
  • create string to hole read-in text
  • use .readalltext to read
  • make sure filename is full path
  • make sure file exists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s the difference between .ReadAllLines and .ReadLines?

A
  • .ReadAllLines reads the whole file into memory

- .ReadLines reads each line as a text string which can be looped through with a foreach loop

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

How do i write text to a file?

A
  • add using.system.IO
  • 2 use File.WriteAllText(file name, text)
  • if we want to add onto end of existing file use File.AppendAllText
  • could also use the WriteAllLines variants of both of these to write line by line
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

1) what is a class?

2) what is an object?

A

1) defines a new type of object - defines its common characteristics
2) object is individual instance of that class

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

Difference between methods and properties?

A
  • Methods are what an object can do

- Properties are the description of the object

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

What is the class identifier?

A

Name given to class

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

What two types of things can be contained in a class?

A
  • Data members (variables and constants)

- Functions

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

What’s a void function?

A

Returns no values

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

What is the declaration of an object called?

A

Instantiation

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

What are constructors?

A

-Take in parameters and change the private values equal to these values

17
Q

What is a static class member?

A
  • when a class member is static it can invoked directly from the class level without creating an object
  • Allows us to refer to a class from within itself
  • makes members belong to the class itself instead of the individual objects
  • static methods can access only static members
18
Q

What are the two ways to pass data to a method?

A
  • passing by value: passes copy, original not affected
  • passing by reference: passes a reference to the memory location of the original variable. Original is affected
  • default is pass by value, have to put ‘ref’ key word (in method and calling statement )to pass by reference
19
Q

What is the ‘out’ keyword

A

-can be used in the method header specifically for returning values

20
Q

What is method overloading?

A
  • a class has 2 or more methods with the same name
  • they may have different types, number or order of parameters in parameter list
  • choice of method that is triggered is made on runtime and depends on the values being passed to the class
21
Q

What is a methods signature?

A
  • name, number, type and order of its parameters
  • should be different for each overloading method
  • changing return type will not affect the signature
22
Q

What do properties allow? What does value mean? What are accessor methods?

A
  • provide the opportunity to protect a field in a class by reading and writing to it through a property
  • consists of get and set method wrapped inside the property (called property accessor methods)
  • keyword ‘value’ refers to the value the user is trying to assign to a variable
23
Q

What are constructors?

A
  • used in initial set up or construction of an object
  • can contain same type/amount of code as method
  • can never return a value and has the same name as the class
  • if no constructor is defined the default constructor is called which sets all value to 0 or false
  • constructor with at least 1 parameter is called parameterised constructor. Can initialise each instance of a class with different values
  • can be overloaded
24
Q

What is a destructor?

A
  • called automatically by the runtime after an object of a class is no longer in use (as program ends)
  • defined by using the sqwiggle
  • can only have one, cannot be overloaded, cannot manually call it
25
Q

What is an array?

A

Collection of elements with the same data type accessed through an index

26
Q

What are the 2 types of 2D array?

A

-Rectangular and jagged?

27
Q

What is a rectangular array?

A
  • Table
  • has co-ordinates
  • require nested brackets when inserting values during declaration
  • can also manually elements to each co-ord
28
Q

What is a jagged array?

A
  • array of vectors (array of arrays)
  • 2 separate brackets during declaration
  • rank gets the dimensions os the array
  • accessed using [x] [y]
29
Q

What are collections?

A
  • data structures that hold data in different ways for flexible operations
  • dont have to define numbers of elements in a collection beforehand
  • size is not fixed and elements can be added and removed
30
Q

What are the two types of collections?

A
  • non generic: each element can be represent a different data type (stack, queue and array list)
  • generic: collection that can hold data of the same type (list, dictionary and sorted list)
31
Q

An example of a non-generic collection?

A
  • ArrayList
  • similar to array but has dynamic nature
  • can use ArrayList.Add/Remove
  • Elements are stored as objects
  • capacity gets or sets the number of elements the ArrayList can contain (different to length(count))
32
Q

Example of generic collection?

A
  • Dictionary
  • stores key-value paris where the key must be unique
  • use ContainsKey() method to check key doesn’t exist
33
Q

Difference between verification and validation?

A
  • verification = Are you building it right?

- validation = are you building the right thing?

34
Q

What is black box testing?

A
  • validates requirements
  • dont know whats going on inside program
  • only care about put and output of data
  • detect errors such as incorrect or missing functions
  • cannot detect design errors
35
Q

What is white box testing?

A
  • validates internal program logic
  • detects design and logic errors
  • can detect if program is performing its expected functions or if its missing functionality
36
Q

Name some types of black box testing

A
  • test of requirements: success and failure paths designed
  • boundary value analysis: test at max and min values and then 1 lower than the min and 1 higher than the max
  • cause effect graphics: for each effect ID the causes that produce the effect and draw a diagram
37
Q

Name some types of white box testing

A
  • Statement coverage: Write enough test cases to execute every statement at least once
  • Decision coverage: cases to exercise the true and false outcomes of every decision
  • loop testing: test loops
  • condition coverage: cases such that each condition in a decision takes on all possible outcomes at least once
38
Q

What are exceptions?

A
  • occur during run time
  • untaught programming errors
  • try and catch statements used to check for them
  • multiple catch statements can be used but they must go from specific problems (eg dividing by 0) to general problems (wrong number given)
39
Q

How many bits in….

1) short
2) int
3) long
4) float
5) double
6) decimal

A

1) 16
2) 32
3) 64
4) 32 with a smaller range
5) 64 with a bigger range
6) 128 with the highest precision of any values