Flashcards in Programming And Data Structures Deck (39):
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
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
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 +)
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
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
What are the two types of string literals?
-quoted: normal string with speech marks
-@quoted: start with @ as well as speed marks
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
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
How do i write text to a file?
-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
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
Difference between methods and properties?
-Methods are what an object can do
-Properties are the description of the object
What is the class identifier?
Name given to class
What two types of things can be contained in a class?
-Data members (variables and constants)
What’s a void function?
Returns no values
What is the declaration of an object called?
What are constructors?
-Take in parameters and change the private values equal to these values
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
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
What is the ‘out’ keyword
-can be used in the method header specifically for returning values
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
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
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
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
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
What is an array?
Collection of elements with the same data type accessed through an index
What are the 2 types of 2D array?
-Rectangular and jagged?
What is a rectangular array?
-require nested brackets when inserting values during declaration
-can also manually elements to each co-ord
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]
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
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)
An example of a non-generic collection?
-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))
Example of generic collection?
-stores key-value paris where the key must be unique
-use ContainsKey() method to check key doesn’t exist
Difference between verification and validation?
-verification = Are you building it right?
-validation = are you building the right thing?
What is black box testing?
-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
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
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
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
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)