quiz 3 Flashcards
In a structure definition, the identifiers declared in the braces are called
member names
You specify an individual member of a struct by using
The dot operator
To assign values to a structure variable, you use the
assignment operator
What is wrong with the following structure definition?
struct MyStruct
{
int size;
float weight;
}
missing semicolon
Given the following strucure 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 «_space;person.birthday.year;
Given the following strucure 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};
When defining a class, the class should be composed of the kind of values a variable of the class can contain, and
member functions for that class
Which of the following is the correct function definition header for the getAge function which is a member of the Person class?
int Person::getAge()
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 «_space;age «_space;weight «_space;id;
Why do you want to usually make data members private in a class?
ensure data integrity
provide data abstraction.
provide information hiding.
A member function of a class should be made private
if it will only be used by other members of the class
A member function that allow the user of the class to change the value in a data member is known as
a mutator function
A Member function that allows the user of the class to see the value in a data member is known as
an accessor function
If you design a class with private data members, and do not provide mutators and accessors, then
The data can not be changed or viewed by anyone.
A class member function that automatically initializes the data members of a class is called
a constructor