• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/168

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

168 Cards in this Set

  • Front
  • Back
If p1 is an integer pointer variable, with the value of 1000, p1++ changes P1 to point to the memory location 1001. T/F?
ANSWER: FALSE
When you return a dynamic array to the freestore, you must include the number of elements in the array.
T/F?
ANSWER: FALSE
You can assign an array to a pointer variable. T/F?
ANSWER: TRUE
The size of a dynamic arrays must be declared at compile time. T/F?
ANSWER: FALSE
int *p1; declares a static variable. T/F?
ANSWER: FALSE
Dynamically created variables have no name. T/F?
ANSWER: TRUE
If p1 and p2 are both pointers that point to integers in memory, the condition p1 == p2 will be true if the values that are in those memory locations are the same. T/F?
ANSWER: FALSE
Even though pointers point to addresses which are integers, you can not assign an integer to a pointer variable. T/F?
ANSWER: TRUE
In the following statement, all the variables are pointers, int* p1, p2; T/F?
ANSWER: FALSE
A pointer can be stored in an integer variable. T/F?
ANSWER: FALSE
A ______ is the memory address of a variable
pointer
Declare a pointer variable named ptr to an integer.
int *ptr;
In the statement cout << *p1; the * is called the ________
dereferencing operator
The & operator is called the ____________
address of operator
Write the code that assigns to p1 and the pointer to a dynamically created integer.
p1 = new int;
Dynamic variables are created at ________
Run Time
Dynamic variables are created from the
freestore or heap
Write the code to return the dynamic memory pointed to by p1 to the freestore.
delete p1;
The size of a dynamic array is defined at
run-time
Write the code to declare a dynamic array of strings that has as many elements as the variable arraySize.
p1 = new string[arraySize];
Write the function declaration for a destructor for a class named myClass
~myClass();
Write the function declaration for a copy constructor for a class named myClass
myClass(const myClass& object_name);
Write the function declaration for an assignment operator for a class named myClass
void operator=(const myClass& objectname);

OR

myclass& operator =(const myClass& object_name);
Both the copy constructor and the assignment operator should make _________
A complete and independent copy of the dynamic variables.
The assignment operator must be a ______ of the class.
(MEMBER) of the class
Which of the following correctly declare 3 integer pointers?

a. int* p1, p2, p3;
b. int *p1, p2, p3;
c. int *p1, *p2, *p3;
d. all of the above.
int *p1, *p2, *p3;
Which of the following assigns to p1 the pointer to the address of value?

a. *p1=&value;
b. p1=value;
c. p1=&value;
d. &p1 = *value;
p1=&value;
What is the output of the following code fragment?
int v1=2, v2=-1, *p1, *p2;
p1 = & v1;
p2= & v2;
p2=1;
cout<<*p2<
a. 2
b. -1
c. -2
d. 1
2
Which of the following statements correctly prints out the value that is in the memory address that the pointer p1 is pointing to?

a. cout << &p1;
b. cout << p1;
c. cout << int* p1;
d. cout << *p1;
cout <<*p1;
Given that p1 is a pointer variable of the string class, which of the following are legal statements?

a. p1 = new int;
b. cout << *p1;
c. p1 = new char[10];
d. *p1 = new string;
e. B and D
cout <<*p1;
What is the output of the following code fragment?
float *p1;
p1 = newfloat(3);
cout<<*p1;

a. 3.0
b. unknown, the address p1 points to is not initialized
c. unknown, the code is illegal, p1 points to a dynamic array
d. 0.0
3.0
What is the output of the following code?
int *p1, *p2;
p1 = new int;
p2 = new int;
*p1 = 11;
*p2 = 0;
p2=p1;
cout <<*p1 <<" "<<*p2<
a. 11 0
b. 0 11
c. 11 11
d. 0 0
11 11
What is wrong with the following code fragment?
int *p1, *p2;
p1 = new int;
p2 = new int;
*p1=11;
*p2=0;
p2=p1;
cout<<*p1<<" "<<*p2delete p2;

a. nothing
b. p1 and p2 both have the same value, so the delete p2 will cause an error
c. You have a memory leak.
d. B and C
B and C...
p1 and p2 both have the same value so the delete p2 will cause an error. You have a memory leak.
Which of the following correctly declares a user-defined data type that defines a pointer to a float?

