Solved > Question Computing III: Homework Packet 10 Name___________________________________ SHORT:857433 …

Question

Computing III: Homework Packet 10

Name___________________________________

SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question.

1) If a given task being performed by a function involves more than one object, then that 1)

function should normally be a ________ function.

2) A ________ function is not a member of the class, but has access to the private members of 2)

the class.

3) Putting the keyword const in front of a pass by reference parameter guarantees ________. 3)

4) An operator that expects only one parameter is called a ________ operator 4)

5) The assignment operator must be a ________ of the class. 5)

6) If a given task being performed by a function involves one object, then that function should 6)

normally be a ________ function.

7) Both the copy constructor and the assignment operator should make ________. 7)

8) Write the function declaration for a destructor for a class named myClass. 8)

9) Write the function declaration for a copy constructor for a class named myClass. 9)

10) Putting the keyword const after the function declaration guarantees ________. 10)

11) Write the function declaration for an assignment operator for a class named myClass. 11)

12) In order to do automatic type conversion for your class, you would write ________. 12)

13) An operator that expects two parameters is called a ________ operator. 13)

14) A friend function needs to be passed an object of the class. If the friend only needs to access 14)

the object, but not change its data members, then the object should be passed as ________.

15) An overloaded extraction or insertion operator should return ________. 15)

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

16) Which of the following operators cannot be overloaded? 16)

A) . B) == C) [ ] D) =

1

17) The copy constructor for a class is called 17)

A) when an object of the class is passed by value to a function.

B) when a function returns an object of the class.

C) when an object of the class is initialized by another object of the class.

D) all of the above

18) Given the following class, which is the correct function header for the display function? 18)

class Rational

{

public:

Rational( );

Rational(int numer, int denom);

Rational(int whole);

int getNumerator( );

int getDenominator( );

friend void display(ostream& out, const Rational& value);

private:

int numerator;

int denominator;

};

A) friend void Rational::display(ostream& out, const Rational& value)

B) void display(ostream& out, const Rational& value)

C) void Rational::display(ostream& out, const Rational& value)

D) friend void display(ostream& out, const Rational& value)

19) Since accessors functions in a class do not modify or mutate the data members of the object, the 19)

function should have the ________ modifier.

A) private B) reference C) friend D) const

20) How many members (data and functions) does the following class have? 20)

class Rational

{

public:

Rational( );

Rational(int numer, int denom);

Rational(int whole);

int getNumerator( );

int getDenominator( );

friend void display(ostream& out, const Rational& value);

private:

int numerator;

int denominator;

};

A) 2 B) 6 C) 8 D) 7 E) 5

2

21) What is wrong with the following overloaded extraction operator declaration? 21)

istream& operator >> (istream& in, const myClass &object);

A) You cannot put the & on the return type.

B) Object should not be a pass by reference parameter.

C) Object should not be a const parameter.

D) nothing

22) When you have a class which has a dynamic array as one of it’s members, you should also include 22)

________ in the class.

A) a copy constructor

B) a destructor

C) a default constructor

D) the assignment operator

E) all of the above

23) If you want to be able to compile the following code, 23)

Rational r1;

int x;

cout << r1 + x << endl;

which overloaded operator(s) do you need?

A) friend Rational operator+( const Rational& left, int right);

B) friend ostream operator << (ostream& out, const Rational& object);

C) friend void operator+ (const Rational& left, int right);

D) friend ostream& operator << (ostream& out, const Rational& object);

E) A and D

24) Given the following function declaration, 24)

friend void display(const myClass& object);

which is the correct header for the definition of the function?

A) void display(const myClass& object)

B) void myClass::display(const myClass& object)

C) friend void display(const myClass& object)

D) friend void display(const myClass& object);

25) Operators can be overloaded as 25)

A) members of a class. B) non-friends, non-members of a class.

C) friends of a class. D) all of the above

26) In the following code fragment, which is the calling object for the less-than operator? 26)

string s1, s2;

if( s1 < s2 )

A) s2 B) s1 C) < D) none

27) Which of the following function declarations would be correct to overload the multiply operator for 27)

the Rational numbers class if declared inside the class?

A) Rational operator times(const Rational &left, const Rational &right);

B) friend Rational operator times(const Rational &left, const Rational &right);

C) Rational operator *(const Rational &left, const Rational &right);

D) friend Rational operator *(const Rational &left, const Rational &right);

3

28) If c is a character variable that contains a digit, what does the following function return? 28)

int digit_to_int(char c)

{

return ( int(c) – int(‘0’));

}

A) the integer equivalent of the digit stored in c

B) the ASCII value of c

C) the character value of c

D) none of the above

29) To overload functions with symbolic names (like + – / <<), you must use the keyword ________ 29)

before the symbolic name.

A) const B) void C) operator D) reference

30) Who can access private data in a class? 30)

A) members of the class

B) friends of the class

C) A and B

D) everyone

E) no one

31) How many parameters are there in a unary operator implemented as a friend? 31)

A) 1 B) 0

C) 2 D) as many as you need

32) Which of the following would be an appropriate function declaration to add two rational numbers 32)

if the declaration is not made within a class?

A) Rational operator+( const Rational &left, const Rational &right);

B) void operatator+( const Rational &left, const Rational &right);

C) friend Rational operator+( const Rational &left, const Rational &right);

D) void friend operator+( const Rational &left, const Rational &right);

33) Which of the following are valid declarations for an assignment operator for a class named 33)

myClass?

A) void operator = (const myClass& source);

B) void friend operator = (const myClass& source);

C) void operator = (myClass& left, const myClass& source);

D) void friend operator = (myClass& left, const myClass& source);

34) If obj1 and obj2 are both objects of a class that uses dynamic memory allocation, but the class does 34)

not have an assignment operator, what happens if you execute the following code?

obj1 = obj2;

A) A run-time error occurs, because the C++ system does not know how to do the assignment.

B) A syntax error occurs, you cannot assign one object to another object without the = operator.

C) There is a complete and independent copy of all the dynamic memory from obj2 to obj1.

D) The pointer(s) to the dynamically declared memory in obj2 are copied to the corresponding

pointers in obj1.

35) How many parameters are there in a binary operator implemented as a member function? 35)

A) 2 B) 0

C) 1 D) as many as you need

4

36) The destructor for a class is called 36)

A) explicitly from the main program.

B) only at the end of main.

C) when the class is instantiated.

D) when the object of the class goes out of scope.

37) If we have a full selection of accessor and mutator functions, why would we have friend functions? 37)

A) The friend function must call the accessor or mutator functions anyway.

B) more efficient access to the private data members

C) You should not have them.

D) none of the above

38) How many parameters are there in a binary operator implemented as a friend? 38)

A) 2 B) 1

C) 0 D) as many as you need

39) In an overloaded insertion or extraction operator, which object should be the first parameter, the 39)

stream or the object of the class?

A) the stream B) It doesn’t matter.

C) the object D) none of the above

40) Why should you generally pass an object of the class to a friend function as a reference parameter? 40)

A) It is more efficient to pass the object by reference.

B) if the friend function will not change the values of the data member(s)

C) if the friend function changes the values of the data member(s)

D) A and B

E) A and C

41) What member functions do you need to allow the compiler to perform automatic type conversions 41)

from a type different than the class to the class?

A) overloaded constructors B) This already happens automatically.

C) converters D) This cannot be done.

5

42) Given the following class, what is syntactically wrong with the implementation of the display 42)

function?

class Rational

{

public:

Rational( );

Rational(int numer, int denom);

Rational(int whole);

int getNumerator( );

int getDenominator( );

friend void display(ostream& out, const Rational& value);

private:

int numerator;

int denominator;

};

void display(ostream& out, const Rational& value)

{

out << value.getNumerator( ) << ‘/”<< value.getDenominator( );

}

A) value must not be pass by reference. B) nothing

C) The get functions are not const functions. D) out should be pass by value.

43) What happens when you define a class that used dynamic memory allocation and define a 43)

destructor but no copy constructor?

A) If an object of the class is plugged in for a call-by-value parameter, when the function ends,

the parameter’s dynamic memory is returned to the freestore at the end of the function

execution.

B) It is possible to modify the values in the argument in the function.

C) When an object that was used as an argument for a call-by-value parameter goes out of

scope, it will cause a run-time error.

D) all of the above

E) none of the above

6

44) What is wrong with the following member function definition given the class below? 44)

class Rational

{

public:

Rational( );

Rational(int numer, int denom);

Rational(int whole);

int getNumerator( ) const;

int getDenominator( ) const;

friend void display(ostream& out, const Rational& value);

private:

int numerator;

int denominator;

};

