CS2 EXAM 1 QUESTIONS AND
ANSWERS WITH COMPLETE
SOLUTIONS 100% CORRECT!!!
Consider the UML class diagram shown in the accompanying figure. Which of the
following is the name of the class?
clockType
-hr: int
-min: int
-sec-: int
+setTime(int, int, int): void
+getTime(int&, int&, int&) const : void
+printTime() const: void
+incrementSeconds(): int
+incrementMinutes(): int
+incrementHours(): int
+equalTime(const clockType&) const: bool -ANSWER ✔✔clockType
Given the declaration
class myClass
{
public:
,void print(); //Output the value of x;
MyClass();
private:
int x;
};
myClass myObject;
The following statement is legal.
myObject.x = 10; -ANSWER ✔✔False
The public members of a class must be declared before the private members. -
ANSWER ✔✔False
If a function of a class is static, it is declared in the class definition using the
keyword static in its ____. -ANSWER ✔✔heading
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;
};
Consider the accompanying class definition, and the declaration:
rectangleType bigRect;
Which of the following statements is correct? -ANSWER ✔✔bigRect.print();
class secretType
ANSWERS WITH COMPLETE
SOLUTIONS 100% CORRECT!!!
Consider the UML class diagram shown in the accompanying figure. Which of the
following is the name of the class?
clockType
-hr: int
-min: int
-sec-: int
+setTime(int, int, int): void
+getTime(int&, int&, int&) const : void
+printTime() const: void
+incrementSeconds(): int
+incrementMinutes(): int
+incrementHours(): int
+equalTime(const clockType&) const: bool -ANSWER ✔✔clockType
Given the declaration
class myClass
{
public:
,void print(); //Output the value of x;
MyClass();
private:
int x;
};
myClass myObject;
The following statement is legal.
myObject.x = 10; -ANSWER ✔✔False
The public members of a class must be declared before the private members. -
ANSWER ✔✔False
If a function of a class is static, it is declared in the class definition using the
keyword static in its ____. -ANSWER ✔✔heading
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;
};
Consider the accompanying class definition, and the declaration:
rectangleType bigRect;
Which of the following statements is correct? -ANSWER ✔✔bigRect.print();
class secretType