Chapter 10

¡Supera tus tareas y exámenes ahora con Quizwiz!

Given the following structure definition, what is the correct way to initialize a variable called today? struct DateType { int day; int month; int year; } DateType today(1,1,2000); DateType today = {1,1,2000); DateType today = (1,1,2000); DateType today = {1,1,2000,0);

DateType today = {1,1,2000);

If you design a class with private data members, and do not provide mutators and accessors, then The data cannot be changed or viewed by anyone. The private data members can still be accessed from outside the class by using the & operator. none of the above A and B

The data cannot be changed or viewed by anyone.

Given the following class, what would be the best declaration for a constructor that would allow the user to initialize the object with an initial age and cost? class Wine { public: Wine(); int getAge(); float getCost(); private: int age; float cost; } Wine(); Wine(int age); Wine(int newAge, float newCost); int getAge(int newAge);

Wine(int newAge, float newCost);

A class member function that automatically initializes the data members of a class is called the init function. an operator. a cast. a constructor

a constructor

Given the following class definition, what is missing? class ItemClass { public: ItemClass(int newSize, float newCost); int getSize(); float getCost(); void setSize(int newSize); void setCost(float newCost); private: int size; float cost; }; nothing mutator functions a default constructor accessor functions

a default constructor

A member function that allow the user of the class to change the value in a data member is known as a mutation. an accessor function. a mutator function. a manipulator function.

a mutator function.

A data type consisting of data members and operations on those members which can be used by a programmer without knowing the implementation details of the data type is called an abstract definition type. a primitive data type. an abstract data type. an available data type.

an abstract data type.

A Member function that allows the user of the class to see the value in a data member is known as an accessor function. a mutation. a mutator function. a manipulator function.

an accessor function.

To assign values to a structure variable, you use the assignment operator. equals operator. less than operator. extraction operator.

assignment operator.

Given the following class and object declaration, how would you print out the age and cost of a bottle of wine? class Wine { public: Wine(); int getAge(); float getCost(); private: int age; float cost; } Wine bottle; cout << bottle.getAge() << bottle.getCost(); cout << Wine.age, Wine.cost; cout << bottle; cout << bottle.getAge << bottle.getCost; cout << bottle.age << bottle.cost;

cout << bottle.getAge() << bottle.getCost();

Given the following structure definitions, what is the correct way to print the person's birth year? struct DateType { int day; int month; int year; } struct PersonType { int age; float weight; DateType birthday; } PersonType person; cout << year; cout << peson.year; cout << person.birthday.year; cout << birthday.year;

cout << person.birthday.year;

A member function of a class should be made private never, it is illegal to make a member function private. if it will only be used by other members of the class. only if it will never be used. always.

if it will only be used by other members of the class.

Developing an ADT means that the user of your class does not have to know the details about how the class is implemented. This is known as interface. implementation. information hiding. testing and debugging.

information hiding.

A derived class has access to the public functions and variables of its ancestor classes. the private functions and variables of its ancestor classes. only the functions and variables defined it its class. none of the above

the public functions and variables of its ancestor classes.

Given the following class, what would be the best declaration for a mutator function that allows the user of the class to change the age? class Wine { public: Wine(); int getAge(); float getCost(); private: int age; float cost; } void setAge(int newAge); int getAge(int newAge); Wine(); void setAge();

void setAge(int newAge);

Given the following class definition, how would you declare an object of the class, so that the object automatically called the default constructor? class ItemClass { public: ItemClass(); ItemClass(int newSize, float newCost); int getSize(); float getCost(); void setSize(int newSize); void setCost(float newCost); private: int size; float cost; }; ItemClass myItem(1, 0.0); ItemClass myItem; ItemClass myItem(); ItemClass() myItem; You cannot do this.

ItemClass myItem;

In a structure definition, the identifiers declared in the braces are called structs. member names. classes. variables.

member names.

What is wrong with the following structure definition? struct MyStruct { int size; float weight; } nothing Braces are not needed. cannot have mixed data types in a structure missing semicolon

missing semicolon

If you have a class named myPersonClass, which of the following correctly declare a constructor in the class definition? cast(); myPersonClass::myPersonClass(); init(); myPersonClass();

myPersonClass();

Data members or member functions of a class that are declared to be private may only be accessed by the main program. are considered to be global variables. not be accessed by the class. only be accessed by members of the class.

only be accessed by members of the class.

Given the following class definition and the following member function header, which is the correct way to output the private data? class Person { public: void outputPerson(ostream& out); private: int age; float weight; int id; }; void Person::outputPerson(ostream& out) { //what goes here? } out << person; out << person.age << person.weight << person.id; out << age << weight << id; outputPerson(person);

out << age << weight << id;

In a class, all members are ________ by default. global public private all of the above

private

In a struct, all members are ________ by default. public global private all of the above

public


Conjuntos de estudio relacionados

TB - Chapter 28 Postpartum Adaptation and Nursing Assessment Chapter 29 The Postpartum Family: Early Care Needs and Home Care Chapter 30 The Postpartum Family at Risk

View Set

IB Physics HL Astrophysics Option D.5: Further Cosmology

View Set

Chapter 64: Arthritis and Connective Tissue Diseases

View Set