15 Problems on Computer Programming - Quiz 2 | CS 253, Quizzes of Computer Science

Material Type: Quiz; Class: Problem Solving with C++; Subject: Computer Science; University: Colorado State University; Term: Unknown 1989;

Typology: Quizzes

Pre 2010

Uploaded on 03/10/2009

koofers-user-ilt
koofers-user-ilt 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 253: Problem Solving in C++ Fall 2006
Name:
Quiz 2, September 20, 2006
1. Mark the following statements as true or false:
(a) In C++, all operators can be overloaded for user-defined types.
(b) In C++, operators cannot be redefined for built-in types.
(c) The function that overloads a function is called the operator func-
tion.
(d) C++ allows users to create their own operators.
(e) The precedence of an operator cannot be changed but its associa-
tivity can be changed.
1
pf3
pf4
pf5

Partial preview of the text

Download 15 Problems on Computer Programming - Quiz 2 | CS 253 and more Quizzes Computer Science in PDF only on Docsity!

CS 253: Problem Solving in C++ Fall 2006

Name:

Quiz 2, September 20, 2006

  1. Mark the following statements as true or false:

(a) In C++, all operators can be overloaded for user-defined types.

(b) In C++, operators cannot be redefined for built-in types.

(c) The function that overloads a function is called the operator func- tion.

(d) C++ allows users to create their own operators.

(e) The precedence of an operator cannot be changed but its associa- tivity can be changed.

(f) It is not necessary to overload relational operators for classes that have only int member variables.

(g) When writing the definition of a friend function, the keyword friend must appear in the function heading. The function head-

ing of the operator function to overload the pre-increment operator (++) and the post-increment operator (++) is the same because both operators have the same symbols.

  1. What is a friend function?
  2. Suppose that the binary operator << is to be overloaded for a user- defined class mystery. Why must << be overloaded as a friend func- tion?
  3. Suppose that the binary operator + is overloaded as a member function for a class strange. How many parameters does the function operator+ have?
  4. When should a class overload the assignment operator and define the copy constructor?
  1. Find the error(s) in the following code:

class mystery { ... bool operator<=(mystery); ... };

bool mystery::<=(mystery rightobj) { ... }

  1. Find the error(s) in the following code:

class mystery { ... bool operator<=(mystery, mystery); ... };

  1. Find the error(s) in the following code:

class mystery { ... friend operator+(mystery); //overload binary + ... };

  1. How many operators are required to overload the pre-increment oper- ator for a class as a member function?
  1. How many operators are required to overload the pre-increment oper- ator for a class as a friend function?
  2. How many operators are required to overload the post-increment oper- ator for a class as a member function?
  3. How many operators are required to overload the post-increment oper- ator for a class as a friend function?
  4. Does a nonmember function have to be a friend to access a class’s members?
  5. Mark the following statements as true or false.

(a) In C++, pointer is a reserved word. (b) In C++, pointer variables are declared using the word pointer. (c) The statement delete p deallocates the variable pointer p. (d) The statement delete p deallocates the dynamic variable that is pointed to by p.