Chapter 13 C++

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What are a class's responsibilities?

The class is responsible for knowing the action that the class is responsible for doing.

Under what circumstances should a member function be private?

When the function is needed for internal processing, but not useful to the program outside of the class. In some cases a class may have member functions that initialize member variables or destroy their contents. Those functions should not be accessible by external parts of the program because they may be called at a wrong time.

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

Yes, executes when the object is created.

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

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

Is it possible to have more than one onstructor?

Yes, it's called Constructor Overloading.

A class is very similar to a ______

Structure

True or False! A class may only have on destructor.

T

True or False! A class's responsibilities are the things the class is responsible for knowing, and actions the class must perform.

T

True or False! Class members are private by default.

T

True or False! Classes and structures in C++ are very similar

T

True or False! Constructors may have default arguments.

T

True or False! Constructors may not have a return type.

T

True or False! Destructors cannot take arguments.

T

True or False! It is legal to define a pointer to a class object.

T

True or False! Member functions may be overloaded.

T

True or False! You can use the new operator to dynamically allocate an instance of a class.

T

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

->

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

1. Get a written description of the problem domain. 2. Identify all the nouns in the description. Each of these are called potential. 3. Refine the list to include only the classes that are relevant to the problem.

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

A class describes a data type. An instance of a class is an object of the data type that exists in memory.

A ______ is a key word inside a class declaration that establishes a member's accessibility.

Access specifier

What is an Accessor function?

Accessor Function: When a member function that gets a value from a class's member variable but does not change then it is known as an accessor function.

A ______ may be used to pass arguments to the constructors of elements in an object array.

String Object

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

Blueprint -> Classes Houses -> Objects Long Answer: Classes are analogous to the blueprint where the objects created from the blueprints. The blueprint itself is a detailed description.

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

Call a constructor that requires arguments we must specify the arguments for each object individually in an initializer list such as: InventoryItem inventory[3] = {"Hammer", "Wrench", "Pliers"};

If you were writing the external definitions of the Canine class's member functions, you would save them in a file named? ______

Canine.cpp

If you were writing the declaration of a class named Canine, what would you name the file it was stored in? ______

Canine.h

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

Class

A ______ is automatically called when an object is created.

Constructor

A class may only have one default ______ and one ______

Constructor and one Destructor

What is a constructor?

Constructor is a member function that has the same name of the class and is automatically invoked when an object is created in memory or instantiated.

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

Constructors

A ______ constructor is one that requires no arguments.

Default

A constructor whose arguments all have default values is a ______ constructor.

Default

A ______ is a member function that is automatically called when an object is destroyed.

Destructor

A ______ is a member function with the same name as the class.

Destructor

What is a de-constructor?

Destructor is a member function of the class that has same name of the class but preceded with a tilde (~) and is used to destroy the objects.

______ is an object's ability to contain and manipulate its own data.

Encapsulation

True or False! A class may not have a constructor with no parameter list, and a constructor whose arguments all have default values.

F

True or False! 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.

F

True or False! All private members of a class must be declared together.

F

True or False! All public members of a class must be declared together.

F

True or False! Constructors cannot take arguments.

F

True or False! Constructors do not have to have the same name as the class

F

True or False! Constructors may not be overloaded.

F

True or False! Destructors may return a value.

F

True or False! Member of a struct are private by default

F

True or False! Private members must be declared before public members.

F

True or False! To find the classes needed for an object-oriented application, you identify all of the verbs in a description of the problem domain.

F

True or False! When an array of objects is defined, the constructor is only called for the first element.

F

When a member function's body is written inside a class declaration, the function is ______.

Inline

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

Instance

What is the difference between the following Person structure and Person class? struct Person { string name; int age; }; ------------------------------- class Person { string name; int age; };

Main difference between struct and classes: Default declaration attributes are structures taken as public, classes are taken as private. Attributes name and age declarations public is used for Person structure, private members for Person class.

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

Member functions are used to retrieve a set data for class there is not a need to have cin or cout states in function.

What is a mutator function?

Mutator Function: When a member function that stores a value in a member variable or a changes the value of member variable in some way then it is known as a mutator function.

Is it possible to have more than one destructor?

No, a class can have any number of constructors but only one destructor.

______ programming is centered around objects.

Object-Oriented

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

Parameter

What is the default access specification of class members

Private

______ programming is centered around functions or procedures.

Procedural

The two common programming methods in practice today are ______ and ______.

Procedural Programming and Object-Oriented Programming

Constructors cannot have a ______ type.

Return

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?

getRadi is the function Circle

Like constructors, destructors cannot have a ______ type.

return

A destructor has the same name as the class, but is preceded by a ______ character.

tilde (~)


संबंधित स्टडी सेट्स

Substance Use Disorders Diagnosis

View Set

Atome/molecule/intrant extrant/mélange/shema de principe/shema de construction/ tableau périodique/ changement

View Set

physics chapter 1 lecture assignment, physics chapter 2/3 lecture assignment, physics chapter 2/3 lecture quiz, Chapter 4 Lecture Assignment

View Set

MODULE 10: Ch. 42 (Fluid & Electrolytes) - FLUID BALANCE

View Set

Chapter 61: Management of Patients with Neurologic Dysfunction

View Set

ART 311 - Final Exam Study Guide

View Set