Cs 141 Exam 1 Review 1
Game Show!
Cs 141 Exam 1 Review 2
What type/types hold the following: 'a' '\n' '4'
Cs 141 Exam 1 Review 3
What type/types hold the following: 0,1,-1,2,-2,...
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?
Cs 141 Exam 1 Review 5
What type/types hold the following:0,1,2,3,4,...
Cs 141 Exam 1 Review 6
What type/types could be legitimately substituted for TYPETYPE foo = 4;
Cs 141 Exam 1 Review 7
What is the main difference between a float and a double?
Cs 141 Exam 1 Review 8
int bar = 23/4;
What is bar?
Cs 141 Exam 1 Review 9
int foo = 23%4;
What is foo?
Cs 141 Exam 1 Review 10
float bop = 23/4;
What is bop?
Cs 141 Exam 1 Review 11
int baz;
What is the value of baz?
Cs 141 Exam 1 Review 12
What are three ways to initialize the value of a variable?
Cs 141 Exam 1 Review 13
What would happen if you did this:
const int foo = 5;
foo = 10;
Cs 141 Exam 1 Review 14
Is this a valid comment?
/* Written by Jeanna
Cs 141 Exam 1 Review 15
Is this a valid comment?
\\ Written by Jeanna
Cs 141 Exam 1 Review 16
What are two ways to write a valid comment?
Cs 141 Exam 1 Review 17
Declare a variable to hold someone's last name.
Cs 141 Exam 1 Review 18
Declare a variable to hold someone's age in years.
Cs 141 Exam 1 Review 19
Declare a variable to hold someone's hourly wage.
Cs 141 Exam 1 Review 20
Declare a variable to hold someone's middle initial.
Cs 141 Exam 1 Review 21
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?
Cs 141 Exam 1 Review 22
What does != mean?
Cs 141 Exam 1 Review 23
What is the difference between = and ==?
Cs 141 Exam 1 Review 24
What does && mean?
Cs 141 Exam 1 Review 25
What does || mean?
Cs 141 Exam 1 Review 26
What is the difference between:cin >> foo;cout << foo;
Cs 141 Exam 1 Review 27
Which of these lines is not like the others?
foo++;++foo;foo+=1;foo = foo +1;foo+1;
Cs 141 Exam 1 Review 28
What is wrong with this?
if ((answer == ‘y’) | (answer == ‘Y’)){cout << “User entered yes\n”;
}
Cs 141 Exam 1 Review 29
What is wrong with this?
if ((answer == ‘y’) && (answer == ‘Y’)){cout << “User entered yes\n”;
}
Cs 141 Exam 1 Review 30
What will happen if you do this?
num =3;if (num =2){
cout << “Number is 2\n”;} else {
cout << “Number is not 2\n”;}
Cs 141 Exam 1 Review 31
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”;}
Cs 141 Exam 1 Review 32
What is the value of BAZ below?
enum SillyNames {FOO=1, BAR, BAZ};
Cs 141 Exam 1 Review 33
Declare an enum of the days of the week.
Cs 141 Exam 1 Review 34
What is the advantage of declaring an enum?
Cs 141 Exam 1 Review 35
Are these two boolean expressions the same?
(x >=10)
((x ==10) && (x > 10))
Cs 141 Exam 1 Review 36
There are 3 different types of clauses in an if statement: if, else if and else
How many of each can you have?
Cs 141 Exam 1 Review 37
Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions
total =0;i=0;while (i< 10){
total = total +i;i++;
}cout << total;
Cs 141 Exam 1 Review 38
Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions
for(i=0; i< 10; i++){total = total +i;
}cout << total;
Cs 141 Exam 1 Review 39
Identify the following in this loop: InitializationActions, LoopCondition, UpdateActions, BodyStatements, CompletionActions
howMany=0;while(input_stream >> num){
howMany++;total = total + num;
}average = total/howMany;
Cs 141 Exam 1 Review 40
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;
Cs 141 Exam 1 Review 41
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
Cs 141 Exam 1 Review 42
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.
Cs 141 Exam 1 Review 43
If you want to read from or write to a file what must you add to our basic template?
Cs 141 Exam 1 Review 44
#include <fstream>
Cs 141 Exam 1 Review 45
Declare a variable to hold a file you want to read from
Cs 141 Exam 1 Review 46
ifstream input_file;
Cs 141 Exam 1 Review 47
Declare a variable to hold a file you want to write to.
Cs 141 Exam 1 Review 48
ofstream output_file;
Cs 141 Exam 1 Review 49
How would you open the file “foo.txt”?
Cs 141 Exam 1 Review 50
fileVariable.open(“foo.txt”);
Cs 141 Exam 1 Review 51
If you try to open a file, what type of error should you check for and how do you do that?
Cs 141 Exam 1 Review 52
Check if weren't able to open the file
fileVariable.open(“foo.txt”);
if (fileVariable.fail()){cout << “Couldn't open the file\n”;
}
Cs 141 Exam 1 Review 53
How would you open the file foo.txt?
Cs 141 Exam 1 Review 54
What does it mean to have a if statement nested inside a loop?
Cs 141 Exam 1 Review 55
What does it mean to have nested for loops?
What are nested for loops especially good for?
Cs 141 Exam 1 Review 56
True or false: There are some problems for which you must use a do-while loop. A while loop just won't work.
Cs 141 Exam 1 Review 57
When is it generally better to use a do-while loop instead of a while loop?
Cs 141 Exam 1 Review 58
When is it generally better to use a for loop instead of a while loop or do-while loop?
Cs 141 Exam 1 Review 59
When you get a bunch of compiler errors which one should you fix first and why?
Cs 141 Exam 1 Review 60
If you are trying to fix a specific compiler error, how can you figure out where the problem is?
Cs 141 Exam 1 Review 61
What is a fence post error?
Cs 141 Exam 1 Review 62
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;}
Cs 141 Exam 1 Review 63
Will these do the same thing?
for (i=0; i< 3;i++ )cout << i;
for (i=0;i< 3 ){cout << i;
i++;}
Cs 141 Exam 1 Review 64
Will these do the same thing?
for (i=0; i< 3;i++ )cout << i;
i=0;while (i< 3 )
cout << i++;
Cs 141 Exam 1 Review 65
What would you expect to happen if you did this
int numArray[5];numArray[5] = 100;cout << numArray[5];
Cs 141 Exam 1 Review 66
Whats wrong with this
int numArray[9];for (int i=0; i<=9; i++){
numArray[i] = i;}
Cs 141 Exam 1 Review 67
Do these all do the same thing?
cout << num << “\n”;
cout << num << endl;
cout << num;cout << “\n”;
Cs 141 Exam 1 Review 68
What child of a famous British poet is often considered the first programmer?
Cs 141 Exam 1 Review 69
Ada Byron Lovelace (1815-1852)
Cs 141 Exam 1 Review 70
Who is the creator of C++?
Cs 141 Exam 1 Review 71
Bjarne Stroustrup
Cs 141 Exam 1 Review 72
Who is the creator of the C programming language and a co-author of the UNIX operating system?
Cs 141 Exam 1 Review 73
Dennis Ritchie
Cs 141 Exam 1 Review 74
Explain the joke in the name C++
Cs 141 Exam 1 Review 75
Who coined the term “debugging” and wrote the first compiler for a computer programming language?
Cs 141 Exam 1 Review 76
Rear Admiral Grace Hopper
Cs 141 Exam 1 Review 77
Picture of the moth that was the first computer “bug”
Cs 141 Exam 1 Review 78
Who is this?
Cs 141 Exam 1 Review 79
Linus Torvalds author and developer of Linux
Cs 141 Exam 1 Review 80
Who is this?
Cs 141 Exam 1 Review 81
Steve Jobs, co-founder and CEO of Apple Corporation
Cs 141 Exam 1 Review 82
Who is this?
Cs 141 Exam 1 Review 83
Steve Wozniak, co-founder of Apple Corporation
Cs 141 Exam 1 Review 84
What does IBM stand for?
Cs 141 Exam 1 Review 85
International Business Machines
Cs 141 Exam 1 Review 86
Who is considered the founder of IBM?
Cs 141 Exam 1 Review 87
Thomas J. Watson
Cs 141 Exam 1 Review 88
Whats wrong with this function
bool foo (int, double){return true;
}
Cs 141 Exam 1 Review 89
Whats wrong with this function
void doubleIt(int num){num = 2* num;
}
Cs 141 Exam 1 Review 90
Whats wrong with this function
int double bar(int num){return num;
}
Cs 141 Exam 1 Review 91
Whats wrong with this function
void doubleIt(int num){return 2* num;
}
Cs 141 Exam 1 Review 92
void baz (int num1, int &num);
Which is the call by value parameter and which is the call by reference parameter?
Cs 141 Exam 1 Review 93
What does call by value mean?
Cs 141 Exam 1 Review 94
What does call by reference mean?
Cs 141 Exam 1 Review 95
void bar(int numArray[]){
}
Is numArray call by value or call by reference?
Cs 141 Exam 1 Review 96
What do you have to do to make an array parameter call by value?
Cs 141 Exam 1 Review 97
What does procedural abstraction or information hiding or black box design mean?
Cs 141 Exam 1 Review 98
What is the purpose of assertions?
Cs 141 Exam 1 Review 99
How can you turn off assertions before you release code to users?
Cs 141 Exam 1 Review 100
Why would you turn off assertions before you release code to users?
Cs 141 Exam 1 Review 101
Give me an example of function overloading?
Cs 141 Exam 1 Review 102
What is meant by a global variable?
Cs 141 Exam 1 Review 103
Where are global variables declared?
Cs 141 Exam 1 Review 104
What is the type of variable used for output files?
Cs 141 Exam 1 Review 105
What is the type of variable used for input files?
Cs 141 Exam 1 Review 106
How do you test if a file open succeeds?
Cs 141 Exam 1 Review 107
How do you test if a file read or write succeeds?
Cs 141 Exam 1 Review 108
How do you test if you read all the contents of a file?
Cs 141 Exam 1 Review 109
What do you add to the file open call if you want to append to a file?
Cs 141 Exam 1 Review 110
If I did this ./a.out inputFile.txt
What would argc be?
Cs 141 Exam 1 Review 111
If I did this ./a.out inputFile.txt
What would argv[1] be?
Cs 141 Exam 1 Review 112