Unformatted text preview:

CS101 Exam II PLEDGED SPRING 2000CS 101 PLEDGED PAGE 1 OF 6This exam is pledged, and is closed book and closed notes. All answers are to be given on the providedanswer sheet. For objective questions, if you find more than one answer is acceptable, choose the mostencompassing answer. YOU MUST HAND IN ALL COPIES OF THE EXAM AND ITS ANSWER SHEET.This exam has 6 pages containing 45 questions.Fill in the blank1. A ___________ is a collection of function interfaces, constant and variable object definitions, andclass descriptions. It does not include implementation.2. A function’s computation is normally brought back as the ___________ value.3. The parameters in the invocation are called the ___________ parameters.4. Every function invocation creates an _________, which stores values of parameters and local objects. 5. The ___________ is responsible for handling file inclusion directives.6. When creating a new class type, two important initial steps are determining the ___________ and thebehaviors of the objects.7. Member functions that return the value of an attribute of an object are called ___________.8. Member functions that set or change the value of an attribute of an object are called ___________.9. A ___________ member function is one that cannot change its objects’ attributes.10. A ___________ is a list of statements within curly braces.11. A ___________ object is an object defined within a statement block.12. A ___________ object is an object defined outside of any function interface or function body.13. When a ___________ parameter is used any modifications made to that parameter by the invokedfunction change the original object.14. If an object is large, making a copy of it can be expensive in terms of time and space. Thus objectsthat are large or objects whose size is not known are often passed by ___________.15. A ___________ modifier applied to a parameter declaration indicates that the function may notmodify the object. If the function attempts to modify the object, the compiler reports an error.16. Function ___________ is when two or more functions have the same name.True/false questions17. Indices, also called referencing, are used to select an element of an array.18. Default parameters must always occur after non-default parameters.19. A programmer must put a return statement in a void function.20. Auxiliary functions must use the object-dot notation to reference data members, but member func-tions need not.21. Elements in an array always have the same type.22. a[3] accesses the third element of the array a.CS101 Exam II PLEDGED SPRING 2000CS 101 PLEDGED PAGE 2 OF 6The following declarations are in effect for Questions 23 - 27. 23. The following statement is legal for function main().24. The following statement is legal for function main().25. The following statement is legal for function main().26. The following statement is legal for Widget member function get().27. The following statement is legal in a Widget member function.The following code fragment is in effect for Questions 28 - 31.28. The parameter list correctly defines that there are two bool value parameters.29. The definition of cups defines an array of nine char elements.30. The assignment to cups[i] within the if statement is correct.31. The for loop iterates ten times.class Widget {public:Widget ();int get() const;private:int dataValue;void set(int v);};Widget t;t.dataValue = 3;int k = t.get();t.set(3);dataValue = 3;int k = t.get();int Coffee(bool cream, sugar) {char cups[9];for (int i=0;i<=9;i){if (cream && sugar) {cups[i] = "5";}}}CS101 Exam II PLEDGED SPRING 2000CS 101 PLEDGED PAGE 3 OF 632. What is the output of the following program? 33. Consider the following function scramble():What is the output of the following program fragment?#include <iostream>using namespace std;int counter = 0;void f() {++counter;}void g() {f();f();}void h() {f();g();}int main() {g();cout << ++counter << endl;h();cout << ++counter << endl;return 0;}void scramble(int i, int &j, int &k) {i = 10;j = 20;k = 30;return;}#include <iostream>using namespace std;int main() {int i=1;int j=2;int k=3;scramble(k, j, i);cout << i <<""<<j<<""<<k<<endl;return 0;}CS101 Exam II PLEDGED SPRING 2000CS 101 PLEDGED PAGE 4 OF 634. What is the output of the following program? 35. What does the following correct program print out?36. What is the output of the following program fragment?#include <iostream>using namespace std;void f(int i, int j) {int temp;temp = i;i=j;j = temp;cout << i <<""<<j<<endl;return;}int main() {int a=10;int b=20;f(a, b);f(b, a);return 0;}#include <iostream>using namespace std;const int LoopBound = 5;int i;int f(int a) {for (i = 0; i <= LoopBound; ++i) {if(i<=a){cout << i << " ";}}cout << endl;}int main() {for(i=0;i<2;++i) {f(i);}return 0;}int a[5];a[0] = 0;for (int i = 1; i <= 4; ++i) {a[i] = a[i-1] + i;}cout << a[3] << endl;CS101 Exam II PLEDGED SPRING 2000CS 101 PLEDGED PAGE 5 OF 6The following definitions are in effect for questions 37– 40. Member functions have the purposes thattheir names suggest. 37. The const in the prototypes of functions GetNumerator() and GetDenominator() in classRational indicates that(a) The functions will return a constant value.(b) The functions will not modify their parameters.(c) The functions will not change the object.(d) None of the above.38. Fill in the blank using only objects a, b, c, and d to complete the following member functionEqual() so that it returns true if and only if the invoking Rational is mathematicallyequivalent to its parameter (e.g., the rational 1/2 is equal to the rational 2/4). 39. Complete the definition of the auxiliary operator != that returns true if and only if the rationalnumbers represented by its two operands are not equivalent.40. Complete the definition of the member function Reciprocal() that returns the reciprocal of theinvoking Rational. For example if the invoking Rational was equivalent to a/b, then thefunction returns a Rational equal to b/a. Do not use division in completing your answer.class Rational {public: // member functions and operatorRational();Rational(const int numer, const int denom);bool Equal(const Rational &r) const;void IncrementByOne(const Rational &r);Rational Reciprocal() const;protected:int GetNumerator() const;int GetDenominator() const;void SetNumerator(const int numer);void SetDenominator(const int denom);private:int Numerator;int Denominator;};bool Rational::Equal(const Rational &r) {int a = GetNumerator();int b =


View Full Document

UVA CS 101 - Exam II PLEDGED

Documents in this Course
Classes

Classes

53 pages

Recursion

Recursion

15 pages

Iteration

Iteration

88 pages

PLEDGED

PLEDGED

6 pages

Objects

Objects

33 pages

PLEDGED

PLEDGED

11 pages

CS 101

CS 101

42 pages

Classes

Classes

83 pages

Iteration

Iteration

92 pages

Classes

Classes

186 pages

Classes

Classes

208 pages

Hardware

Hardware

21 pages

Arrays

Arrays

70 pages

Load more
Download Exam II PLEDGED
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exam II PLEDGED and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exam II PLEDGED 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?