cs 141 exam 2 review1 game show!. cs 141 exam 2 review2 whats wrong with this function bool foo...

133
Cs 141 Exam 2 Review 1 Game Show!

Upload: ernest-west

Post on 17-Jan-2018

223 views

Category:

Documents


0 download

DESCRIPTION

Cs 141 Exam 2 Review3 Whats wrong with this function void doubleIt(int num){ num = 2* num; }

TRANSCRIPT

Page 1: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 1

Game Show!

Page 2: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 2

Whats wrong with this function

bool foo (int, double){return true;

}

Page 3: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 3

Whats wrong with this function

void doubleIt(int num){num = 2* num;

}

Page 4: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 4

Whats wrong with this function

int double bar(int num){return num;

}

Page 5: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 5

Whats wrong with this function

void doubleIt(int num){return 2* num;

}

Page 6: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 6

void baz (int num1, int &num);

Which is the call by value parameter and which is the call by reference parameter?

Page 7: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 7

What does call by value mean?

Page 8: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 8

What does call by reference mean?

Page 9: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 9

• In what ways do return values and call-by-reference parameters accomplish the same thing. In what ways are they different?

Page 10: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 10

• What are the limitations of return values versus call-by-reference parameters?

Page 11: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 11

void bar(int numArray[]){

}

Is numArray call by value or call by reference?

Page 12: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 12

What do you have to do to make an array parameter call by value?

Page 13: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 13

What is the purpose of assertions?

Page 14: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 14

What is meant by a global variable?

Page 15: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 15

Where are global variables declared?

Page 16: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 16

• If the following function compiles then what is a?

void func1(int b){ a = b;}

Page 17: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 17

int a=10; what output?

void func2(int b){ int a; a = b;} void func3(){ cout << a;} int main(){

func2(5);func3();

}

Page 18: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 18

• C-strings are a bit like our big Integers. We had arrays of 1000 locations we could use to store digits, but for any given big Integer, we may only use a few of those locations. C-strings are an array of characters but for any given string we may only use a few of the characters in the full array.

• In bigIntegers, how did we determine how many locations hold the digits of our number?

• In C-strings, how do we determine how many locations hold the characters in our string?

Page 19: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 19

• We've learned quite a few preexisting functions that we can use when programming.

• What functions did we use to generate random numbers?

Page 20: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 20

• What functions did we use to convert c-strings to numbers?

Page 21: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 21

• What functions did we use to test if a character was whitespace? Or a digit?

Page 22: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 22

• Some pre-existing functions we've learned belong to classes.

• What function did we learn to get the c-string equivalent of a C++ string?

Page 23: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 23

• What is the difference between exit and return?

Page 24: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 24

• Do return and exit have a different effect when called in the main function?

• Do return and exit have a different effect when called in another function?

Page 25: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 25

• Is int main() in our basic template a function?

Page 26: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 26

• What is special about the main function?

Page 27: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 27

• What is the difference between break and continue?

Page 28: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 28

• What function did we learn to open a file?

Page 29: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 29

What is the type of variable used for output files?

Page 30: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 30

What is the type of variable used for input files?

Page 31: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 31

• What is the difference between get and peek?

Page 32: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 32

• What two functions can be used to allocate memory dynamically?

Page 33: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 33

• If you allocate memory with malloc, what function should you use to deallocate it?

Page 34: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 34

• If you allocate memory with new what function should you use to deallocate it?

Page 35: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 35

• What is the difference between a plain array of characters and C-string?

Page 36: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 36

Suggest an assertion to test the preconditions of this function:

/* precondition: a and b are positive */void func7(int a, int b);

Page 37: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 37

• What is a function prototype?• How is it useful?

Page 38: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 38

• Propose a struct to hold a song type

Page 39: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 39

• Declare a variable of type song and initialize it to represent an actual song that you like.

Page 40: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 40

• Propose a struct to hold a BigInteger type?

Page 41: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 41

• Declare a variable of type BigInteger and initialize it to represent the variable 89.

