DOC PREVIEW
UVA CS 101 - Exams CS 101

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS101 PLEDGED SPRING 2001CS 101 PLEDGED PAGE 1 OF 10The following exam is pledged. All answers are to be given on the provided answer sheet. The test isclosed book, closed note, and closed calculator. If you believe more than one answer is acceptable,choose the best answer. YOU MUST HAND IN ALL COPIES OF THE TEST AND THE ANSWERSHEET. Leaving out or misentering identification information on the answer sheet will cause a 5point penalty.On Questions 1 – 14 the following definition and prototypes are in effect. Please observe that the defini-tions of the Widget member functions are very similar to the definitions given in Homework 7. Theimportance differences are that debugging output statements have been removed and a new memberfunction concatenate() has been added to the Widget class definition. In addition, the following definitions are in effect. class Widget {public:Widget(const string &id = "ID", const string &value = "Value");Widget(const Widget &w);string getID() const;string getValue() const;void setValue(const string &s);Widget& operator = (const Widget &source);void insert(ostream &sout) const;void extract(istream &sin);Widget concatenate(const Widget &suffix) const;protected:void setID(const string &s);private:string thisID;string thisValue;};istream& operator >> (istream &sin, Widget &object);ostream& operator << (ostream &sout, Widget &object);Widget operator + (const Widget &w1, const Widget &w2);Widget::Widget(const string &id, const string &value) {setID(id);setValue(value);}string Widget::getID() const { return thisID;}string Widget::getValue() const { return thisValue;}void Widget::setID(const string &s) { thisID = s;}void Widget::setValue(const string &s) {thisValue = s;CS101 PLEDGED SPRING 2001CS 101 PLEDGED PAGE 2 OF 10}void Widget::insert(ostream &sout) const { sout << "(" << getId() << " - " << getValue() << ")";}void Widget::extract(istream &sin) { string newValue;sin >> newValue;setValue(newValue);}Widget& Widget::operator = (const Widget &source) {string newValue = source.getValue();setValue(newValue);return *this;}istream& operator >> (istream &sin, Widget &object) {object.extract(sin);return sin;} ostream& operator << (ostream &sout, const Widget &object) {object.insert(sout);return sout;} Widget operator + (const Widget &w1, const Widget &w2) {return w1.concatenate(w2);}CS101 PLEDGED SPRING 2001CS 101 PLEDGED PAGE 3 OF 10PART I: Multiple choice questions regarding the Widget library. Each of the following questionsshould be answered in isolation, i.e., if part of some question causes for a change to a class, func-tion, or variable, that change is not in effect in any other question.1. How many Widget constructors can be used by Widget clients?(a) 0(b) 1(c) 2(d) 3(e) more than 32. How many Widget inspectors can the Widget class designer use?(a) 0(b) 1(c) 2(d) 3(e) more than 33. How many of the following Widget member functions are allowed to get the value of Widget datamember thisValue? (a) 0(b) 1(c) 2(d) 3(e) 44. The source code for Widget member function extract() is most likely to be found in which ofthe following files?(a) Widget.h(b) Widget.cpp(c) Widget.obj(d) Widget.lib(e) ClientCode.cpp5. The prototype for Widget auxiliary operator << is most likely to be found in which of the followingfiles?(a) Widget.h(b) Widget.cpp(c) Widget.obj(d) Widget.lib(e) ClientCode.cppWidget(const string &id = "ID", const string &value = "Value");Widget& operator = (const Widget &source);void insert(ostream &sout) const;void setID(const string &s);CS101 PLEDGED SPRING 2001CS 101 PLEDGED PAGE 4 OF 106. Which of the following definitions implements a shallow Widget copy constructor?(a) Widget::Widget(const Widget &w) {string id = w.getID();string value = w.getValue();Widget(id, value);}(b) Widget::Widget(const Widget &w) {string id = w.getID();string value = w.getValue();setID(id);setValue(value);}(c) Widget::Widget(const Widget &w) {thisID = w.thisID;thisValue = w.thisValue;}(d) More than one of the preceding choices with choice b being preferred.(e) Choices a, b, and c are equally goodIn Questions 7 – 9, the following definitions are in effect. 7. What is the output (if any) of the following code segment? (a) (X - abc)(b) (X - def)(c) (X - jkl)(d) (Z - jkl)(e) none of the above8. How many non-constructors Widget member functions can be invoked with W as the invokingobject?(a) 0(b) 1(c) 2(d) 3(e) more than 3const Widget W("W", "abc");Widget X("X", "def");Widget Y("Y", "ghi");Widget Z("Z", "jkl");X = Y = Z;cout << X << endl;CS101 PLEDGED SPRING 2001CS 101 PLEDGED PAGE 5 OF 109. In which file(s) is the following statement most likely to occur?X.setID("aaa");(a) Widget.cpp(b) ClientCode.cpp(c) ClientCode.exe(d) Both Widget.cpp and ClientCode.cpp(e) None of the aboveQuestion 10 – 14 are concerned with implementing Widget member function concatenate(). Thefunction is to return a Widget object whose data member thisID is to have value of the left oper-and’s data member thisID and whose data member thisValue is to be a concatenation of the leftand right operand thisValue data members. Thus, in particular, we want the function to have a def-inition that allows the following code segment to have output Your implementation is to begin by defining three string variables id, leftValue, and right-Value, where their names imply their use. With those variables you are to define a Widgetresult representing the return value for the function.10. Which of the following is the appropriate definition for id?(a) string id = getID();(b) string id << getID();(c) string id << thisID;(d) string id = suffix.getID();(e) none of the above11. Which of the following is the appropriate definition for leftValue?(a) string leftValue = Widget;(b) string leftValue = getValue();(c) string leftValue << getValue();(d) string leftValue << thisValue;(e) none of the above12. Which of the following is the appropriate definition for rightValue?(a) string rightValue = suffix;(b) string rightValue = suffix.getValue();(c) string rightValue << suffix.getValue();(d) string rightValue << suffix.thisValue;(e) none of the aboveWidget X("X", "def");Widget Y("Y", "ghi");Widget Z("Z", "jkl");cout << X + Y << endl;cout << Y + Z << endl;(X - defghi)(Y - ghijkl)CS101 PLEDGED SPRING 2001CS 101 PLEDGED PAGE 6 OF 1013. Which of the following is the appropriate definition for result?(a) string result = leftValue + rightValue;(b) string result << leftValue + rightValue;(c) Widget result(id, leftValue + rightValue);(d)


View Full Document

UVA CS 101 - Exams CS 101

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 Exams CS 101
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 Exams CS 101 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 Exams CS 101 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?