a. float* floatPtr ;
b. typedef float* floatPtr;
c. typedef floatPtr *float;
d. typedef floatPtr* float
typedef float* floatPtr;
Given that a typedef for IntPtr defines a pointer to an integer, what would be the correct declaration for a function that expects a reference to an integer pointer?

a. void f1 (IntPtr& ptr);
b. void f1 (IntPtr&* ptr);
c. void f1 (IntPtr*& ptr);
d. All of the above
void f1(IntPtr& ptr);
Which of the following correctly declares a dynamic array of strings?

a. p1 = new string(13);
b. p1 = new string[];
c. p1 = new string[13];
d. p1 = new stringArray(13);
p1 = new string[13];
Given that p1 is an integer pointer variable, and a1 is an integer array, which of the following statements are not legal code?

a. p1= a1;
b. cout << p1[0];
c. cin >> p1[0];
d. a1 = p1;
a1 = p1;
Assuming that the pointer variable p1 is of the correct type and size is an integer with some value > 1, which of the following declarations are legal?

a. p1 = new string[size];
b. p1 = new ifstream[size];
c. p1 = new char[size*size];
d. A and B
e. A, B and C
A, B, C
p1 = new string[size];
p1 = new ifstream[size];
p1 = new char[size*size];
Which of the following statements correctly returns the memory for the dynamic array pointer to by p1 to the freestore?

a. delete [] p1;
b. delete p1[];
c. delete *p1;
d. delete p1;
delete [] p1;
If p1 is an integer pointer that is pointing to a memory location 1001, and an integer takes 4 bytes, then (p1+1) evaluates to

a. 1002
b. 1004
c. 1005
d. Unknown
1005
Given that p1 is a pointed, p1++

a. always causes a run time error
b. advances p1 by one unit of the type of variable to which p1 points
c. adds 1 to whatever p1 is pointing to
d. adds one element to the array that p1 is pointing to
Advances p1 by one unit of the type of variable to which p1 points.
If a program requires a dynamically allocate two-dimensional array, you would allocate the memory by using

