1 - Fundamentals of programming Flashcards
(45 cards)
What is SELECTION and nested selection? Give an example of both.
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
What is ITERATION? Name the different types and give examples.
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
Define variable/ constant declaration
Process of defining variables and constants in terms of a name and a data type
Define assignment
Process of giving a value to a variable or constant
Define a subroutine
A named block of code carrying out a specific task saving the rewriting of the same code over and over
Why is it important to have meaningful identifier names?
- 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
Advantages of constants:
3
- 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_
Define constants :
An item of data who’s value doesn’t change
Define variables
Short term memory used to store temporary values
How do you do exponentiation in c#?
Math.Pow(3,2)
–> 3^2 = 9
Difference between rounding and truncating:
Rounding decreases the number of digits while maintaining a value approximately equivalent.
Truncating (Match.Truncate) cuts of numbers after a certain dp.
Define exception handling:
Process of dealing with events causing the current subroutine to stop (errors). EG division by 0, so use try and catch
Name the 3 types of errors and explain:
Syntax error –> forgot closing bracket or misspelling
Run - time error –> Works fine but breaks when run
Logic error –> program runs but gives incorrect answer
Define local variables:
Only accessible within the subroutine and exist only while the subroutine is executing.
Define global variables:
Accessible from all parts of program
Defined at top in c#
Why locals more desirable than global?
+ 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
Recursion:
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
Stack frames:
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
Debug
Process of finding and correcting errors in a program
Define a subroutine
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
Uses of subroutines
Allow for:
Reuse of code
Structure your programming
Easily incorporate other people’s code
Subroutines by ref
Directly changing the value and anything happening to it within procedure will change the original value
What does a parameter do?
Allows to pass values to procedures an fucntions that you declare.
What are arguments?
The piece of data given to a function when called