Skip to main content

Section 1.7 Homework 7 -- Classes

Exercises Exercises

1.

The acronym "OOP" refers to...
  • object-oriented programming
  • open object paradigm
  • output operator programming

2.

3.

4.

It’s important that other programmers are able to use one of the classes you’ve created in C++ without knowing the details of how you implemented the class.
  • True
  • False

5.

6.

The operator `::` (two colons) in C++ is called the...
  • scope resolution operator
  • double colon operator
  • four dots operator
  • namespace specifier

7.

8.

A constructor is called automatically whenever a variable of the class is _______________ .
  • declared
  • accessed
  • evaluated
  • destroyed

9.

Which of these is a syntactically correct prototype for the constructor of a class called `quadratic`?
  • quadratic(a, b, c);
  • quadratic(double a, double b, double c);
  • double quadratic(double a, double b, double c);
  • quadratic_constructor(double a, double b, double c);
  • void quadratic_constructor(double a, double b, double c);

10.

11.

12.

A constructor with no formal parameters is called a _________ constructor.
  • default
  • deficient
  • simple
  • working

13.

True, or false? When defining a new class, you may declare as many constructors as you like.
  • true
  • false

14.

The value semantics of a class determines how values are copied from one object of the class to another.Β  In C++, the value semantics consists of these two operations:
  • assignment operator
  • copy constructor
  • default constructor
  • stream output operator (<<)

15.

Which of the following is a correct prototype for a COPY CONSTRUCTOR belonging to the throttle class?
  • throttle(const throttle &t);
  • throttle(int size);
  • void throttle(throttle t);
  • void throttle(int size);

16.

Which of the following parts of defining a new class in C++ belong in the HEADER file (e.g., throttle.h)?
  • an extended comment which tells folks how to USE the class
  • the class definition, including prototypes for member functions and declarations for member variables
  • a macro guard to prevent duplicate definition
  • complete implementations for all member functions

17.

True, or false? You should always put a ’using’ statement in the header file for a new C++ class, to help out other programs that will include that header file in their code.
  • false
  • true

18.

19.

The function int_to_string takes an integer ’nums’ and returns the equivalent string of digits. Β For example, the function call int_to_string(33250) returns the equivalent string, "33250".
Hint: Β Use a stringstream to help with this conversion. Β Assume that the enclosing program has included the sstream header file.

20.

Write a function is_numerical that takes a string called 'input_string' and returns true if that string can be interpreted as a number; otherwise, is_numerical returns false.
Here is the meaning of the phrase, "string can be interpreted as a number", in the current context:
- the string is not empty
- the string has no characters other than '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
- the optional '-' character can ONLY be at index 0 (for indicating a negative number)
- the optional '.' character (for making a decimal point) should NOT appear more than once and should NOT appear to the left of '-'
- the string must contain AT LEAST ONE DIGIT
Note: This is a review question.Β  You might find it helpful to write helper functions, call on string class methods, use a for loop, a stringstream,Β  a switch statement, etc.Β  Everything we’ve used so far is fair game. Make a CLEAR PLAN before you start coding.
You have attempted of activities on this page.