Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

C++ Programming From Problem

Analysis to Program Design 8th Edition


Malik Test Bank
Visit to download the full and correct content document: https://testbankdeal.com/dow
nload/c-programming-from-problem-analysis-to-program-design-8th-edition-malik-test
-bank/
Name: Class: Date:

Chapter 10
1. A class is an example of a structured data type.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 652
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

2. In C++, class is a reserved word and it defines only a data type.


a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 653
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

3. If the heading of a member function of a class ends with the word const, then the function member cannot modify the
private member variables, but it can modify the public member variables.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 655
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

4. In C++ terminology, a class object is the same as a class instance.


a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 656
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
Copyright Cengage Learning. Powered by Cognero. Page 1
Name: Class: Date:

Chapter 10
DATE MODIFIED: 10/5/2016 1:41 PM

5. Given this declaration:


class myClass
{
public:
void print(); //Output the value of x;
MyClass();

private:
int x;
};

myClass myObject;

The following statement is legal.


myObject.x = 10;
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 657
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/30/2016 12:12 PM

6. If an object is declared in the definition of a member function of the class, then the object can access both the public
and private members of the class.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 657
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

7. If an object is created in a user program, then the object can access both the public and private members of the
class.
a. True
b. False
ANSWER: False
POINTS: 1

Copyright Cengage Learning. Powered by Cognero. Page 2


Name: Class: Date:

Chapter 10
REFERENCES: 657
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

8. You can use arithmetic operators to perform arithmetic operations on class objects.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 659
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

9. As parameters to a function, class objects can be passed by reference only.


a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 660
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

10. The public members of a class must be declared before the private members.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 670
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

11. The components of a class are called the ____ of the class.
a. elements b. members
c. objects d. properties
ANSWER: b
Copyright Cengage Learning. Powered by Cognero. Page 3
Name: Class: Date:

Chapter 10
POINTS: 1
REFERENCES: 652
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

12. Which of the following class definitions is correct in C++?

a. class studentType
{
public:
void setData(string, double, int);
private:
string name;
};

b. class studentType
{
public:
void setData(string, double, int);
void print() const;
private:
string name;
double gpa;
}

c. class studentType
{
public void setData(string, double, int);
private string name;
};

d. studentType class
{
public: void setData(string, double, int);
private: string name;
};

ANSWER: a
POINTS: 1
REFERENCES: 654
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

13. If a member of a class is ____, you cannot access it outside the class.
Copyright Cengage Learning. Powered by Cognero. Page 4
Name: Class: Date:

Chapter 10
a. public b. automatic
c. private d. static
ANSWER: c
POINTS: 1
REFERENCES: 654
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

14. A class and its members can be described graphically using a notation known as the ____ notation.
a. OON b. OOD
c. UML d. OOP
ANSWER: c
POINTS: 1
REFERENCES: 656
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

clockType
-hr: int
-min: int
-sec: int
+setTime(int, int, int): void
+getTime(int&, int&, int&) const: void
+printTime() const: void
+incrementSeconds(): int
+incrementMinutes(): int
+incrementHours(): int
+equalTime(const clockType&) const: bool

15. The word ____ at the end of several the member functions in the accompanying figure class clockType specifies
that these functions cannot modify the member variables of a clockType object.
a. static b. const
c. automatic d. private
ANSWER: b
POINTS: 1
REFERENCES: 655
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
PREFACE NAME: clockType definition
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM
Copyright Cengage Learning. Powered by Cognero. Page 5
Name: Class: Date:

Chapter 10

16. Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class?
a. clock b. clockType
c. Type d. +clockType
ANSWER: b
POINTS: 1
REFERENCES: 656
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
PREFACE NAME: clockType definition
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

17. Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many
private members are in the class?
a. none b. zero
c. two d. three
ANSWER: d
POINTS: 1
REFERENCES: 656
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
PREFACE NAME: clockType definition
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

18. A ____ sign in front of a member name on a UML diagram indicates that this member is a public member.
a. + b. -
c. # d. $
ANSWER: a
POINTS: 1
REFERENCES: 656
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

19. A ____ sign in front of a member name on a UML diagram indicates that this member is a protected member.
a. + b. -
c. # d. $
ANSWER: c
POINTS: 1
REFERENCES: 656
Copyright Cengage Learning. Powered by Cognero. Page 6
Name: Class: Date:

Chapter 10
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

class rectangleType
{
public:
void setLengthWidth(double x, double y);
//Postcondition: length = x; width = y;
void print() const;
//Output length and width;
double area();
//Calculate and return the area of the rectangle;
double perimeter();
//Calculate and return the parameter;
rectangleType();
//Postcondition: length = 0; width = 0;
rectangleType(double x, double y);
//Postcondition: length = x; width = y;

private:
double length;
double width;
};

20. Consider the accompanying class definition. Which of the following variable declarations is correct?
a. rectangle rectangleType;
b. class rectangleType rectangle;
c. rectangleType rectangle;
d. rectangle rectangleType.area;
ANSWER: c
POINTS: 1
REFERENCES: 657
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
PREFACE NAME: rectangleType class
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

21. Consider the accompanying class definition, and the declaration:

rectangleType bigRect;

Which of the following statements is correct?


a. rectangleType.print(); b. rectangleType::print();
c. bigRect.print(); d. bigRect::print();
ANSWER: c
Copyright Cengage Learning. Powered by Cognero. Page 7
Name: Class: Date:

Chapter 10
POINTS: 1
REFERENCES: 657
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
PREFACE NAME: rectangleType class
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

22. Consider the accompanying class definition, and the object declaration:

rectangleType bigRect(14,10);

