Question 1. What is the output of the following C++ code? int alpha[5] = {2, 4,
ID: 3558798 • Letter: Q
Question
Question 1. What is the output of the following C++ code?
int alpha[5] = {2, 4, 6, 8, 10};
int j;
for (j = 4; j >= 0; j--)
cout << "alpha[" << j<< "] = " << alpha[j] << endl;
2 4 6 8 10
4 3 2 1 0
8 6 4 2 0
10 8 6 4 2
Question 2. Assume you have the following declaration.
char nameList[100];
Which of the following ranges is valid for the index of the array nameList?
0 through 99
0 through 100
1 through 100
1 through 101
Question 3. A class and its members can be described graphically by using _____.
Unified Modeling Language (UML) notation
a flowchart
Unified Abstract Language (UAL) notation
Unified Encapsulation Language (UEL) notation
Question 4. If a member of a class is ____, you cannot access it outside the class.
public
automatic
private
static
Question 5. Consider the following class definition.
class rectangleType
{
public:
void setLengthWidth(double x, double y);
//Postcondition: length = x; width = y;
void print() const;
//Output length and width;
double area();
//Calculate and return the area of the rectangle;
double perimeter();
//Calculate and return the parameter;
rectangleType();
//Postcondition: length = 0; width = 0;
rectangleType(double x, double y);
//Postcondition: length = x; width = y;
private:
double length;
double width;
};
And consider this object declaration.
rectangleType bigRect(14,10);
Which of the following statements is correct?
bigRect.setLengthWidth();
bigRect.setLengthWidth(3.0, 2.0);
bigRect.length = 2.0;
bigRect.length = bigRect.width;
Question 6. In C++, the ____ is an operator called the member access operator.
.
,
::
#
Question 7. A ____ sign in front of a member name on the UML diagram indicates that the member is a private member.
+
-
#
$
Question 8. Suppose you have the following UML class diagram of a class.
----------------------------------------------------------------------------------------------
clockType
-----------------------------------------------------------------------------------------------
-hours: int
-minutes: int
-seconds: int
-----------------------------------------------------------------------------------------------
-incrementHours{} : void
+equalTime{} : bool
+printTime{} : void
+clockType{}
+-clockType{}
+getTime{} : int
+setTime(in setHours : int, in setMinutes : int, in setSeconds : int) : bool
------------------------------------------------------------------------------------------------
According to the UML class diagram, which function is public and doesn't return anything?
incrementHours
equalTime
printTime
setTime
Question 9. Consider the following declaration.
class myClass
{
public:
void print();
private:
int x;
};
myClass myObject;
Which statement is legal?
myObject.print = 10;
myClass.print = 10;
myObject.print();
myClass.print();
Question 10. When composition is used, _____.
the host object is constructed first, and then the member objects are placed into it
member objects are constructed first, in the order they appear in the host constructor's initializer list
member objects are constructed first, in the order they are declared in their own class
member objects are constructed last, in the order they are declared in the host's class
Question 11. Composition and inheritance are two fundamental ways of relating _____.
classes
objects
class function members
class data members
Question 12. Aggregation is also sometimes called _____.
inheritance
instantiation
composition
encapsulation
Question 13. A(n) _____ relationship represents composition.
"has a"
"is a"
"part of"
logical
Question 14. If the derived class does not override a public member function of the base class, you may specify a call to that public member function that has parameters by _____.
using the name of the function and no parameter list
using only the name of the function
using the name of the function and the appropriate parameter list
Public member functions cannot be accessed in a derived class.
Question 15. The new classes that we create from the existing classes are called ____ classes.
sibling
base
derived
parent
Question 16. Which of the following statements does not correctly describe inheritance?
Going from a general description to a more specific description
Describes an "is a" relationship
Describes a "has a" relationship
Allows for reusable code
Question 2. Assume you have the following declaration.
char nameList[100];
Which of the following ranges is valid for the index of the array nameList?
0 through 99
0 through 100
1 through 100
1 through 101
Explanation / Answer
1. D) 10 8 6 4 2
2. A) 0 through 99
3. C) Unified Abstract Language (UAL) notation
4. C) private
5. B) bigRect.setLengthWidth(3.0, 2.0);
6. A) "."
7. B) -
8. C) printTime
9. D) myClass.print();
10. D) member objects are constructed last, in the order they are declared in the host's class
11. A) classes
12. C) composition
13. A) "has a"
14. C) using the name of the function and the appropriate parameter list
15. C) derived
16. A) Going from a general description to a more specific description
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.