a. p1 = new int*[numRows];
for(int i=0; i < numRows; i++)
p1[i] = new int[numColumns];
b. p1 = new int*[numRows][numColumns];
c. p1 = new[numRows][numColumns]int;
d. none of the above
p1 = new int*[numRows];
for(int i=0; i p1[i] = new int[numColumns];
Which of the following statements are true?

a. A dynamic array can have a base type which is a class or a struct.
b. A class or a struct may have a member which is a dynamic array.
c. A and B
d. Neither
A and B.
A dynamic array can have a base type which is a class or a struct.
A class of a struct may have a member which is a dynamic array.
When a dynamic array with a class for a base type is declared, which constructor is called?

a. the copy constructor

b. the destructor
c. the default constructor
d. an explicit constructor

the default constructor
When you have a class which has a dynamic array as one of it's members, you should also include ______ in the class.

a. a copy constructor
b. a default constructor
c. a destructor
d. the assignment operator
e. all of the above
f. none of the above
All of the above.
A copy constructor,
a default constructor,
a destructor,
the assignment operator.
A destructor for a class is called

a. explicitly from the main program
b. when the class is instantiated
c. when the object of the class goes out of scope
d. Only at the end of main
when the object of the class goes out of scope
The copy constructor for a class is called

a. when an object of the class is passed by value to a function.
b. when an object of the class is initialized by another object of the class
c. when a function returns an object of the class
d. all of the above
All of the above.
When an object of the class is passed by value to a function.
When an object of the class is initialized by another object of the class.
When a function returns an object of the class.
Which of the following are not correct?

a. The destructor of a class is not named the same as the name of the class, but preceded with a tilde

b. The destructor of a class is not called when an object of the class goes out of scope
c. The destructor of a class is not a member of the class
d. The destructor of a class is a void function e. all of the above

The destructor of a class is a void function IS NOT CORRECT.
What happens when you define a class that used dynamic memory allocation and define a destructor but no copy constructor?

a. If an object of the class is plugged in for a call-by-value parameter, when the function ends, the parameter's dynamic memory is returned to the freestore at the end of the function execution.
b. When an object that was used as an argument for a call-by-value parameter goes out of scope, it will cause a run-time error.

c. It is possible to modify the values in the argument in the function.
d. All of the above e. None of the above

All of the above.
If an object of the class is plugged in for a call-by-value parameter, when the function ends, the parameter's dynamic memory is returned to the freestore at the end of the function execution.
When an object that was used as an argument for a call-by-value parameter goes out of scope, it will cause a run-time error.
It is possible to modify the values in the argument of the function.
If obj1 and obj2 are both objects of a class that uses dynamic memory allocation, but the class does not have an assignment operator, what happens if you execute the following code?
obj1=obj2;

a. A syntax error occurs, you can not assign one object to another object without the = operator
b. A run-time error occurs, because the C++ system does not know how to do the assignment.
c. The pointer(s) to the dynamically declared memory in obj2 are copied to the corresponding pointers in obj1.
d. There is a complete and independent copy of all the dynamic memory from obj2 to obj1
The pointer(s) to the dynamically declared memory in obj2 are copied to the corresponding pointers in obj1.
If two pointer variables point to the same memory location, what happens when one of the pointers is freed?
a. The other pointer should be considered to be un-initialized
b. The other pointer still points to a valid memory address
c. If you attempt to free the other pointer a run-time error will occur.
d. All of the above
e. A and C
A and C
The other pointer should be considered to be un-initialized
If you attempt to free the other pointer a run-time error will occur.
Friend functions are members of the class. T/F?
FALSE
All operators can be overloaded. T/F?
FALSE
If you have mutators and accessors, you should not have friend functions also. T/F?
FALSE
Friend functions may directly modify or access the private data members? . T/F?
TRUE
The following is a properly declared overloaded insertion operator for myClass. ostream& operator << (ostream & out, const myClass &obj); . T/F?
TRUE
Functions that are constant member functions may call the class mutator functions. . T/F?
FALSE
Functions that are constant member functions may call constant class accessor functions. T/F?
TRUE
You cannot create new operators (such as the quote). T/F?
TRUE
Operators must be friends of the class. T/F?
FALSE
You may not change the precedence of operators by overloading them. T/F?
TRUE
If given a task being performed by a function involves more than one object, then that function should normally be a _________ function.
friend
If given a task being performed by a function involves one object, than that function should normally be a _________ function.
member
A __________ function is not a member of the class, but has access to the private members of the class.
friend
An overloaded extraction or insertion operator should return ____________
a reference to the stream
A friend function needs to be passed an object of the class. If the friend only needs to access the object, but not change its data members, then the object should be passed as a ___________
a constant reference.
An operator that expects only one parameter is called a _______ operator
unary
An operator that expects two parameters is called a __________ operator.
binary
In order to do automatic type conversion for your class, you would write ______________
overloaded functions or overloaded constructors
Putting the keyword const after the function declaration guarantees ________
That the function will not change the calling object
Putting the keyboard const in front of a pass by reference parameter guarantees _______
that the function will not modify that parameter
How many members (data and functions) does the following class have?

class Rational
{
public:
Rational ();
Rational (int number, int denom);
Rational(int whole);

int getNumerator();
int getDenominator();

friend void display(ostream& out, const Rational& value);

private:
int numerator;
int denominator;
};

a. 2
b. 6
c. 5
d. 7
e. 8
7
Who can access private data in a class?

a. members of the class
b. friends of the class
c. everyone
d. B and C
B and C
Members of the class
Friends of the class
Given the following class, which is the correct function header for the display function?
class Rational
{
public:
Rational ();
Rational (int number, int denom);
Rational(int whole);

int getNumerator();
int getDenominator();

friend void display(ostream& out, const Rational& value);

private:
int numerator;
int denominator;
};

a. friend void display(ostream& out, const Rational& value)
b. void display(ostream& out, const Rational& value)
c. void Rational::display(ostream& out, const Rational& value)
d. friend void Rational::display(ostream& out, const Rational& value)
void display(ostream& out, const Rational& value)
Operators can be overloaded as

a. friends of a class
b. members of a class
c. non-friends, non-members of a class
d. All of the above
D, all of the above
Friends of a class
Members of a class
Non-friends, non members of a class
If we have a full selection of accessor and mutator functions, why would we have friend functions?

a. You should not have them
b. More efficient access to the private data members.
c. The friend function must call the accessor or mutator functions anyway.
d. none of the above
More efficient access to the private data members
Since accessor functions in a class do not modify or mutate the data members of the object, the function should have the ________ modifier.

a. reference
b. friend
c. const
d. private
const
Why should you generally pass an object of the class to a friend function as a reference parameter?

a. If the friend function changes the values of the data member(s).
b. If the friend function will not change the values of the data member(s).
c. It is more efficient to pass the object by reference.
d. A and B
e. A and C
A and C
If the friend function changes the values of a the data member(s)
It is more efficient to pass the object by reference.
If c is a character variable that contains a digit, what does the following function return?
int digit_to_int(char c)
{
return (int(c)- int('0'));
}

a. The ASCII value of c
b. The character value of c
c. The integer equivalent of the digit stored in c
d. none of the above
The integer equivalent of the digit stored in c
What is wrong with the following member function definition given the class below?

class Rational
{
public:
Rational ();
Rational (int number, int denom);
Rational(int whole);

int getNumerator();
int getDenominator();

friend void display(ostream& out, const Rational& value);

private:
int numerator;
int denominator;
};

int Rational::getNumerator() const
{
numerator = 0;
return numerator;
}

a. You can not set the numerator to zero
b. The function may not modify numerator, but it can modify denominator
c. The function may not modify any of the private data members
d. nothing
e. A and B
f. A and C
A and C
You cannot set the numerator to zero.
The function may not modify any of the private data members.
Given the following class, what is syntactically wrong with the implementation of the display function?
class Rational
{
public:
Rational ();
Rational (int number, int denom);
Rational(int whole);

int getNumerator();
int getDenominator();

friend void display(ostream& out, const Rational& value);

private:
int numerator;
int denominator;
};

void display(ostream& out, const Rational&value)
{
out << value.getNumerator() << "/" << value.getDenominator();
}

a. nothing
b. value must be not be pass by reference
c. The get functions are not const functions
d. out should be pass by value
The get functions are not const functions.
To overload functions with symbolic names (like +/ <<),
you must use the keyword ______ before the symbolic name
a. const
b. operator
c. reference
d. void

operator

In the following code fragment, which is the calling object for the lass-than operator?
string s1, s2;
if ( s1 < s2)

a. s1
b. s2
c. <
d. none
s1
Given the following class declaration, class Rational
{
public:
Rational ();
Rational (int number, int denom);
Rational(int whole);

int getNumerator();
int getDenominator();

friend void display(ostream& out, const Rational& value);
friend bool operator(const Rational& left, const Rational& right);

private:
int numerator;
int denominator;
};

What must we add to the class in order for the following code to compile?

Rational myRational(2,3);
if (3 < myRational)
a. We need another < operator that expects an integer as the second parameter.
b. We need another < operator that expects an integer as the first parameter.
c. We need a constructor that expects a ration number
d. We need a constructor that expects an integer
e. A or D
f. B or D
B or D
We need another < operator that expects an integer as the first parameter.
We need a constructor that expects an integer.
When overloading an operator, which of the following is true.

a. One of the arguments must be an object of the class
b. The operator can be a friend or a member of the class.
c. The operator does not have to be a friend or a member of the class
d. All of the above
e. None of the above
All of the above.
One of the arguments must be an object of the class.
The operator can be a friend or a member of the class.
The operator does not have to be a friend or a member of the class.
What is wrong with the following overloaded extraction operator declaration?
istream& operator >> (istream& in, const myClass & object);

a. Object should not be a pass by reference parameter
b. Object should not be a const parameter
c. You can not put the & on the return type
d. nothing
Object should not be a const parameter
Which of the following would be an appropriate function declaration to add two rational numbers?

a. void friend operator+( const Rational &left, const Rational &right);
b. void operatator+( const Rational &left, const Rational &right);
c. friend Rational operator+( const Rational &left, const Rational &right);
d. Rational operator+( const Rational &left, const Rational &right);
Rational operator +(const Rational &left, const Rational &Right);
How many parameters are there in a binary operator implemented as a friend?

a. 0
b. 1
c. 2
d. as many as you need
2
How many parameters are there in a unary operator implemented as a friend?

a. 0
b. 1
c. 2
d. as many as you need
1
Given the following function declaration,
friend void display(const myClass& object);
which is the correct header for the definition of the function?

a. void myClass::display(const myClass& object)
b. void display(const myClass& object)
c. friend void display(const myClass& object);
d. friend void display(const myClass& object)
void display(const myClass& object)
Which of the following function declarations would be correct to overload the multiply operator for the Rational numbers class?

a. friend Rational operator times(const Rational &left, const Rational &right);
b. Rational operator times(const Rational &left, const Rational &right);
c. friend Rational operator *(const Rational &left, const Rational &right);
d. Rational operator *(const Rational &left, const Rational &right);
friend Rational operator *(const Rational &left, const Rational &right);
Why are the extraction and insertion operators always implemented as friends of the class rather than as members of the class?

a. Because the first parameter must be the stream object.
b. They don't, they could be members
c. Because they return a reference
d. Because the stream is passed by reference.
Because the first parameter must be the stream object.
If you want to be able to compile the following code,
Rational r1;
int x;

cout << r1+ x << endl;

Which overloaded operator(s) do you need?

a. friend Rational operator+( const Rational& left, int right);
b. friend void operator+ (const Rational& left, int right);
c. friend ostream operator << (ostream& out, const Rational& object);
d. friend ostream& operator << (ostream& out, const Rational& object);
e. A and C
f. A and D
A and D
friend Rational operator+(const Rational& left, int right);
friend ostream& operator <<(ostream& out, const Rational& object);
What member functions do you need to allow the compiler to perform automatic type conversions from a type difference than the class to the class?

a. Overloaded constructors
b. Converters
c. This can not be done
d. This already happens automatically
Overloaded constructors
In an overloaded insertion or extraction operator, which object should be the first parameter, the stream or the object of the class?

a. the stream
b. the object
c. it doesn't matter
d. none of the above
The stream
Given the following class and array declaration, how would you print out the age of the 10th person in the array?
class personClass
{
public:
void setAge(int newAge);
void setGender( char newGender);
void setSalary(float newSalary);

int getAge();
char getGender();
float getSalary();
private:
int age;
char gender;
float salary;
};

personClass people[100];

a. cout << people[10];
b. cout << people[9];
c. cout << people[9].age;
d. cout << people[9].getAge();
cout << people[9].getAge();
Which of the following operators cannot be overloaded?

a. =
b. ==
c. .
d. []
.
Which of the following statements are true?
a. Array elements may be user-defined types (structs or classes)
b. If a function is expecting a variable of the base type of the array, then you can pass an element of the array to the function.
c. All of the above.
d. None of the above.
All of the above.
Array elements may be user-defined types (structs or classes)
If a function is expecting a variable of the base type of the array, then you can pass an element of the array to the function.
Which of the following statements are true?
a. A dynamic array can have a base type which is a class or a struct.
b. A class or a struct may have a member which is a dynamic array.
c. A and B
d. Neither
A and B
A dynamic array can have a base type which is a class or a struct.
A class or a struct may have a member which is a dynamic array.
When a dynamic array with a class for a base type is declared, which constructor is called?
a. the copy constructor
b. the destructor
c. the default constructor
d. an explicit constructor
the default constructor
When you have a class which has a dynamic array as one of it's members, you should also include _____________ in the class.
a. a copy constructor
b. a default constructor
c. a destructor
d. the assignment operator
e. all of the above
f. none of the above
All of the above
a copy constructor
a default constructor
a destructor
the assignment operator
The destructor for a class is called
a. explicitly from the main program
b. when the class is instantiated
c. when the object of the class goes out of scope
d. Only at the end of main
When the object of the class goes out of scope
The copy constructor for a class is called
a. when an object of the class is passed by value to a function.
b. when an object of the class is initialized by another object of the class
c. when a function returns an object of the class
d. all of the above
All of the above
when an object of the class is passed by value to a function.
when an object of the class is initialized by another object of the class
when a function returns an object of the class
Which of the following are not correct?
a. The destructor of a class is not named the same as the name of the class, but preceded with a tilde
b. The destructor of a class is not called when an object of the class goes out of scope
c. The destructor of a class is not a member of the class
d. The destructor of a class is a void function
e. all of the above
The destructor of a class is a void function
What happens when you define a class that used dynamic memory allocation and define a destructor but no copy constructor?
a. If an object of the class is plugged in for a call-by-value parameter, when the function ends, the parameter's dynamic memory is returned to the freestore at the end of the function execution.
b. When an object that was used as an argument for a call-by-value parameter goes out of scope, it will cause a run-time error.
c. It is possible to modify the values in the argument in the function.
d. All of the above
e. None of the above
All of the above.
-If an object of the class is plugged in for a call-by-value parameter, when the function ends, the parameter's dynamic memory is returned to the freestore at the end of the function execution.
-When an object that was used as an argument for a call-by-value parameter goes out of scope, it will cause a run-time error.
-It is possible to modify the values in the argument in the function.
If obj1 and obj2 are both objects of a class that uses dynamic memory allocation, but the class does not have an assignment operator, what happens if you execute the following code?
obj1=obj2;
a. A syntax error occurs, you can not assign one object to another object without the = operator
b. A run-time error occurs, because the C++ system does not know how to do the assignment.
c. The pointer(s) to the dynamically declared memory in obj2 are copied to the corresponding pointers in obj1.
d. There is a complete and independent copy of all the dynamic memory from obj2 to obj1
The pointer(s) to the dynamically declared memory in obj2 are copied to the corresponding pointers in obj1
Which of the following are valid declarations for an assignment operator for a class named myClass?
a. void friend operator = (myClass& left, const myClass& source);
b. void operator = (myClass& left, const myClass& source);
c. void friend operator = (const myClass& source);
d. void operator = (const myClass& source);
void operator = (const myClass& source);
A struct variable is declared differently from a predefined type such as int. T/F?
ANSWER: FALSE
Two different structure definitions may have the same member names. T/F?
ANSWER: TRUE
A structure can only be passed to a function as a call-by-value parameter T/F?
ANSWER: FALSE
A function may return a structure T/F?
ANSWER: TRUE
Different class may not have member functions with the same name. T/F?
ANSWER: FALSE
Class data members are almost always public. T/F?
ANSWER: FALSE
A class member function may be private. T/F?
ANSWER: TRUE
It is possible to have multiple private labels in a class definition. T/F?
ANSWER: TRUE
The assignment operator may not be used with objects of a class. T/F?
ANSWER: FALSE
All constructors for a class must be private. T/F?
ANSWER: FALSE
The keyword_____ defines a structure type definition.
struct
A structure definition ends with the closing brace and a _______.
semicolon
A structure variable is a collection of smaller values called _____________values.
member
When a structure contains another structure variable as one of its members, it is known as a ___________________
hierarchical structure
When several items (variables or variables and functions) are grouped together into a single package, that is known as _______________.
(data) encapsulation
The double colon (::) is known as the _________ operator
scope resolution operator
Who can access private members in class?
Only other members of the class
A member function that allows the user of the class to find out the value of a private data type is called a _____________.
accessor function
A member function that allows the user of the class to change the value of a private data type is called a __________
mutator function
If you have a class with a member function called display(ostream& out), that will send the values in the class to the parameter stream, and you need to call that function from within another member function, how would you call it to print the data to the screen?
display(cout);
What can a constructor return?
nothing
The name of a constructor is
the name of the class
The constructor of a class that does not have any parameters is called a _______ constructor
default
In the following class constructor definition, the part of the header starting with a single colon is called the ____________. BankAccount::BankAcount(): balance(), interest(0.0)
initialization section
A class in which modifications to the implementation appear to be invisible to the user of the class is known as ________
An abstract data type (ADT)
A member function that get called automatically when an object of the class is declared is called a __________
constructor
In a structure definition, the identifiers declared in the braces are called

a. classes
b. structs
c. member names
d. variables
member names
You specify an individual member of a struct by using

a. the assignment operator
b. an ampersand
c. an underscore
d. The dot operator
the dot operator
To assign values to a structure variable, you use the

a. equals operator
b. assignment operator
c. extraction operator
d. less than operator
assignment operator
What is wrong with the following structure definition?
struct myStruct
{
int size;
float weight;
}

a. Nothing
b. Can not have mixed data types in a structure
c. missing semicolon
d. Braces are not needed.
missing semicolon
Given the following structure definitions, what is the correct way to print the person's birth year?
struct DataType
{
int day;
int month;
int year;
}
struct PersonType
{
int age;
float weight;
DateType birthday;
}

PersonType person;

a. cout << person.birthday.year;
b. cout << year;
c. cout << birthday.year;
d. cout << peson.year;
cout << person.birthday.year;
Given the following structure 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);
b. DateType today = (1,1,2000);
c. DateType today = {1,1,2000);
d. DateType today = {1,1,2000,0);
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

a. member functions for that class
b. the keyword private
c. other class definitions
d. nothing else
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?

a. int getAge();
b. int getAge()
c. int Person:getAge()
d. int Person::getAge()
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 outputPerson(ostream& out)
{
//what goes here?
}

a. out << person.age << person.weight << person.id;
b. out << person;
c. out << age << weight << id;
d. outputPerson(person);
out << age<< weight << id;
Why do you want to usually make data members private in class?

a. so that no one can use the class.
b. ensure data integrity
c. provide data abstraction.
d. provide information hiding.
e. B and D
f. B, C and D
B, C, and D.
Ensure data integrity
Provide data abstraction
Provide information hiding
A member function of a class should be made private

a. always
b. only if it will never be used
c. if it will only be used by other members of the class
d. never, it is illegal to make a member function private.
If it will only be used by other members of the class
A member function that allows the user of the class to change the value in data member is known as

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

a. a mutator function
b. a mutation
c. a manipulator function
d. an accessor function
An accessor function
If you design a class with private data members, and do not provide mutators and accessors, then

a. The private data members can still be accessed from outside the class by using the & operator
b. The data can not be changed or viewed by anyone.
c. None of the above
d. A and B
A and B
The class cannot be used
The data cannot be changed or viewed by anyone.
A class member function that automatically initializes the data members of a class is called

a. the init function
b. an operator
c. a constructor
d. a cast
A constructor
If you have a class named myPersonClass, which of the following correctly declares a constructor in the class definition?

a. myPersonClass::myPersonClass();
b. myPersonClass();
c. init();
d. cast();
myPersonClass();
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(float myRate, float myBalance);

b. myAccount = CDAccount {myRate, myBalance};


c. myAccount = CDAccount[myRate, myBalance];


d. myAccount = CDAccount(myRate, myBalance);

myAccount = CDAccount(myRate, myBalance);
Given the 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;
};

a. nothing
b. a default constructor
c. accessor functions
d. mutator functions
a default constructor
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;
b. ItemClass myItem(1, 0.0);
c. ItemClass myItem;
d. ItemClass myItem();
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

a. an abstract definition type
b. an available data type
c. an abstract data type
d. a primitive data type
an abstract data type
Which part of the ADT tells the programmer using it how to use it?

a. the implementation
b. the interface
c. the abstractness
d. the scope resolution
the interface
If you are designing a class for an ADT, you can tell if the class is an ADT if

a. when you change the implementation of the class, none of the rest of the program needs to change.
b. when you change the interface of the class, nothing else needs to change.
c. you change the privte part and the rest of the program using the ADT does not compile.
d. everything must be changed.
when you change the implementation of the class, none of the rest of the program needs to change.
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

