----------------------------------------------------------------- Chapter 17 (543-564) Summary: 560 Review Questions p560-562 ---------------------------------------------------------------- 1) What is a recursive function? 2) What are the base cases of a recursive function? 3) What is the 'winding up' and 'winding down' of a recursive function? 4) How is the stack used in recursive functions? 5) How do you prove that a recursive function is correct? -show base cases are correct -show recursive case always works toward base cases -prove recursive case is correct 6) Is recursion faster than iteration? Explain. 7) What is the difference between recursion and iteration. 8) Write code for this recursive function . . . 9) What is the output of the following code . . . 10) What is stack overflow in recursive functions? 11) Can all recursive functions be rewritten iteratively? 12) What is necessary to re-write all recursive functions iteratively? ------------------------------------------------------------------- Chapter 9 (281-308) Summary: p303 Review Questions p304-305 We have not discussed constructors yet and thus, many of the review questions are not yet accessible for this exam. Focus on: Review questions: 1, 9, 10, 11, 12, 14, 15, 16 ------------------------------------------------------------------ Short Answer Questions ------------------------------------------------------------------ 1) What does the C++ keyword struct do? 2) What does the C++ keyword class do? 3) What is data encapsulation? 4) What is information hiding? 5) Why are classes safer than structs? 6) Demonstrate in code how to make a class. 7) Variables describe an is-a relationship while classes describe a have-a relationship. Example - consider the following two code segments: //segment 1 int a; // a is an integer. //segment 2 class Date { private: //accessors mutators and other functions go here public: int month; int day; int year; }; //Date has-a day month and year. 8) What is an accessor function? 9) What is a mutator function? 10) Why are accessor and mutator functions necessary when using classes and not necessary when using structs? Be sure to describe why to both. 11) Design a class for ... 12) Demonstrate the proper way to define a class. 13) Given a class called Help, demonstrate how to compile the class's implementation file and the main program file called main.cpp. 14) Given a class called Help, what two files should be associated with this class. Describe what these two files do/What is their purpose? 15) What does #include do? 16) What is a preprocessor command? Name two. 17) What is the difference between #ifndef and #define? 18) What is the scope resolution operator? 19) What does the scope resolution operator do? 20) Why is the scope resolution operator necessary? ------------------------------------------------------------------ True or False example questions (some of the statements below are true and some are false) ------------------------------------------------------------------ 1) All data in a struct is public. 2) All data in a struct is private. 3) All data in a class is public. 4) All data in a class is private. 5) Classes are safer than structs. 6) Structs are safer than classes. 7) #include is used to properly protect a header file from multiple inclusions. 8) #ifndef is used to properly protect a header file from multiple inclusions. 9) #include is used to incorporate class header files and function prototypes into a program or implementation file. 10) #endif is needed after a #define. 11) #endif is needed after a #ifndef. 12) #endif is needed after a #include. 13) Classes should be defined in separate files. 14) Classes should be defined in the main program file.