1). Consider the following program:
#include <iostream>
#include <string>
using namespace std;
int main () 
{
 string str = "This*is^a.45min test.";
 int i;
 for (i = 0; i < str.length( ); i++) 
{
 if (ispunct(str[i]))
 str[i] = ’ ’; // a blank
 str[i] = tolower (str[i]);
 }
 cout << str;
}
What is printed by the last line of the code ?
A. this*is^a.45min test.
B. thisisa45mintest
C. this is a 45min test
D. this is a 45min test

2). What is cout?
A. It is a function
B. It is an operator
C. It is a class
D. It is an object (class instance)
E. It is a reserved word (C++ keyword

3). Given below are some statements about the default (0-argument) constructor:
I. Its return type is the type of the class
II. It has no return type
III. The programmer can define it, but the C++ language doesn’t require this
IV. The programmer must define it
V. It is always defined by C++ if it isn’t provided by the programmer
VI. It is sometimes, but not always, defined by C++ if it isn’t provided by the programmer
Which of these statements are true?
A. I, III and V only
B. I, II and VI only
C. II and IV only
D. II, III, and V only
E. II, III, and VI only 

4). Which of the following functions will correctly return true if its argument is an odd integer?
I. bool IsOdd (int x) 
{
 return (x % 2 == 1);
}
II. bool IsOdd (int x) 
{
 return (x / 2 == 1);
 }
III. bool IsOdd (int x) 
{
 if (x % 2 == 1)
 return true;
 else
 return false;
}
A. II only
B. I and II only
C. I and III only
D. II and III only
E. I, II and III 

5). When an ADT is implemented as a C++ class, which of the following should normally be true?
A. Member functions are private, member variables are public
B. Member functions are public, member variables are private
C. Member functions, as well as member variables, are private
D. Member functions, as well as member variables, are public 

6). Given below are three implementations of the swap function:
I. 
void swap (int a, int b) 
{
 int temp;
 temp = a;
 a = b;
 b = temp;
 }
 int main () 
{
 int i = 0, j = 1;
 swap (i, j);
 }
II. 
void swap (int &a, int &b) 
{
 int temp;
 temp = a;
 a = b;
 b = temp;
 }
 int main () 
{
 int i = 0, j = 1;
 swap (i, j);
 }
III. 
void swap (int *a, int *b) 
{
 int *temp;
 temp = a;
 a = b;
 b = temp;
 }
 int main () 
{
 int i = 0, j = 1;
 swap (&i, &j);
 } 
Which of these would actually swap the contents of the two integers i and j ?
A. I only
B. II only
C. III only
D. I and II only
E. II and III only 

7). What is printed by the following program ?
void func (int *b) 
{
 *b = 1;
}
int main () 
{
 int *a;
 int n;
 a = &n;
 *a = 0;
 func (a);
 cout << *a << endl;
}
A 0
B. 1
C. The address of b
D. The address of a
E. The address of n 

8). Consider the following class:
class FooBar 
{
 public:
 void f1 (string s);
 void f2 (const string &s);
 void f3 (string s) const;
 private:
 string str;
};
Which of the three member functions could legally alter member variable str ?
A. The function f1 only
B. The function f2 only
C. The function f3 only
D. Two of them
E. All three of them 

9). Consider this piece of code:
void mysterious(int i, int &k) 
{
 i = 1;
 k = 2;
}
int main () 
{
 int x = 0;
 mysterious (x, x);
 cout << x << endl;
 return 0;
}
What is the value of x that gets printed by the main ?
A. 0
B. 1
C. 2
D. None of these 

10). Consider the following statements:
int *p;
int i, k;
i = 142;
k = i;
p = &i;
Which of the following statements changes the value of i to 143 ?
A. k = 143;
B. *k = 143;
C. p = 143;
D. *p = 143;
E. More than one of the above 

11). In the following function:
int f (int n) 
{
 int v;
 v = 2*n+1;
 return v;
}
What is the storage class of variable v?
A. static
B. dynamic
C. contextual
D. automatic
E. inline 
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: