CVJI 82.doc

CLICK HERE TO DOWNLOAD THIS ANSWER INSTANTLY

 

1. What is the output of the following code snippet?
int value = 10;
int *
iptr = &value;
*iptr = 5;
Cout << *iptr << “ “ <<
value;
5 5
10 10
5 10
10 5
2. What is the output of the following code snippet?
int *p;
int *q;
p =
new int;
*p = 43;
q = p;
*q = 52;
p = new int;
*p = 78;
q =
new int;
*q = *p;
cout << *p << ” ” << *q << end1
4352
5278
7878
7852

3. (TCO 4) What is wrong with the following switch statement?
switch(x)
{
case 0:
cout << x;
case 2:
cout << 2 / x;
break;
default:
cout << “error”;
break;
}
The value of x could be something other than 1 or 2.
There is no break statement for case 1.
There is no semicolon after the closing bracket.
All of the above
4. (TCO 4) A variable declared before and outside all function blocks
is visible only in main.
is visible to all functions.
is visible to all functions except main.
is not visible to any functions.
5. (TCO 4) C++ selection statements include
(Points : 7)
for, while, do-while.
cout and cin.
if, if-else, if-else if, switch.
#include and using namespace std;.
6. (TCO 4) Which operation in the following expression will be performed first?
c = a++ / b + 5;
a
a/b
assignment to c
b + 5
7. (TCO 4) How many elements does the following array contain?
double data [100] [500];
500
100
600
50,000
8. (TCO 4) The code below computes the length of a C-style string. What should the value of FLAG be?
char name[20]= “Lancilot”;
int length=0;
while(name[length] != FLAG)
{
length = length+1;
}
cout << length << endl;
‘\0’
20
NULL
0
9. (TCO 4) Given the following code to fill an array,
int;
int data[100];
for(int i = 0; i <= X; i++)
data = i;
what should the value of X be?
100
101
99
i
10. (TCO 4) Given the following code fragment, what is the data type of thisStudent?
struct student
{
string name;
double gpa;
};
student thisStudent;
string
const pointer to student
student
double
11. (TCO 4) Which of the following is an invalid declaration to overload the following function?
double foo(int);
double foo(double);
int foo(int);
double foo(double *):
double foo(int *);
12. (TCO 4) Which of the following statements call the following function correctly?
int MultiplyValues (int, int);
int a = MultiplyValues (int x, int y);
int a = MultiplyValues (10, 20);
double d = MultiplyValues (int 10, int 20);
All of the above
13. (TCO 4) What is the output of the following code?
void func(int x[ ])
{
x[0] = x[0] * 3;
x[1[ = x[1] * 3;
x[2] = x[2] * 3;
}
void main ()
{
int x[ ] = {1, 2, 3};
func(x);
cout << x[0] << “ “ << x[1] << “ “ << x[2] << endl;
}
1 2 3
3 4 5
3 6 9
3 3 3
14. (TCO 4) Which of the following function definitions uses pass-by-values?
int myFunc( int * x, int * y );
int myFunc( int x, int y ) ;
int myFunc( int & x, int & y ) ;
int myFunc( int @ value1, int @ value2 ) ;
15. (TCO 4) Which of the following is called automatically each time an object is created?
Compiler
Builder
Constructor
Destructor
16. (TCO 4) Creating one class from another in a parent/child hierarchy is an example of
encapsulation.
polymorphism.
inheritance.
abstraction.
17. (TCO 4) A Distance class has two private members, ‘feet’, of type int, and ‘inches’, of type double. Which prototype correctly declares the copy constructor for such class?
Distance Distance(const Distance &);
Distance(const Distance &);
int Distance(int, double);
Distance(feet, inches);
18. (TCO 4) Composition is typically an example of
a “has a” relationship.
an “is a” relationship.
a “uses a” relationship.
a “is used” relationship.
19. (TCO 4) What is the name of a member function of a class that only accesses the value(s) of member variable(s) and does not modify the value(s)?
Set
Private
Member
Accessor
20. (TCO 4) A derived class is typically an example of
a “has a” relationship.
an “is a” relationship.
a “uses a” relationship.
a “is used” relationship.
21. (TCO 4) When writing a class, the compiler automatically creates some support functions for the class. What are some of these functions?
Assignment operator function
Copy constructo
Assignment operator and copy constructor
None of the above
22. (TCO 4) Given the definition of
some class called Employee, which of the following correctly dynamically
allocates an array of 20 Employee objects?
Employee * myData = new Employee[20];
Employee myData[20] = new Employee[20];
Employee = myData[20];
Employee array = new Employee[20];