CS M125 chapter 13

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/67

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:34 PM on 5/18/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

68 Terms

1
New cards

What is the difference between a class and an instance of the class?

  1. A class describes a data type.

  2. An instance of a class is an object of the data type

that exists in memory.

2
New cards

What is the difference between the following Person structure and Person class?

struct Person

{

string name;

int age;

};

class Person

{

string name;

int age;

};

All members of a struct are public by default.

The members of a class are private by default.

3
New cards

What is the default access specification of class members?

private

4
New cards

Look at the following function header for a member function.

void Circle::getRadius()

What is the name of the function?

What class is the function a member of?

The function's name is getRadius.

It is a member of the Circle class.

5
New cards

A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the

blueprint or the houses?

A class is analogous to the blueprint

6
New cards

What is a mutator function? What is an accessor function?

A mutator is a member function that stores a value in a private member variable, or in some way changes an attribute.

An accessor is a member function that retrieves the value stored in a private member variable.

7
New cards

Is it a good idea to make member variables private? Why or why not?

Yes. protects the variables from being manipulated by code outside the class, and prevents them from receiving invalid data

8
New cards

Can you think of a good reason to avoid writing statements in a class member function that use cout or cin ?

Classes should avoid handling input and output directly, instead using member functions to store and retrieve data so programmers can choose their own I/O methods.

9
New cards

Under what circumstances should a member function be private?

Functions meant only for a class’s internal operations, such as initializing or destroying data, should remain inaccessible outside the class to prevent them from being used at the wrong time.

10
New cards

What is a constructor? What is a destructor?.

A constructor is a member function that is automatically called when a class object is created.

A destructor is a member function that is automatically called when a class object is destroyed

11
New cards

What is a default constructor? Is it possible to have more than one default constructor?

A default constructor is a constructor that is called without any arguments.

It is not possible to have more than one default constructor

12
New cards

Is it possible to have more than one constructor? Is it possible to have more than one

destructor?

Yes, it is possible to have more than one constructor. It is not possible to have more than one destructor

13
New cards

If a class object is dynamically allocated in memory, does its constructor execute? If so,when?

Yes, the constructor executes when the object is created.

14
New cards

When defining an array of class objects, how do you pass arguments to the constructor for each object in the array?

You specify the arguments for each object individually in an initialization list.

15
New cards

What are a class’s responsibilities?

the things that the class is responsible for knowing and the actions that the class is responsible for doing.

16
New cards

How do you identify the classes in a problem domain description?

Identify all the nouns in the problem domain description. Each of these is a potential class. Then, refine the list to include only the classes that are relevant to the problem.

17
New cards

The two common programming methods in practice today are _________ and

_________.

procedural programming, object-oriented programming

18
New cards

________ programming is centered around functions or procedures.

procedural

19
New cards

________ programming is centered around objects

object oriented

20
New cards

________ is an object’s ability to contain and manipulate its own data.

encapsulation

21
New cards

In C++ the _________ is the construct primarily used to create objects.

class

22
New cards

A class is very similar to a(n) _________.

structure

23
New cards

A(n) _________ is a key word inside a class declaration that establishes a member’s

accessibility.

access specifier

24
New cards

The default access specification of class members is _________.

private

25
New cards

The default access specification of a struct in C++ is _________.

public

26
New cards

Defining a class object is often called the _________ of a class.

instantiation

27
New cards

Members of a class object may be accessed through a pointer to the object by using the

_________ operator.

->

28
New cards

If you were writing the declaration of a class named Canine , what would you name the file it

was stored in? _________

canine.h

29
New cards

If you were writing the external definitions of the Canine class’s member functions, you

would save them in a file named _________.

canine.cpp

30
New cards

When a member function’s body is written inside a class declaration, the function is

_________.

inline

31
New cards

A(n) _________ is automatically called when an object is created

constructor

32
New cards

A(n) _________ is a member function with the same name as the class.

constructor

33
New cards

________ are useful for performing initialization or setup routines in a class object.

constructors

34
New cards

Constructors cannot have a(n) _________ type.

return

35
New cards

A(n) _________ constructor is one that requires no arguments.

default

36
New cards