Which of the following statements is correct?


a. bigRect.setLengthWidth();
b. bigRect.setLengthWidth(3.0, 2.0);
c. bigRect.length = 2.0;
d. bigRect.length = bigRect.width;
ANSWER: b
POINTS: 1
REFERENCES: 658
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
PREFACE NAME: rectangleType class
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

23. In C++, the ____ is called the member access operator.


a. . b. ,
c. :: d. #
ANSWER: a
POINTS: 1
REFERENCES: 657
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

24. A class object can be ____. That is, it is created each time the control reaches its declaration, and destroyed when
the control exits the surrounding block.
a. static b. automatic
c. local d. public
ANSWER: b
POINTS: 1

Copyright Cengage Learning. Powered by Cognero. Page 8


Name: Class: Date:

Chapter 10
REFERENCES: 660
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

25. A class object can be ____. That is, it can be created once, when the control reaches its declaration, and destroyed
when the program terminates.
a. static b. automatic
c. local d. public
ANSWER: a
POINTS: 1
REFERENCES: 660
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

26. In C++, you can pass a variable by reference and still prevent the function from changing its value by using the
keyword ____ in the formal parameter declaration.
a. automatic b. private
c. static d. const
ANSWER: d
POINTS: 1
REFERENCES: 660
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

27. In C++, the scope resolution operator is ____.


a. : b. ::
c. $ d. .
ANSWER: b
POINTS: 1
REFERENCES: 662
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

28. A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function.
a. accessor b. mutator

Copyright Cengage Learning. Powered by Cognero. Page 9


Name: Class: Date:

Chapter 10
c. constructor d. destructor
ANSWER: a
POINTS: 1
REFERENCES: 666
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

29. To guarantee that the member variables of a class are initialized, you use ____.
a. accessors b. mutators
c. constructors d. destructor
ANSWER: c
POINTS: 1
REFERENCES: 671
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

class secretType
{
public:
static int count;
static int z;

secretType();
secretType(int a);
void print();
static void incrementY();

private:
int x;
static int y;
};

secretType::secretType()
{
x = 1;
}

secretType::secretType(int a)
{
x = a;
}

void secretType::print()
{
Copyright Cengage Learning. Powered by Cognero. Page 10
Name: Class: Date:

Chapter 10
cout << "x = " << x << ", y = " << y
<< "z = " << z
<< ", count = " << count << endl;
}

static void secretType::incrementY()


{
y++;
}

30. Consider the accompanying class and member functions definitions. How many constructors are present in the class
definition?
a. none b. one
c. two d. three
ANSWER: c
POINTS: 1
REFERENCES: 672
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
PREFACE NAME: secretType class
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

31. How many destructors can a class have?


a. no explicit destructors b. one
c. two d. any number
ANSWER: b
POINTS: 1
REFERENCES: 681
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/30/2016 12:15 PM

32. A destructor has the character ____, followed by the name of the class.
a. . b. ::
c. # d. ˜
ANSWER: d
POINTS: 1
REFERENCES: 681
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

Copyright Cengage Learning. Powered by Cognero. Page 11


Name: Class: Date:

Chapter 10
33. What does ADT stand for?
a. abstract definition type b. asynchronous data transfer
c. abstract data type d. alternative definition type
ANSWER: c
POINTS: 1
REFERENCES: 682
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

34. Which of the following is true about classes and structs?


a. By default, all members of a struct are public and all members of a class are private.
b. A struct variable is passed by value only, and a class variable is passed by reference only.
c. An assignment operator is allowed on class variables, but not on struct variables.
d. You cannot use the member access specifier private in a struct.
ANSWER: a
POINTS: 1
REFERENCES: 685
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

35. If a function of a class is static, it is declared in the class definition using the keyword static in its ____.
a. return type b. parameters
c. heading d. main function
ANSWER: c
POINTS: 1
REFERENCES: 701
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

36. With ____________________ functions, the definitions of the member functions are placed in the implementations
file.
ANSWER: inline
POINTS: 1
REFERENCES: 700
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
Copyright Cengage Learning. Powered by Cognero. Page 12
Name: Class: Date:

Chapter 10
DATE MODIFIED: 10/30/2016 12:22 PM

37. If a class object is passed by ____________________, the contents of the member variables of the actual parameter
are copied into the corresponding member variables of the formal parameter.
ANSWER: value
POINTS: 1
REFERENCES: 660
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

38. Non-static member variables of a class are called the ____________________ variables of the class.
ANSWER: instance
POINTS: 1
REFERENCES: 666
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

39. A program or software that uses and manipulates the objects of a class is called a(n) ____________________ of that
class.
ANSWER: client
POINTS: 1
REFERENCES: 666
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

40. A(n) ____________________ function of a class changes the values of the member variable(s) of the class.
ANSWER: mutator
POINTS: 1
REFERENCES: 666
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

41. A(n) ____________________ contains the definitions of the functions to implement the operations of an object.
ANSWER: implementation file
POINTS: 1
REFERENCES: 686
Copyright Cengage Learning. Powered by Cognero. Page 13
Name: Class: Date:

Chapter 10
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

42. The header file is also known as the ____________________.


ANSWER: interface file
interface
POINTS: 1
REFERENCES: 686
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

43. A(n) ____________________ is a statement specifying the condition(s) that must be true before the function is called.
ANSWER: precondition
POINTS: 1
REFERENCES: 687
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:41 PM
DATE MODIFIED: 10/5/2016 1:41 PM

Copyright Cengage Learning. Powered by Cognero. Page 14


Another random document with
no related content on Scribd:
back
back
back
back
back
back
back
back
back
back
back
back
back

You might also like