Page 42: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 42

How do you test if a file open succeeds?

Page 43: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 43

How do you test if a file read or write succeeds?

Page 44: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 44

How do you test if you read all the contents of a file?

Page 45: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 45

If I did this ./a.out inputFile.txt

What would argc be?

Page 46: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 46

If I did this ./a.out inputFile.txt

What would argv[1] be?

Page 47: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 47

What type/types hold the following: 0,1,-1,2,-2,...

Page 48: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 48

What is the main difference between the values that can be stored in an int variable and the set of all integers that you learned about in math?

Page 49: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 49

What type/types hold the following:0,1,2,3,4,...

Page 50: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 50

What type/types could be legitimately substituted for TYPE

TYPE foo = 4;

Page 51: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 51

What is the main difference between a float and a double?

Page 52: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 52

int bar = 23/4;

What is bar?

Page 53: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 53

int foo = 23%4;

What is foo?

Page 54: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 54

float bop = 23/4;

What is bop?

Page 55: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 55

int baz;

What is the value of baz?

Page 56: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 56

What are three ways to initialize the value of a variable?

Page 57: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 57

What would happen if you did this:

const int foo = 5;

foo = 10;

Page 58: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 58

Is this a valid comment?

/* Written by Jeanna

Page 59: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 59

Is this a valid comment?

\\ Written by Jeanna

Page 60: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 60

What are two ways to write a valid comment?

Page 61: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 61

Declare a variable to hold someone's last name.

Page 62: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 62

Declare a variable to hold someone's age in years.

Page 63: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 63

Declare a variable to hold someone's hourly wage.

Page 64: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 64

Declare a variable to hold someone's middle initial.

Page 65: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 65

If you wanted to declare a variable to keep track of the number of times someone blinks in a year, what would be a good choice for the type and why?

Page 66: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 66

What does != mean?

Page 67: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 67

What is the difference between = and ==?

Page 68: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 68

What does && mean?

Page 69: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 69

What does || mean?

Page 70: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 70

What is the difference between:cin >> foo;cout << foo;

Page 71: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 71

What type/types hold the following: 'a' '\n' '4'

Page 72: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 72

Which of these lines is not like the others?

foo++;++foo;foo+=1;foo = foo +1;foo+1;

Page 73: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 73

What is wrong with this?

if ((answer == ‘y’) | (answer == ‘Y’)){cout << “User entered yes\n”;

}

Page 74: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 74

What is wrong with this?

if ((answer == ‘y’) && (answer == ‘Y’)){cout << “User entered yes\n”;

}

Page 75: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 75

What will happen if you do this?

num =3;if (num =2){

cout << “Number is 2\n”;} else {

cout << “Number is not 2\n”;}

Page 76: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 76

What will happen if you do this

num =3;if (num !=2){

cout << “Number is not 2\n”;} else if (num < 4) {

cout << “Number is less than 4\n”;} else if (num >0){

cout << “Number is greater than 0\n”;}

Page 77: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 77

What is the value of BAZ below?

enum SillyNames {FOO=1, BAR, BAZ};

Page 78: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 78

Declare an enum of the days of the week.

Page 79: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 79

What is the advantage of declaring an enum?

Page 80: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 80

Are these two boolean expressions the same?

(x >=10)

((x ==10) && (x > 10))

Page 81: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 81

There are 3 different types of clauses in an if statement: if, else if and else

How many of each can you have?

Page 82: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 82

Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions

total =0;i=0;while (i< 10){total = total +i;i++;}cout << total;

Page 83: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 83

Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions

for(i=0; i< 10; i++){total = total +i;}cout << total;

Page 84: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 84

Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions

howMany=0;while(input_stream >> num){howMany++;total = total + num;}average = total/howMany;

Page 85: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 85

If homMany and total are ints, what problem will be have computing average? What could we do to fix the problem? What type should average be?

howMany=0;while(input_stream >> num){howMany++;total = total + num;}average = total/howMany;

Page 86: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 86

int numbers[3];

How many ints are declared?How would you refer to the first one?The last one?Write a for loop to add them all up

Page 87: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 87

int numbers[3][2];

How many ints are declared?How would you refer to first one?How would you refer to the last one?Write a for loop to add them all up.

Page 88: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 88

If you want to read from or write to a file what must you add to our basic template?

Page 89: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 89

#include <fstream>

Page 90: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 90

Declare a variable to hold a file you want to read from

Page 91: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 91

ifstream input_file;

Page 92: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 92

Declare a variable to hold a file you want to write to.

Page 93: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 93

ofstream output_file;

Page 94: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 94

How would you open the file “foo.txt”?

Page 95: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 95

fileVariable.open(“foo.txt”);

Page 96: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 96

If you try to open a file, what type of error should you check for and how do you do that?

Page 97: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 97

Check if weren't able to open the file

fileVariable.open(“foo.txt”);

if (fileVariable.fail()){cout << “Couldn't open the file\n”;}

Page 98: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 98

How would you open the file foo.txt?

Page 99: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 99

What does it mean to have a if statement nested inside a loop?

Page 100: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 100

What does it mean to have nested for loops?

What are nested for loops especially good for?

Page 101: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 101

True or false: There are some problems for which you must use a do-while loop. A while loop just won't work.

Page 102: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 102

When is it generally better to use a do-while loop instead of a while loop?

Page 103: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 103

When is it generally better to use a for loop instead of a while loop or do-while loop?

Page 104: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 104

When you get a bunch of compiler errors which one should you fix first and why?

Page 105: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 105

If you are trying to fix a specific compiler error, how can you figure out where the problem is?

Page 106: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 106

What is a fence post error?

Page 107: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 107

If you were going to test this loop what would be three great values of x to test? Why?

cin >> x;for (int i=0; i< x; i++){cout << i;}

Page 108: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 108

Will these do the same thing?for (i=0; i< 3;i++ )

cout << i;

for (i=0;i< 3 ){cout << i;

i++;}

Page 109: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 109

Will these do the same thing?for (i=0; i< 3;i++ )

cout << i;

i=0;while (i< 3 )

cout << i++;

Page 110: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 110

What would you expect to happen if you did this

int numArray[5];numArray[5] = 100;cout << numArray[5];

Page 111: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 111

Whats wrong with this

int numArray[9];for (int i=0; i<=9; i++){

numArray[i] = i;}

Page 112: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 112

Do these all do the same thing?

cout << num << “\n”;

cout << num << endl;

cout << num;cout << “\n”;

Page 113: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 113

What child of a famous British poet is often considered the first programmer?

Page 114: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 114

Ada Byron Lovelace (1815-1852)

Page 115: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 115

Who is the creator of C++?

Page 116: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 116

Bjarne Stroustrup

Page 117: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 117

Who is the creator of the C programming language and a co-author of the UNIX operating system?

Page 118: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 118

Dennis Ritchie

Page 119: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 119

Explain the joke in the name C++

Page 120: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 120

Who coined the term “debugging” and wrote the first compiler for a computer programming language?

Page 121: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 121

Rear Admiral Grace Hopper

Page 122: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 122

Picture of the moth that was the first computer “bug”

Page 123: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 123

Who is this?

Page 124: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 124

Linus Torvalds author and developer of Linux

Page 125: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 125

Who is this?

Page 126: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 126

Steve Jobs, co-founder and CEO of Apple Corporation

Page 127: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 127

Who is this?

Page 128: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 128

Steve Wozniak, co-founder of Apple Corporation

Page 129: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 129

What does IBM stand for?

Page 130: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 130

International Business Machines

Page 131: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 131

Who is considered the founder of IBM?

Page 132: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 132

Thomas J. Watson

Page 133: Cs 141 Exam 2 Review1 Game Show!. Cs 141 Exam 2 Review2 Whats wrong with this function bool foo (int, double){ return true; }

Cs 141 Exam 2 Review 133

Give me an example of function overloading?