A(n) _________ is a member function that is automatically called when an object is

destroyed.

destructor

37
New cards

A destructor has the same name as the class, but is preceded by a(n) _________ character.

~

38
New cards

Like constructors, destructors cannot have a(n) _________ type.

return

39
New cards

A constructor whose arguments all have default values is a(n) _________ constructor.

default

40
New cards

A class may have more than one constructor, as long as each has a different _________.

parameter list

41
New cards

A class may only have one default _________ and one _________.

constructor, destructor

42
New cards

A(n) _________ may be used to pass arguments to the constructors of elements in an object

array.

initialization list

43
New cards

T F Private members must be declared before public members.

false

44
New cards

T F Class members are private by default.

true

45
New cards

T F Members of a struct are private by default

false

46
New cards

T F Classes and structures in C++ are very similar.

true

47
New cards

T F All private members of a class must be declared together.

False

48
New cards

T F All public members of a class must be declared together.

false

49
New cards

T F It is legal to define a pointer to a class object.

true

50
New cards

T F You can use the new operator to dynamically allocate an instance of a class.

true

51
New cards

T F A private member function may be called from a statement outside the class, as long as

the statement is in the same program as the class declaration.

false

52
New cards

T F Constructors do not have to have the same name as the class.

false

53
New cards

T F Constructors may not have a return type.

true

54
New cards

T F Constructors cannot take arguments

false

55
New cards

T F Destructors cannot take arguments.

true

56
New cards

T F Destructors may return a value.

false

57
New cards

T F Constructors may have default arguments.

true

58
New cards

T F Member functions may be overloaded

true

59
New cards

60
New cards

T F A class may not have a constructor with no parameter list, and a constructor whose

arguments all have default values.

true

61
New cards

T F A class may only have one destructor.

true

62
New cards

T F When an array of objects is defined, the constructor is only called for the first element.

false

63
New cards

T F When an array of objects is defined, the constructor is only called for the first element.

false

64
New cards

T F A class’s responsibilities are the things the class is responsible for knowing, and actions

the class must perform.

true

65
New cards

73. class Circle:

{

private

double centerX;

double centerY;

double radius;

public

setCenter(double, double);

setRadius(double);

}

There should not be a colon after the word Circle.

Colons should appear after the words private and public.

A semicolon should appear after the closing brace.

66
New cards

#include <iostream>

using namespace std;

Class Moon;

{

Private;

double earthWeight;

double moonWeight;

Public;

moonWeight(double ew);

{ earthWeight = ew; moonWeight = earthWeight / 6; }

double getMoonWeight();

{ return moonWeight; }

}

int main()

{

double earth;

cout >> "What is your weight? ";

cin << earth;

Moon lunar(earth);

cout << "On the moon you would weigh "

<<lunar.getMoonWeight() << endl;

return 0;

}

The semicolon should not appear after the word Moon.

The first character of the words private and public should not be

capitalized.

There should be a colon, not a semicolon, following the words private and

public.

Semicolons should not appear in the member function headers.

In function main an argument is passed to a constructor that does not exist in the

Moon class.

The moonWeight member function should have been called prior to

getMoonWeight.

67
New cards

#include <iostream>

using namespace std;

class DumbBell;

{

int weight;

public:

void setWeight(int);

};

void setWeight(int w)

{

weight = w;

}

int main()

{

DumbBell bar;

DumbBell(200);

cout << "The weight is " << bar.weight << endl;

return 0;

}

The semicolon should not appear after the word DumbBell.

The function header for setWeight should appear as:

void DumbBell::setWeight(int w)

The line that reads:

DumbBell(200);

should read:

bar.setWeight(200);

bar.weight cannot be accessed outside of the class because no access specifier

appeared before it in the class, making the variable private to the class by default.

This means the cout statement will not work.

68
New cards

class Change

{

public:

int pennies;

int nickels;

int dimes;

int quarters;

Change()

{ pennies = nickels = dimes = quarters = 0; }

Change(int p = 100, int n = 50, d = 50, q = 25);

};

void Change::Change(int p, int n, d, q)

{

pennies = p;

nickels = n;

dimes = d;

quarters = q;

}

Both constructors are considered the default constructor.