1.13k likes | 1.31k Views
Game Show!. What type/types hold the following: 'a' '<br>' '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?.
E N D
Game Show! Cs 141 Exam 1 Review
Cs 141 Exam 1 Review • What type/types hold the following: • 'a' • '\n' • '4'
Cs 141 Exam 1 Review • What type/types hold the following: • 0,1,-1,2,-2,...
Cs 141 Exam 1 Review • 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 • What type/types hold the following: 0,1,2,3,4,...
Cs 141 Exam 1 Review • What type/types could be legitimately substituted for TYPE TYPE foo = 4;
Cs 141 Exam 1 Review • What is the main difference between a float and a double?
Cs 141 Exam 1 Review • int bar = 23/4; • What is bar?
Cs 141 Exam 1 Review • int foo = 23%4; • What is foo?
Cs 141 Exam 1 Review • float bop = 23/4; • What is bop?
Cs 141 Exam 1 Review • int baz; • What is the value of baz?
Cs 141 Exam 1 Review • What are three ways to initialize the value of a variable?
Cs 141 Exam 1 Review • What would happen if you did this: • const int foo = 5; • foo = 10;
Cs 141 Exam 1 Review • Is this a valid comment? • /* Written by Jeanna
Cs 141 Exam 1 Review • Is this a valid comment? • \\ Written by Jeanna
Cs 141 Exam 1 Review • What are two ways to write a valid comment?
Cs 141 Exam 1 Review • Declare a variable to hold someone's last name.
Cs 141 Exam 1 Review • Declare a variable to hold someone's age in years.
Cs 141 Exam 1 Review • Declare a variable to hold someone's hourly wage.
Cs 141 Exam 1 Review • Declare a variable to hold someone's middle initial.
Cs 141 Exam 1 Review • 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 What does != mean?
Cs 141 Exam 1 Review • What is the difference between = and ==?
Cs 141 Exam 1 Review • What does && mean?
Cs 141 Exam 1 Review • What does || mean?
Cs 141 Exam 1 Review • What is the difference between: cin >> foo; cout << foo;
Cs 141 Exam 1 Review • Which of these lines is not like the others? foo++; ++foo; foo+=1; foo = foo +1; foo+1;
Cs 141 Exam 1 Review • What is wrong with this? if ((answer == ‘y’) | (answer == ‘Y’)){ cout << “User entered yes\n”; }
Cs 141 Exam 1 Review • What is wrong with this? if ((answer == ‘y’) && (answer == ‘Y’)){ cout << “User entered yes\n”; }
Cs 141 Exam 1 Review • 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 • 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 • What is the value of BAZ below? enum SillyNames {FOO=1, BAR, BAZ};
Cs 141 Exam 1 Review • Declare an enum of the days of the week.
Cs 141 Exam 1 Review • What is the advantage of declaring an enum?
Cs 141 Exam 1 Review • Are these two boolean expressions the same? (x >=10) ((x ==10) && (x > 10))
Cs 141 Exam 1 Review • 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 • 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 • 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 • 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 • 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 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 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 • If you want to read from or write to a file what must you add to our basic template?
Cs 141 Exam 1 Review #include <fstream>
Cs 141 Exam 1 Review • Declare a variable to hold a file you want to read from
Cs 141 Exam 1 Review ifstream input_file;
Cs 141 Exam 1 Review • Declare a variable to hold a file you want to write to.
Cs 141 Exam 1 Review ofstream output_file;
Cs 141 Exam 1 Review How would you open the file “foo.txt”?
Cs 141 Exam 1 Review fileVariable.open(“foo.txt”);