Comp Sci Ch 7 Ch 8 Flashcards

1
Q

What is a function?

A

grouping of statements for repeatedly used operations
- a named list of statements

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

function definition vs call

A

definition - function’s type, name, parameters and block of statements
call- name and arguments

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

what is a return statement?
and what is void

A

can return only one
void function does not return

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

what is a parameter? and how does it look

A

a function input specified in a function definition
type and name

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

what is an argument?

A

a value provided to a functions parameter during a call

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

what are multiple parameters separated by

A

comma

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

order in which program should run when declaring functions

A

declare before main and then call in main (this one better)
OR
declare header (but instead of {, have ;) before main then call in main and then define after main

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

what is modular development?

A

dividing program into separate modules that can be developed and tested separately and then integrated into one single program

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

what is incremental development?

A

a process of writing, compiling and testing a small amount of code

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

what is a function stub?

A

a function definition that statements have not been written
-write the header, braces, and return 0
-because just want it to complie

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

what is unit testing?

A

process of individually testing a small part or unit of a program

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

what is a test bench?

A

test harness
a separate program whose purpose is to check that a function returns

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

what is a test vector?

A

each unique set of input values

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

how would you use a test vector?

A

cout what you are testing, what you expect and what you got by calling function with literals to test

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

what predefined function can you use to test a function what does it do and what do you have to include

A

include <cassert></cassert>

assert( functionName(literal arguments) == what you should get)
- it exits program if input expression is false and tell you the line and expression

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

what is the one function you will never call

A

main

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

difference between type functions and void

A

types return a value
void functions cout or update values but do not return

18
Q

a variable you declare in a function…

A

does not exist outside that function

19
Q

what is the common method to swap variables

A

temp variable

20
Q

what is scope?

A

the name of a defined variable or function item is only visible to a part of a program

21
Q

what is a global variable? and why should we use very little

A

variable declared outside any function and reaches into functions
- because of naming and updates so it is limited to const variables

22
Q

what is a preprocessor

A

a tool that scans the file top to bottom looking for any lines that begin with #

23
Q

what is # called

A

hash symbol

24
Q

what does a line with # do

A

directs preprocessor to modify the file in some way before compilation continues

25
Q

what is #include called?

A

preprocessor directive
- directs compiler to replace that line by the contents of the given file name

26
Q

including a file with “” vs <>

A

””- preprocessor to look for the file in some directory/folder as the including file
<>- looks in the system’s standard library folder/directory

27
Q

adding .h to the back of a file name under “” does..

A

any file that will be included in another file

28
Q

what is a stack frame?

A

each function creates a new set of local variable

29
Q

what does a return do to local variables

A

discards them

30
Q

what is a parameter

A

into that a functions needs to do its job and tends to get it from another function

31
Q

how can we share info between main and other functions

A

with parameters

32
Q

what is a pass by value parameter

A

communicates from other function a value or piece of data
- can communicate into but not out (needs a return)
- only allows one piece of into to exit out

33
Q

what is a pass by reference parameter?

A

communicates info regarding the location of a piece of data
-passes in the memory address of where info it so that function can go find it
- both in and out of function

34
Q

what is a const pass by reference parameter

A
  • still shares location but is limited to only read
  • just read only to that function that has it as a const parameter
35
Q

we are default to what parameter except when..

A

pass by value except when:
1- need to communicate more than one piece of info to the calling function…returning more than one
2- if parameter is large data type ( string or vector of 10 elements or more)

36
Q

what is the main difference between pass by value and reference parameters

A

value - passes in a value and
needs a return statement
reference- passes in a location address and do not need a return statement because retuning more than one ( so use void functions)

37
Q

what type of function can use reference parameters

A

void because these do not return

38
Q

how a void function with a reference parameter works and is called

A

call 1st to update values
then output the arguments that correspond to the reference parameters

39
Q

simple steps to make a function

A
  1. what type needs to be returned
  2. meaningful name
  3. figure out parameters - what does function need from main (or the calling function)
  4. ask if need pass by reference parameters - based on how many to return or if a large data type
  5. body and return (if applicable)
  6. call it - void with no cout, later cout the arguments called that correspond to the reference parameters - return type, with cout
40
Q

how to call a function with reference parameters

A

you only need the & in the definition function
- when calling put the variables you created in the call
- then cout those variables that correspond to the reference ones in the function