quiz 3 Flashcards

1
Q

In a structure definition, the identifiers declared in the braces are called

A

member names

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

You specify an individual member of a struct by using

A

The dot operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

To assign values to a structure variable, you use the

A

assignment operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is wrong with the following structure definition?
struct MyStruct
{
int size;
float weight;
}

A

missing semicolon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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;

A

cout &laquo_space;person.birthday.year;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Given the following strucure definition, what is the correct way to initialize a variable called today?
struct DateType
{
int day;
int month;
int year;
};

A

DateType today = {1,1,2000};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When defining a class, the class should be composed of the kind of values a variable of the class can contain, and

A

member functions for that class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following is the correct function definition header for the getAge function which is a member of the Person class?

A

int Person::getAge()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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?
}

A

out &laquo_space;age &laquo_space;weight &laquo_space;id;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why do you want to usually make data members private in a class?

A

ensure data integrity
provide data abstraction.
provide information hiding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

A member function of a class should be made private

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A member function that allow the user of the class to change the value in a data member is known as

A

a mutator function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A Member function that allows the user of the class to see the value in a data member is known as

A

an accessor function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If you design a class with private data members, and do not provide mutators and accessors, then

A

The data can not be changed or viewed by anyone.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

A class member function that automatically initializes the data members of a class is called

A

a constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If you have a class named myPersonClass, which of the following correctly declare a constructor in the class definition?

A

myPersonClass();

17
Q

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;

A

myAccount = CDAccount(myRate, myBalance);

18
Q

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;
};

A

a default constructor

19
Q

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;
};

A

ItemClass myItem;

20
Q

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

A

an abstract data type