1) Assume you have the following declaration. double salesData[1000]; Which of t
ID: 3551098 • Letter: 1
Question
1) Assume you have the following declaration.
double salesData[1000];
Which of the following ranges is valid for the index of the array salesData? (4 points)
(A) 0 through 999 (B) 0 through 1000 (C) 1 through 1001 (D) 1 through 1000
Answer ____
2) Consider the following declaration.
class myClass {
public:
void print();
int y;
private:
int x;
};
myClass myObject;
Which statement is legal? (4 points)
(A) myObject.x = 10 (B) myClass.x = 10 (C) myObject.y = 10 (D) myClass.y = 10
Answer ____
3) 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? (Points : 4)
(A) bigRect.setLengthWidth()
(B) bigRect.setLengthWidth(3.0, 2.0)
(C) bigRect.length = 2.0
(D) bigRect.length = bigRect.width
Answer _____
4) What will be the output of the following code snippet (4 points)?
int *list = new int[5];
int *ptr;
for(i = 0; i < 5; i++)
list[i] = i+1;
ptr = list;
delete [] list;
cout << *ptr;
(A) 1
(B) address of list
(C) address of ptr
(D) Unpredicted--ptr references memory, which no longer belongs to the program
Answer ____
5) What term is used to describe the condition where dynamically allocated memory is not formally returned using the delete operator and the operating system does not reclaim the allocated memory area? (4 points)
(A) Stack leak
(B) Heap leak
(C) Garbage collection
(D) Memory leak
Answer ____
6) Which term is a correct definition of compile time binding? (4 points)
(A) Independent binding
(B) Dependent binding
(C) Static binding
(D) Dynamic binding
Answer ____
7) If a class has a pure virtual function, then _____. (4 points)
(A) that class is an abstract class
(B) it is a derived class with multiple base classes
(C) any class derived from it cannot redefine or override that function
(D) it cannot be inherited.
Answer ____
1) Assume you have the following declaration.
double salesData[1000];
Which of the following ranges is valid for the index of the array salesData? (4 points)
(A) 0 through 999 (B) 0 through 1000 (C) 1 through 1001 (D) 1 through 1000
Answer ____
2) Consider the following declaration.
class myClass {
public:
void print();
int y;
private:
int x;
};
myClass myObject;
Which statement is legal? (4 points)
(A) myObject.x = 10 (B) myClass.x = 10 (C) myObject.y = 10 (D) myClass.y = 10
Explanation / Answer
1. (A)Valid indices are 0 through 999. In C++ all array indexing starts from 0.
2. (C)myObject.y = 10 is legal. y is a public member and hence can be accessed from outside the class using member operator(.) .Whereas x being private cann only be accessed through a member function.
3. (B) bigRect.setLengthWidth(3.0, 2.0) .Here length and width are private members and hence they cannot be accessed using the member operator(.) with an object. They can be accessed by a method of the same class.
4. (A) 1 will be the output. This is because on deletion on the refrence is removed. The data is not deleted. Ptr still points to the same location(ie- 1st array element).
5. (D) Memory Leak
6. (D) Dynamic Binding
7. (A) that class is an abstract class. The pure virtual function needs to be overridden in the derived classes.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.