int Rational::getNumerator( ) const

{

numerator = 0;

return numerator;

}

A) You cannot set the numerator to zero.

B) The function may not modify numerator, but it can modify denominator.

C) The function may not modify any of the private data members.

D) nothing

E) A and C

45) Which of the following are not correct? 45)

A) The destructor of a class is a void function.

B) The destructor of a class is not named the same as the name of the class, but preceded with a

tilde.

C) The destructor of a class is not called when an object of the class goes out of scope.

D) The destructor of a class is not a member of the class.

E) all of the above

46) When overloading an operator, which of the following is true? 46)

A) The operator can be a friend or a member of the class.

B) One of the arguments must be an object of the class.

C) The operator does not have to be a friend or a member of the class.

D) all of the above

E) none of the above

7

47) Given the following class declaration, 47)

class Rational

{

public:

Rational( );

Rational(int numer, int denom);

int getNumerator( ) const;

int getDenominator( ) const;

friend void display(ostream& out, const Rational& value);

friend bool operator(const Rational& left, const Rational& right);

private:

int numerator;

int denominator;

};

what must we add to the class in order for the following code to compile?

Rational myRational(2,3);

if ( 3 < myRational)

A) We need a constructor that expects a ration number

B) We need another < operator that expects an integer as the first parameter.

C) We need another < operator that expects an integer as the second parameter.

D) We need a constructor that expects an integer

E) B or D

48) Why are the extraction and insertion operators always implemented as friends of the class rather 48)

than as members of the class?

A) They don’t, they could be members.

B) because they return a reference

C) because the first parameter must be the stream object

D) because the stream is passed by reference

TRUE/FALSE. Write ‘T’ if the statement is true and ‘F’ if the statement is false.

49) You cannot create new operators (such as the quote). 49)

50) Friend functions may directly modify or access the private data members. 50)

51) The following is a properly declared overloaded insertion operator for myClass. 51)

ostream& operator << (ostream &out, const myClass &obj);

52) Operators must be friends of the class. 52)

53) You may not change the precedence of operators by overloading them. 53)

54) Friend functions are members of the class. 54)

55) Functions that are constant member functions may call constant class accessor functions. 55)

8

56) If you have mutators and accessors, you should not have friend functions also. 56)

57) All operators can be overloaded. 57)

58) Functions that are constant member functions may call the class mutator functions. 58)

9

 

GraduateWriterHelp.com is an online academic writing platform that provides extensive assistance to graduate school students as they work through their research projects, papers and dissertations. GraduateWriterHelp.com gives students access to experienced professionals who can provide the help they need in a timely and efficient manner. The service offers a wide range of services, including editing, proofreading, formatting, researching and more that can give students the confidence they need to write the perfect paper or dissertation for their chosen subject matter.

Services Offered by GraduateWriterHelp.com
GraduateWriterHelp.com offers a wealth of different services designed to make research projects easier for graduate school students. These include editing, proofreading, formatting and researching services, all tailored specifically for graduate-level studies such as PhDs or Master’s degrees in any field from business administration to engineering or even psychology – all with the aim of helping busy students find success in their academics without having to sacrifice other important commitments like family time or work hours towards earning a living wage outside of college hours.

The Benefits of Using GraduateWriterHelp.com
Using GraduateWriterHelp.com gives you access to experts from all over the world who are highly qualified and experienced in helping graduate-level students to complete successful projects in various fields quickly and efficiently – something that would otherwise be difficult, if not impossible, given tight deadlines associated with most Ph.D./Master’s degree programs today. Moreover, using this platform makes it easier for students to keep up with multiple research tasks simultaneously since there are so many different experts available on tap at any one time – no longer will you have to put off studying one topic while focusing on another because of lack of resources! Additionally, having access to professional editors, proofreaders, but also formatters means that quality control standards aren’t sacrificed when finishing major pieces – since these individuals understand what makes up good academic writing better than anyone else and can offer guidance on how best one should go about making improvements along those lines. Finally, there is also an added cost-saving benefit associated with utilizing Graduate Writer Help compared to hiring an independent contractor (which could potentially run into thousands depending on length/complexity).
This service allows users only pay for what students need, which tends to be much lower overall because customers pay per hour rather than project basis, thus resulting to greater financial flexibility, especially for those just starting out postgraduate studies looking to conserve some pennies here there whenever possible!

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?