Game Show!

117
Cs 141 Exam 1 Review 1 Game Show!

description

Game Show!. What type/types hold the following: 'a' '\n' '4'. What type/types hold the following: 0,1,-1,2,-2,. 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?. - PowerPoint PPT Presentation

Transcript of Game Show!

Page 1: Game Show!

Cs 141 Exam 1 Review 1

Game Show!

Page 2: Game Show!

Cs 141 Exam 1 Review 2

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

Page 3: Game Show!

Cs 141 Exam 1 Review 3

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

Page 4: Game Show!

Cs 141 Exam 1 Review 4

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 5: Game Show!

Cs 141 Exam 1 Review 5

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

Page 6: Game Show!

Cs 141 Exam 1 Review 6

What type/types could be legitimately substituted for TYPETYPE foo = 4;

Page 7: Game Show!

Cs 141 Exam 1 Review 7

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

Page 8: Game Show!

What happens if you add 1 to the largest possible int?

Cs 141 Exam 1 Review

Page 9: Game Show!

What values can ints hold that unsigned ints cannot?

Cs 141 Exam 1 Review

Page 10: Game Show!

What values can unsigned ints hold that ints cannot?

Cs 141 Exam 1 Review

Page 11: Game Show!

What values can floats hold that ints cannot?

Cs 141 Exam 1 Review

Page 12: Game Show!

Cs 141 Exam 1 Review 12

int bar = 23/4;

What is bar?

Page 13: Game Show!

Cs 141 Exam 1 Review 13

int foo = 23%4;

What is foo?

Page 14: Game Show!

Cs 141 Exam 1 Review 14

float bop = 23.0/4;

What is bop?

Page 15: Game Show!

Cs 141 Exam 1 Review 15

float bop = 23/4;

What is bop?

Page 16: Game Show!

Cs 141 Exam 1 Review 16

int baz;

What is the value of baz?

Page 17: Game Show!

Cs 141 Exam 1 Review 17

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

Page 18: Game Show!

Cs 141 Exam 1 Review 18

What would happen if you did this:

const int foo = 5;

foo = 10;

Page 19: Game Show!

Cs 141 Exam 1 Review 19

Is this a valid comment?

