Ch.10 Flashcards
A member function that allows the user of the class to change the value in a data member is known as
a mutation
Why do you want to usually make data members private in a class?
A) so that no one can use the class
B) provide information hiding
C) ensure data integrity
D) provide data abstraction
E) B, C, and D
ensure data integrity
provide data abstraction.
provide information hiding.
You specify an individual member of a struct by using
the dot operator
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 outputPerson(ostream& out) { //what goes here? }
out << age << weight << id;
What is wrong with the following structure definition?
struct MyStruct
{
int size;
float weight;
}
missing semicolon
Member functions of a class
may be in either section
To assign values to a structure variable, you use the
assignment operator
A class member function that automatically initializes the data members of a class is called
a constructor
Data members or member functions of a class that are declared to be private
may only be accessed by members of the class
Given the following class definition, how could you use the constructor to assign values to an object of this class?
class CDAccount { public: CDAccount( ); CDAccount(float interest, float newBalance); float getBalance( ); float getRate( ); void setRate(float interest); void setBalance(float newBalance); private: float balance, rate; };
and the following object declaration
CDAccount myAccount;
myAccount = CDAccount(myRate, myBalance)
If you design a class with private data members, and do not provide mutators and accessors, then
A) the class cannot be used. B) the data cannot be changed or viewed by anyone.
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;
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 data type
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,0);
If you have a class named myPersonClass, which of the following correctly declare a constructor in the class definition?
myPersonClass( );