Programming Fundamentals Flashcards
Compiler
translate high-level language into machine language
levels of programming languages
- higher level language
- assembly language
- machine lanuage
- hardware
generations of programming language
- first: machine code → 0,1
- second: assembly language → MV, R1, R2
- third: C++, Java → IF TRUE THEN, END IF;
- fourth: SQL, assorted artificial intelligence language → SELECT FIRST_NAME FROM EMPLOYEE;
C++ programming language
- general purpose programming language
- based on keywords
// → comments
#include → pre-processor instruction to include code of standard library
int main(0) → declaration of function
{…..} → statement specifiying behaviour of program
variables
defined in programming language, used to perform operations
- name & type → determines operations possible to perform
- variable declaration: int numberOfStudents;
bool → boolean [TRUE, FALSE]
char → character [‘a’, ‘n’, ‘3’]
int → integer [1, 30, 4578]
double → floating point number [3.29, 1.57]
values
assigend to variale name via assignment operator “=”
- variable assignment: numberOfStudents=200;
one might initialise variable when declaring it
type sizes
- corresponds directly to hardware facilities
- fixed size that determines range of values that can be stored
bool → 1 byte (8 bit)
char → 1 byte
int → 4 bytes
double → 8 bytes
array data strucutre
store collection of values of a given type
- char v[6] → array of 6 characters → 6 bytes to store character in
control structures
selection: decision which pathway is taken → TRUE & FALSE
- if & switch (depending ong implemented case different outcome)
iteration (loop): repeat certain path whilst true
- while → as long as condition is true, command is repeated
- for → repeat for a certain amount
sequence: one command after another
function declaration
Functions require a delcaration to be called - declaration: give the name of the function, type of value returned, number of types of arguments void exit(int); → int argument and return nothing double sqrt(double); → double argument & return double double s2 = sqrt(2); → call sqrt with argument double {2} double s3 = sqrt("three"); → error
motivation for functions
- break up complicated & long computations into meaningful chunks & name them
- coding recommendation for one function: 40 lines/7 lines
goal: comprehensible
Function definitions
- every function must be defined somewhere
- need to be defined once
- function definition is a function declaration in which the body of the function is presented
C++ vs. python
python - young language - easy use and readability - "write once, use anywhere" - has to be interpreted → slower C++ - more complicated - easily transferable to wide variety of applications - need to be complie on application system before it can execute - nearer to the hardware → faster
threshold binary
values above a certain threshold are 1/”TRUE”, values below are 0/”FALSE”
→ loss of information
threshold to zero
only values below threshold are 0
→ information is preserved