/* Written by Jeanna

Page 20: Game Show!

Cs 141 Exam 1 Review 20

Is this a valid comment?

\\ Written by Jeanna

Page 21: Game Show!

Cs 141 Exam 1 Review 21

What are two ways to write a valid comment?

Page 22: Game Show!

Cs 141 Exam 1 Review 22

Declare a variable to hold someone's last name.

Page 23: Game Show!

Cs 141 Exam 1 Review 23

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

Page 24: Game Show!

Cs 141 Exam 1 Review 24

Declare a variable to hold someone's hourly wage.

Page 25: Game Show!

Cs 141 Exam 1 Review 25

Declare a variable to hold someone's middle initial.

Page 26: Game Show!

Cs 141 Exam 1 Review 26

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 27: Game Show!

Cs 141 Exam 1 Review 27

What does != mean?

Page 28: Game Show!

Cs 141 Exam 1 Review 28

What is the difference between = and ==?

Page 29: Game Show!

Cs 141 Exam 1 Review 29

What does && mean?

Page 30: Game Show!

Cs 141 Exam 1 Review 30

What does || mean?

Page 31: Game Show!

Cs 141 Exam 1 Review 31

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

Page 32: Game Show!

Cs 141 Exam 1 Review 32

Which of these lines is not like the others?

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

Page 33: Game Show!

Cs 141 Exam 1 Review 33

What is wrong with this?

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

}

Page 34: Game Show!

Cs 141 Exam 1 Review 34

What is wrong with this?

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

}

Page 35: Game Show!

Cs 141 Exam 1 Review 35

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 36: Game Show!

Cs 141 Exam 1 Review 36

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 37: Game Show!

Cs 141 Exam 1 Review 37

What is the value of BAZ below?

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

Page 38: Game Show!

Cs 141 Exam 1 Review 38

Declare an enum of the days of the week.

Page 39: Game Show!

Cs 141 Exam 1 Review 39

What is the advantage of declaring an enum?

Page 40: Game Show!

Cs 141 Exam 1 Review 40

Are these two boolean expressions the same?

(x >=10)

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

Page 41: Game Show!

Cs 141 Exam 1 Review 41

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

How many of each can you have?

Page 42: Game Show!

Cs 141 Exam 1 Review 42

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 43: Game Show!

Cs 141 Exam 1 Review 43

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

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

}cout << total;

Page 44: Game Show!

Cs 141 Exam 1 Review 44

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 45: Game Show!

Cs 141 Exam 1 Review 45

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 46: Game Show!

Cs 141 Exam 1 Review 46

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 47: Game Show!

Cs 141 Exam 1 Review 47

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 48: Game Show!

Cs 141 Exam 1 Review 48

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

Page 49: Game Show!

Cs 141 Exam 1 Review 49

#include <fstream>

Page 50: Game Show!

Cs 141 Exam 1 Review 50

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

Page 51: Game Show!

Cs 141 Exam 1 Review 51

ifstream input_file;

Page 52: Game Show!

Cs 141 Exam 1 Review 52

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

Page 53: Game Show!

Cs 141 Exam 1 Review 53

ofstream output_file;

Page 54: Game Show!

Cs 141 Exam 1 Review 54

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

Page 55: Game Show!

Cs 141 Exam 1 Review 55

fileVariable.open(“foo.txt”);

Page 56: Game Show!

Cs 141 Exam 1 Review 56

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

Page 57: Game Show!

Cs 141 Exam 1 Review 57

Check if weren't able to open the file

fileVariable.open(“foo.txt”);

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

}

Page 58: Game Show!

Cs 141 Exam 1 Review 58

How would you open the file foo.txt?

Page 59: Game Show!

Cs 141 Exam 1 Review 59

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

Page 60: Game Show!

Cs 141 Exam 1 Review 60

What does it mean to have nested for loops?

What are nested for loops especially good for?

Page 61: Game Show!

Cs 141 Exam 1 Review 61

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

Page 62: Game Show!

Cs 141 Exam 1 Review 62

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

Page 63: Game Show!

Cs 141 Exam 1 Review 63

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

Page 64: Game Show!

Cs 141 Exam 1 Review 64

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

Page 65: Game Show!

Cs 141 Exam 1 Review 65

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

Page 66: Game Show!

Cs 141 Exam 1 Review 66

What is a fence post error?

Page 67: Game Show!

Cs 141 Exam 1 Review 67

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 68: Game Show!

Cs 141 Exam 1 Review 68

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

cout << i;

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

i++;}

Page 69: Game Show!

Cs 141 Exam 1 Review 69

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

cout << i;

i=0;while (i< 3 )

cout << i++;

Page 70: Game Show!

Cs 141 Exam 1 Review 70

What would you expect to happen if you did this

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

Page 71: Game Show!

Cs 141 Exam 1 Review 71

Whats wrong with this

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

numArray[i] = i;}

Page 72: Game Show!

Cs 141 Exam 1 Review 72

Do these all do the same thing?

cout << num << “\n”;

cout << num << endl;

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

Page 73: Game Show!

Cs 141 Exam 1 Review 73

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

Page 74: Game Show!

Cs 141 Exam 1 Review 74

Ada Byron Lovelace (1815-1852)

Page 75: Game Show!

Cs 141 Exam 1 Review 75

Who is the creator of C++?

Page 76: Game Show!

Cs 141 Exam 1 Review 76

Bjarne Stroustrup

Page 77: Game Show!

Cs 141 Exam 1 Review 77

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

Page 78: Game Show!

Cs 141 Exam 1 Review 78

Dennis Ritchie

Page 79: Game Show!

Cs 141 Exam 1 Review 79

Explain the joke in the name C++

Page 80: Game Show!

Cs 141 Exam 1 Review 80

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

Page 81: Game Show!

Cs 141 Exam 1 Review 81

Rear Admiral Grace Hopper

Page 82: Game Show!

Cs 141 Exam 1 Review 82

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

Page 83: Game Show!

Cs 141 Exam 1 Review 83

Who is this?

Page 84: Game Show!

Cs 141 Exam 1 Review 84

Linus Torvalds author and developer of Linux

Page 85: Game Show!

Cs 141 Exam 1 Review 85

Who is this?

Page 86: Game Show!

Cs 141 Exam 1 Review 86

Steve Jobs, co-founder and CEO of Apple Corporation

Page 87: Game Show!

Cs 141 Exam 1 Review 87

Who is this?

Page 88: Game Show!

Cs 141 Exam 1 Review 88

Steve Wozniak, co-founder of Apple Corporation

Page 89: Game Show!

Cs 141 Exam 1 Review 89

What does IBM stand for?

Page 90: Game Show!

Cs 141 Exam 1 Review 90

International Business Machines

Page 91: Game Show!

Cs 141 Exam 1 Review 91

Who is considered the founder of IBM?

Page 92: Game Show!

Cs 141 Exam 1 Review 92

Thomas J. Watson

Page 93: Game Show!

Cs 141 Exam 1 Review 93

Whats wrong with this function

bool foo (int, double){return true;

}

Page 94: Game Show!

Cs 141 Exam 1 Review 94

Whats wrong with this function

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

}

Page 95: Game Show!

Cs 141 Exam 1 Review 95

Whats wrong with this function

int double bar(int num){return num;

}

Page 96: Game Show!

Cs 141 Exam 1 Review 96

Whats wrong with this function

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

}

Page 97: Game Show!

Cs 141 Exam 1 Review 97

void baz (int num1, int &num);

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

Page 98: Game Show!

Cs 141 Exam 1 Review 98

What does call by value mean?

Page 99: Game Show!

Cs 141 Exam 1 Review 99

What does call by reference mean?

Page 100: Game Show!

Cs 141 Exam 1 Review 100

void bar(int numArray[]){

}

Is numArray call by value or call by reference?

Page 101: Game Show!

Cs 141 Exam 1 Review 101

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

Page 102: Game Show!

Cs 141 Exam 1 Review 102

What does procedural abstraction or information hiding or black box design mean?

Page 103: Game Show!

Cs 141 Exam 1 Review 103

What is the purpose of assertions?

Page 104: Game Show!

Cs 141 Exam 1 Review 104

How can you turn off assertions before you release code to users?

Page 105: Game Show!

Cs 141 Exam 1 Review 105

Why would you turn off assertions before you release code to users?

Page 106: Game Show!

Cs 141 Exam 1 Review 106

Give me an example of function overloading?

Page 107: Game Show!

Cs 141 Exam 1 Review 107

What is meant by a global variable?

Page 108: Game Show!

Cs 141 Exam 1 Review 108

Where are global variables declared?

Page 109: Game Show!

Cs 141 Exam 1 Review 109

What is the type of variable used for output files?

Page 110: Game Show!

Cs 141 Exam 1 Review 110

What is the type of variable used for input files?

Page 111: Game Show!

Cs 141 Exam 1 Review 111

How do you test if a file open succeeds?

Page 112: Game Show!

Cs 141 Exam 1 Review 112

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

Page 113: Game Show!

Cs 141 Exam 1 Review 113

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

Page 114: Game Show!

Cs 141 Exam 1 Review 114

What do you add to the file open call if you want to append to a file?

Page 115: Game Show!

Cs 141 Exam 1 Review 115

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

What would argc be?

Page 116: Game Show!

Cs 141 Exam 1 Review 116

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

What would argv[1] be?

Page 117: Game Show!

Cs 141 Exam 1 Review 117