Programming And Data Structures Flashcards Preview

Computer Science - Year 1 > Programming And Data Structures > Flashcards

Flashcards in Programming And Data Structures Deck (39):
1

Difference between switch and if statements

-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

2

What is the ternary operator?

-‘?’ 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

3

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

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 +)

4

How do you generate Random numbers?

-using random class
-Random rnd = new random() then rnd.next(x,y)
-lower bound is inclusive, upper bound is exclusive

5

What is command line input?

-Uses the ability of programs to have data passed into them from outside the program
-all command line input is strings

6

What are the two types of string literals?

-quoted: normal string with speech marks
-@quoted: start with @ as well as speed marks

7

How do we read contents from a file?

-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

8

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

-.ReadAllLines reads the whole file into memory
-.ReadLines reads each line as a text string which can be looped through with a foreach loop

9

How do i write text to a file?

-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

10

1) what is a class?
2) what is an object?

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

11

Difference between methods and properties?

-Methods are what an object can do
-Properties are the description of the object

12

What is the class identifier?

Name given to class

13

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

-Data members (variables and constants)
-Functions

14

What’s a void function?

Returns no values

15

What is the declaration of an object called?

Instantiation

16

What are constructors?

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

17

What is a static class member?

-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

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

-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

What is the ‘out’ keyword

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

20

What is method overloading?

-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

What is a methods signature?

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

22

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

-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

What are constructors?

-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

What is a destructor?

-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

What is an array?

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

26

What are the 2 types of 2D array?

-Rectangular and jagged?

27

What is a rectangular array?

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

28

What is a jagged array?

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

29

What are collections?

-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

What are the two types of collections?

-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

An example of a non-generic collection?

-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

Example of generic collection?

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

33

Difference between verification and validation?

-verification = Are you building it right?
-validation = are you building the right thing?

34

What is black box testing?

-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

What is white box testing?

-validates internal program logic
-detects design and logic errors
-can detect if program is performing its expected functions or if its missing functionality

36

Name some types of black box testing

-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

Name some types of white box testing

-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

What are exceptions?

-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

How many bits in....
1)short
2)int
3)long
4)float
5)double
6)decimal

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