List of Topics for Exam 1 If statements o How is an if statement constructed? o Does every if need an else? Looping o While loop! What does a while loop look like?! How do you ensure you will not have an infinite loop?! In which cases would you want to use a while loop over a for loop? o For loop! What does a for loop look like?! In what cases would you use a for loop over a while loop?! What is this? for( ; ; ){ Types o Type Safety o Valid operations on types o What types can be assigned to what types?! Can you set an int equal to a double? o Initial values! string s; // Value of s?! int x; // Value of x? Functions o Basic composition of a function o How to call a function o Return values! What are they?! How do you capture the result? Errors o What are the types of errors possible in your program? o What are ways to check for errors? o What is the difference between pre- conditions and post- conditions? o What is debugging? o What are methods to make debugging easier?! Comments Naming o What are valid names? o What are not valid names? o Are there words you cannot use for naming? Grammars o What is the purpose of a grammar? o How does the calculator grammar ensure order of operations? Input/Output Streams o What does cout do?
o How do you use cout? o What does cin do? o What does getline() do? o How do you use getline()? o What are the four states of input streams?! What are the differences between them?
Exam 1 mock- up questions 1. What is the return type of this C++ function? double add( double n1, double n2){ return n1+n2; a) Nothing b) This isn t a function c) A double d) Some sort of number, but who knows what kind? e) An int 2. What is the name of this C++ function? double add( double n1, double n2){ return n1+n2; a) add b) double c) return d) function e) Oh gosh. I m taking a test?! 3. What is the output in the cout statement? double add( double n1, double n2){ return n1+n2; int main(){ double x = 0.0; add(5.0, 2.0); cout << x << endl; a) 7.0 b) 5..0 c) 0.0 d) 2.0 e) x
4. What is the output in the cout statement? double add( double n1, double n2){ return n1+n2; int main(){ double x = 0.0; x = add(5.0, 2.0); cout << x << endl; a) 5.0 b) 7.0 c) 2.0 d) 0.0 e) x 5. Which of these is a valid variable name? a) int 1; b) string name; c) double 2CoolForSchool; d) string if; e) string first name; 6. std_lib_facilities_4.h a) is a header file b) contains code for sqare root (sqrt function) c) should be included with a #include d) a && b e) a && c 7. Why is there a return 0 statement in main? a) main returns nothing b) main returns an int c) it symbolizes failure d) it symbolizes success e) b && d f) b && c 8. What does && mean? a) No idea b) OR c) AND d) XOR
9. What does mean? a) The opposite of && b) OR c) AND d) XOR e) Never seen it before in my life 10. In an if statement, what goes inside the parentheses? a) if statements don t have parentheses b) A condition that will evaluate to true or false c) A Boolean value d) Wait a bool is something that is true or false, so it must be b AND c 11. In a while loop, what goes inside the parentheses? a) While loops don t have parentheses b) A condition that will evaluate to true or false c) A Boolean value d) Wait a bool is something that is true or false, so it must be b AND c 12. In C++, what goes inside curly brackets, {? a) code to execute b) C++ doesn t use curly brackets c) Conditions that define whether code will execute or not d) None of the above 13. What is the output of the following code? int i = 0; while ( i < 10 ) cout << i << ; a) This loop will never terminate b) 0 1 2 3 4 5 6 7 8 9 c) 0123456789 d) 0 1 2 3 4 5 6 7 8 9 10 e) 012345678910
14. What is the output of the following code? int i = 0; for(i = 0; i < 10; i = i + 2) cout << i << ; cout << i*2 << ; a) 0 1 2 3 4 5 6 7 8 9 b) 0 2 4 6 8 10 c) 0 0 2 4 4 8 6 12 8 16 d) 0 2 4 6 8 e) 0 2 4 6 8 16 f) 0 2 4 6 8 20 g) Nick, why are you being so mean?! 15. In c++, what does cout do? a) Reads something from the keyboard into a variable b) Prints something to the screen c) Invokes the compiler d) Causes a warning e) Crashes the computer 16. In c++, what does cin do? a) Reads something from the keyboard into a variable b) Prints something to the screen c) Invokes the compiler d) Causes a warning e) Crashes the computer 17. Pair things up correctly a) cin, << b) cout, >> c) cout, << d) cin, output e) cin, <> 18. What is \t? a) It means divide by t b) A multi- character string meaning tab c) A single- character meaning tab d) The italicize command e) None of the above
19. What does the compiler output? a) A source code file b) An object code file c) An executable file d) A header file e) What is a compiler?! 20. What does cin >> x do? a) Read a string and put it into x b) Read a double and put it into x c) Read only whitespace and put it into x d) Ignore leading whitespace before x e) Read as much data that is consistent with the type of x f) D and E sound good g) A and D sound good h) B and D sound good i) Why are there so many options?! 21. The first element of a vector v is indicated by? a) v[0] b) v[1] c) v@0 d) v@1 e) v(0) 22. What does a vector do? a) It stores values sequentially b) It stores duplicate values c) It sores different value types d) It is used to count up in a while loop e) It has something to do with math 23. What does the statement vector<int> v(10) mean? a) A vector, named v, contains 10 integers b) A vector, named int, contains 10 v s c) A vector, named v, contains the int 10 d) A vector, named v, can only store values up to 10 e) What is this?!
24. A a C++ token, as seen in class a) Is something invented by Dr. Daugherity to mess with my head b) Is a user defined type c) Is something to use in an arcade d) Is composed of three fields,: a kind, a value, and a name e) Is both B and D 25. A grammar contains a) Rules to generate valid expressions b) Rules to specify the order of operations c) Green underlining in a word processor d) A and B e) None of the above