Extra Notes Flashcards

1
Q

return vs void functions

A

use & sparingly, only use when you really need them

if you only need to return 1 value, just use non-void function

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

char

A

for single digit inputs

eg. user inputs an answer “b” for an exam

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

string

A

for multiple digit/char inputs

eg. user inputs their first name

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

”” and ‘’

A

can use either single or double quotations for characters and strings

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

partially filled arrays: prompting user

A

useful to write:

cout &laquo_space;“please write up to “ &laquo_space;DECLARED_SIZE &laquo_space;” numbers terminated with “ &laquo_space;SENTINEL;

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

eg of program to square a sequence of numbers

A

1) initialise
2) cout request for input
3) readtosentinel() to read in inputs
4) use square_array() function which can use square() function
5) use print_array() function to print results

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

functions and expressions

A

can put expressions into functions

eg. approx = newtonsqrt(n, n/2);

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

efficiency using !

A

instead of:
while (function(x) = false)

you can write:
while (!(function(x)))
if function is a bool

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

efficiency with if statements and bool returns

A

if (n%f == 0)
return true;
else
return false

can be shortened to:

return(n%f == 0);

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

using constants like Pi

A

declare PI at start, ie.
const int PI/const double Pi = …..

then use as such:
area = d/2 * d/2 * PI;

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