{"id":217637,"date":"2018-09-15T22:59:26","date_gmt":"2018-09-15T22:59:26","guid":{"rendered":"http:\/\/localhost\/wordpress\/index.php\/2018\/09\/15\/gsp-125-final-exam-guide\/"},"modified":"2018-10-24T09:02:10","modified_gmt":"2018-10-24T09:02:10","slug":"gsp-125-final-exam-guide","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/gsp-125-final-exam-guide\/","title":{"rendered":"GSP 125 Final Exam Guide"},"content":{"rendered":"<p>Question 1. 1. In addition to grouping functions together, a class also groups (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0libraries.\t\u00a0 \u00a0 \u00a0 \u00a0math operations.\t\u00a0 \u00a0 \u00a0 \u00a0print statements.\t\u00a0 \u00a0 \u00a0 \u00a0variables.\t\u00a0\tQuestion 2. 2. Hiding data in a class is also called (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0encapsulation.\t\u00a0 \u00a0 \u00a0 \u00a0accessibility inversion.\t\u00a0 \u00a0 \u00a0 \u00a0confusion culling.\t\u00a0 \u00a0 \u00a0 \u00a0redirection.\t\u00a0\tQuestion 3. 3. The public members of a class (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0can be changed after compiling, even functions.\t\u00a0 \u00a0 \u00a0 \u00a0must be accessed from an object of that class.\t\u00a0 \u00a0 \u00a0 \u00a0need a special interface to accessed from an object.\t\u00a0 \u00a0 \u00a0 \u00a0can only be accessed within member functions of that class.\t\u00a0\tQuestion 4. 4. Constructors are called (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0whenever an object is created.\t\u00a0 \u00a0 \u00a0 \u00a0whenever a new line of code is typed.\t\u00a0 \u00a0 \u00a0 \u00a0only after math operations.\t\u00a0 \u00a0 \u00a0 \u00a0only after a work contract is defined.\t\u00a0\tQuestion 5. 5. Unions are (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0defined just like structs, though their memory behaves differently.\t\u00a0 \u00a0 \u00a0 \u00a0a place to store multiple data types simultaneously.\t\u00a0 \u00a0 \u00a0 \u00a0a concept from the C language that is uncommon in C++.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 6. 6. When objects contain other objects, it is called (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0composition.\t\u00a0 \u00a0 \u00a0 \u00a0data blending.\t\u00a0 \u00a0 \u00a0 \u00a0subobjecting.\t\u00a0 \u00a0 \u00a0 \u00a0enclosures.\t\u00a0\tQuestion 7. 7. Using the sizeof operator, the compiler will provide the size in bytes of a (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0class or data type.\t\u00a0 \u00a0 \u00a0 \u00a0statically allocated array.\t\u00a0 \u00a0 \u00a0 \u00a0variable instance or object.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 8. 8. When de-allocating arrays dynamically allocated with new, _____ should be used to ensure proper de-allocation. (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0destructor.\t\u00a0 \u00a0 \u00a0 \u00a0delete.\t\u00a0 \u00a0 \u00a0 \u00a0delete [].\t\u00a0 \u00a0 \u00a0 \u00a0free().\t\u00a0\tQuestion 9. 9. A pointer stores a(n) (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0address.\t\u00a0 \u00a0 \u00a0 \u00a0variable.\t\u00a0 \u00a0 \u00a0 \u00a0value.\t\u00a0 \u00a0 \u00a0 \u00a0None of the above\t\u00a0\tQuestion 10. 10. The most common operator used when accessing members of an object through a pointer is this. (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0&#038;\t\u00a0 \u00a0 \u00a0 \u00a0->\t\u00a0 \u00a0 \u00a0 \u00a0.\t\u00a0 \u00a0 \u00a0 \u00a0::\t\u00a0\tQuestion 11. 11. The following can be used to determine the number of elements in a statically allocated array in C or C++. (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0sizeof(arrayname)\/sizeof(arrayname[0])\t\u00a0 \u00a0 \u00a0 \u00a0elementsof<arrayname>\t\u00a0 \u00a0 \u00a0 \u00a0arrayname.length()\t\u00a0 \u00a0 \u00a0 \u00a0None of the above\t\u00a0\tQuestion 12. 12. When returning by reference, (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0the method can be used as an l-value.\t\u00a0 \u00a0 \u00a0 \u00a0other functions cannot use the result as a parameter.\t\u00a0 \u00a0 \u00a0 \u00a0C-style code must be capitalized, as per standard convention.\t\u00a0 \u00a0 \u00a0 \u00a0There is no such thing as returning by reference.\t\u00a0\tQuestion 13. 13. Overloaded methods in a class must use (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0the exact same argument types, but different return types.\t\u00a0 \u00a0 \u00a0 \u00a0the exact same name.\t\u00a0 \u00a0 \u00a0 \u00a0default arguments.\t\u00a0 \u00a0 \u00a0 \u00a0None of the above\t\u00a0\tQuestion 14. 14. The copy constructor takes (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0no arguments.\t\u00a0 \u00a0 \u00a0 \u00a0a single argument by reference.\t\u00a0 \u00a0 \u00a0 \u00a0a single argument by value.\t\u00a0 \u00a0 \u00a0 \u00a0any number of arguments.\t\u00a0\tQuestion 15. 15. A shallow copy is dangerous because (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0it has a knife and is very clumsy.\t\u00a0 \u00a0 \u00a0 \u00a0it may cause bad de-allocation in a properly written destructor in a class that allocates memory.\t\u00a0 \u00a0 \u00a0 \u00a0it prevents recursive methods from being called by using significant amounts of stack space.\t\u00a0 \u00a0 \u00a0 \u00a0None of the above\t\u00a0\tQuestion 16. 16. When using inheritance, the class that is doing the inheriting is called a (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0subclass.\t\u00a0 \u00a0 \u00a0 \u00a0child class.\t\u00a0 \u00a0 \u00a0 \u00a0derived class.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 17. 17. A UML class diagram is commonly used to (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0exactly describe code before writing it.\t\u00a0 \u00a0 \u00a0 \u00a0help programmers explain design to other programmers.\t\u00a0 \u00a0 \u00a0 \u00a0define code standards (for syntax) for programming teams.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 18. 18. Downcasting is considered safe because (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0the compiler is very smart about types.\t\u00a0 \u00a0 \u00a0 \u00a0it is safe to assume a parent can do everything a child can do.\t\u00a0 \u00a0 \u00a0 \u00a0downcasting can only be done on upcasted objects.\t\u00a0 \u00a0 \u00a0 \u00a0downcasting is not considered safe.\t\u00a0\tQuestion 19. 19. If unsure whether to use inheritance or composition, use (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0inheritance, because it saves the most typing.\t\u00a0 \u00a0 \u00a0 \u00a0inheritance, because C++ supports multiple inheritance.\t\u00a0 \u00a0 \u00a0 \u00a0composition, because it gives programmers the most options.\t\u00a0 \u00a0 \u00a0 \u00a0composition, because it is more efficient than inheritance.\t\u00a0\tQuestion 20. 20. Creating classes in separate .h and .cpp files is good because (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0moving code to separate files is good design (separation of concerns).\t\u00a0 \u00a0 \u00a0 \u00a0separating declaration from definition allows decoupling of dependencies.\t\u00a0 \u00a0 \u00a0 \u00a0many smaller files are easier to maintain by teams of programmers.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 21. 21. When using the virtual keyword, C++ can detect the type of an object by using (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0Compile Time Type Information.\t\u00a0 \u00a0 \u00a0 \u00a0dynamic_cast.\t\u00a0 \u00a0 \u00a0 \u00a0a &#8220;constructor inference&#8221; pattern.\t\u00a0 \u00a0 \u00a0 \u00a0C++ does not support any kind of reflection.\t\u00a0\tQuestion 22. 22. Passing pointers by reference (e.g., &#8220;(int * &#038; arg)&#8221;) is possible but limited, because (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0NULL cannot be passed as a valid pointer by reference.\t\u00a0 \u00a0 \u00a0 \u00a0a raw address (&#038;variable) cannot be passed as a valid pointer by reference.\t\u00a0 \u00a0 \u00a0 \u00a0r-values cannot be passed as pointers by reference.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 23. 23. Stack memory is where (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0global variables and raw machine code are stored.\t\u00a0 \u00a0 \u00a0 \u00a0local variables and execution of instructions are kept track of.\t\u00a0 \u00a0 \u00a0 \u00a0dynamic memory is allocated to.\t\u00a0 \u00a0 \u00a0 \u00a0None of the above\t\u00a0\tQuestion 24. 24. A compiler will put sentinel values into memory to (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0help detect array out-of-bound errors.\t\u00a0 \u00a0 \u00a0 \u00a0keep track of how many times a function recurses.\t\u00a0 \u00a0 \u00a0 \u00a0stop bad functions from being executed.\t\u00a0 \u00a0 \u00a0 \u00a0prevent memory leaks.\t\u00a0\tQuestion 25. 25. Virtual functions have a cost when compared to normal (statically bound) functions; specifically, they are (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0slower and less optimizable.\t\u00a0 \u00a0 \u00a0 \u00a0less dynamic.\t\u00a0 \u00a0 \u00a0 \u00a0unusable with polymorphism.\t\u00a0 \u00a0 \u00a0 \u00a0more difficult to read than extern or static functions.\t\u00a0\tQuestion 26. 26. In C++, the diamond problem that results from multiple inheritance can be solved by (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0extern inheritance.\t\u00a0 \u00a0 \u00a0 \u00a0static inheritance.\t\u00a0 \u00a0 \u00a0 \u00a0virtual inheritance.\t\u00a0 \u00a0 \u00a0 \u00a0inline inheritance.\t\u00a0\tQuestion 27. 27. Test-driven development is (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0writing software after finishing multiple choice exams about software quality.\t\u00a0 \u00a0 \u00a0 \u00a0writing many small tests that initially fail, and working on each test until all succeed.\t\u00a0 \u00a0 \u00a0 \u00a0another name for object-oriented programming.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 28. 28. Which piece of the C\/C++ compile tool chain arranges compiled code into the final executable? (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0Preprocessor\t\u00a0 \u00a0 \u00a0 \u00a0Compiler\t\u00a0 \u00a0 \u00a0 \u00a0Linker\t\u00a0 \u00a0 \u00a0 \u00a0Debugger\t\u00a0\tQuestion 29. 29. For C-style error codes to be used effectively, a programmer should (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0always do logic on function returns to test success.\t\u00a0 \u00a0 \u00a0 \u00a0check errno after potentially failed operations to see if any errors occurred.\t\u00a0 \u00a0 \u00a0 \u00a0read documentation to make sense of error codes.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 30. 30. A class template allows (Points : 3)\t\u00a0 \u00a0 \u00a0 \u00a0a class to be re-defined with different types but the same code.\t\u00a0 \u00a0 \u00a0 \u00a0the compiler to ignore unused methods of the templated class.\t\u00a0 \u00a0 \u00a0 \u00a0the templated type to be any type, including another templated type.\t\u00a0 \u00a0 \u00a0 \u00a0All of the above\t\u00a0\tQuestion 31. 31. Write a &#8220;Hello World&#8221;\ufffd program in C++. (Points : 2) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 32. 32. Write code for a struct called &#8220;Coin.&#8221;\ufffd The Coin class should have a floating-point member for radius and thickness and weight, a c-string member for name, and an integer member for color. (Points : 7) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 33. 33. Write code for a class called &#8220;Double.&#8221; The Double class should have a single double member, value. Create accessors and mutators for value. The default constructor of Double should set value to zero. (Points : 7) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 34. 34. Write a class named Person and create another class called Teacher, which inherits from Person (Person is the parent class and Teacher is the child class). (Points : 7) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 35. 35. Write code that instantiates an integer and prints out its address. (Points : 7) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 36. 36. Write the body of thfollowing function so that it returns the square of the number pointed at by the pointer argument.\tfloat square(float * valuePtr)\t{\t\u00a0\t\u00a0\t} (Points : 7) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 37. 37. Consider the following class.\tclass ManagedArray {\tpublic:\tfloat * data;\tint size;\tManagedArray():data(0),size(0){}\tvoid setSize(int a_size){ size = a_size; data = new float[size]; }\t};\tWrite a destructor for this class to de-allocate any memory it may have allocated. (Points : 7) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 38. 38. Write code that dynamically allocates a two-dimensional array of integers called map, 5 high, and 7 wide. Then, de-allocate the two-dimensional array. (Points : 7) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 39. 39. Write code that allocates an integer on the stack and allocates another integer array on the heap. (Points : 7) \u00a0 \u00a0 \u00a0\u00a0\t\u00a0\t\u00a0 \u00a0 \u00a0\u00a0\t\u00a0\tQuestion 40.\t40. Write an abstract base class called LivingThing that has the following methods: breathe and eat. (Points : 7)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Question 1. 1. In addition to grouping functions together, a class also groups (Points : 3) \u00a0 \u00a0 \u00a0 \u00a0libraries. \u00a0 \u00a0 \u00a0 \u00a0math operations. \u00a0 \u00a0 \u00a0 \u00a0print statements. \u00a0 \u00a0 \u00a0 \u00a0variables. \u00a0 Question 2. 2. Hiding data <a href=\"https:\/\/www.benedictsol.com\/blogs\/gsp-125-final-exam-guide\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217637","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=217637"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217637\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=217637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=217637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=217637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}