a. interface
b. implementation
c. testing and debugging
d. information hiding
Information Hiding
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;
};

a. int getAge(int newAge);
b. Wine();
c. void setAge();
d. void setAge(int newAge);
void setAge(int newAge);
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;
};

a. int getAge(int newAge);
b. Wine();
c. Wine(int age);
d. Wine(int newAge, float newCost);
Wine(int newAge, float newCost);
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;
};

a. cout << bottle;
b. cout << Wine.age, Wine.cost;
c. cout << bottle.getAge() << bottle.getCost();
d. cout << bottle.getAge << bottle.getCost;
e. cout << bottle.age << bottle.cost;
cout << bottle.getAge() << bottle.getCost();
Data members or member functions of a class that are declared to be private may

a. only be accessed by the main program
b. only be accessed by members of the class
c. not be accessed by the class
d. are considered to be global variables
only be accessed by members of the class
Member functions of a class

a. may not be in the private section
b. must be in the private section
c. may be in either section
d. can not be called in the main program
May be in either section
In a struct, all members are _______ by default

a. public
b. private
c. global
d. all of the above
public
In a class, all members are _________ by default

a. public
b. private
c. global
d. all of the above
private
A structure can only be passed to a function as a call-by-value parameter.
FALSE
If class A is derived from class B, then B is a _____ of A.
parent
Which of the following function declarations will correctly pass an output stream to the function?
a. void display( ofstream& out);
b. void display( ostream out);
c. void display( ostream& out);
d. void display( ofstream out);
e. A and C
f. B and D
A and C
void display( ofstream& out);
void display( ostream& out);
A derived class has access to

a. the private functions and variables of its ancestor classes
b. the public functions and variables of its ancestor classes
c. only the functions and variables defined it its class
d. none of the above
the public functions and variables of its ancestor classes
Which of the following function declarations will accept either cout or a file stream object as its argument?
a. void output( fstream &outFile);
b. void output( ofstream &outFile);
c. void output( ostream &outFile);
d. void output( iostream &outFile);
void output( ostream &outFile);