QB - Object Oriented Programming Using C++-2
QB - Object Oriented Programming Using C++-2
Part-A
Fundamental Concepts of a Programming Language
2 Marks:
1. Draw a diagram to represent the basic structure of a programin C++.
2. What do you mean by a token?
3. Differentiate between keyword and identifier.
4. Compare and contrast the variables and constants in C++. What are the rules to be followed
for identifiers? 5 Marks
5. What is the need of data types in C++? Describe different data types along with their
representations and size in C++.
6. Give classification of operators available in C++ with the help of neat and clean diagram.
7. Define ternary operator. Compare it with if and if-else statement.
8. What do you mean by operator precedence?
9. What is the need of type conversion? Discuss different types of type conversion in C++. 10
Marks
10. Classify the different statements available in C++.
11. Differentiate between nested if-else and switch statement.
12. Compare and contrast for, while and do-while looping statements.
13. Differentiate between break and continue statement.
14. Why the use of goto statement is not good for quality programming?
15. What is the need of array. Discuss different types of arrays.
16. Discuss different string handling functions available in C++.
Part-B
Pointers and Run Time Polymorphism 2
Marks:
1. What is the need of abstract class in C++?
5 Marks:
2. Write a C++ program demonstrating use of the pure virtual function with the use of base and
derived classes.
3. What is the use of this keyword in C++?
10 Marks:
4. Write a program to demonstrate friend function in C++.
Exception Handling
2 Marks:
1. Compare and contrast error and exception.
2. Draw a neat and clean diagram to show exception handling model in C++.
5 Marks:
3. Write down a detailed C++ program to demonstate the use of try, catch , throw and nested try.
10 Marks:
4. What is a user defined exception. Wirte down the scenario where we require user defined
exceptions.
5. When do we need multiple catch blocks for a single try block? Give an example.
String Handling 2
Marks:
1. How string is used in C++? How can we create string object?
5 Marks:
2. Write a programin C++ to extract character from a string.
3. Draw a neat and clean sketch to show the different streams available in C++.
10 Marks:
4. What is role of manipulators in C++. Write down different manipulators in C++.
5. Differentiate between formatted and unformatted I/O. Discuss its different functions.
File Handling and Templates
2 Marks:
1. What are the file strams?
2. Explain the process of open,read,write and close files?
5 Marks:
3. Explain the role of seekg(),seekp(),tellg(),tellp(),function in the process of random access in a
file.
4. Explain the Standard Template Library and how it is working.
10 Marks:
5. Write a C++ program using function template to find the product of two integer or floating
point type of data.
Programming exercises (5 Marks Each)
void main()
{ cout<<strlen(“Hello, World.\n”)<<”\n”;
(a) 123 (b) Compile time error (c) None (d) Run time Error
{ cout << ;
void main()
{
int a = 20; int &n = a;
n=a++; a=n++; cout<<a
<<”,”<<n<<endl;
}
(a) 20, 20 (b) 20, 21 (c) 21, 22 (d) None
5. What is the output of the following
code? #include<iostream.h>
void main()
&n = a;
n=a++;
n = &b; cout<<a
<<”,”<<n<<endl; }
(a) 21, 21 (b) 20, 21 (c) 21, 22 (d) Error
void main()
{
bool a=10;
cout<<a<<endl;
}
(a) 10 (b) false (c) 1 (d) Error
{
int main; main = 100;
cout<<main++<<endl;
(a) 101 (b) 100 (c) None (d) Error: one cannot use main as identifier
void main()
{ int a=0,x; x = ++a
* --a;
void main()
{ a=32;
cout<<a<<endl;
int a;
(a) 32 (b) 0 (c) Compile time error (d) Run time error
(d) None
(a) variable, location (b) variable, position (c) constant, variable (e) None
(a) string literal (b) float literal (c) double literal (d) character literal
17. To execute a C++ program, one first need to translate the source code into object code. This process if
called .
{ do
int b=0;
cout<<b; b+
+;
}while(b!=10);
(a) recursion (b) passing a reference (c) passing a value (d) None
20. Each generic type in a template function definition is preceded by the keyword
void main()
}
(c) 14, 15 (d) 15,15
(a) 14, 14 (b) 15, 14
{
int a[5] = {0}; for(int
i=0;i<2;i++) a[i]=i;
void main()
int a[5] =
{100,2,3,22,400}; int b[5];
b=a;
void main()
i=0;i<5;i++)
cout<<a[i]<<endl;
26. To delete a dynamically allocated array named ‘a’, the correct statement is (a) delete a;
(d) None
void main()
int i=5,j=0;
while(i-- || j++)
{ cout<<i<<" "<<j<<”,”;
(a) 5 1, 4 2, 3 3, 2 4, 1 5, (b) 4 0, 3 0, 2 0, 1 0, 0 0,
int a; bool
b;
int a = 1; void
main()
{ int a = 100;
{ int a = 200;
cout<<a<<",";
} cout<<a<<",";
cout<<::a<<","; }
(a) Error (b) 100, 200, 300,
100,
(c) 300, 200, 100, garbage, (d) 300, 200, 100, 1,
{ int x=10;
(x<0)?(int a =100):(int a
=1000); cout<<a;
int a = 0;
cout<<(a = 10/a);
void main()
{ static x;
char str1[]=”India”,
str2[]=”India”; if(str1==str2)
(a) Both the string are same (b) Both the string are not same
36. What is the output of the following code if user enters “This is
a test”? #include<iostream.h> #include<string.h> void main()
void main()
void main()
{
x = ptr2 - ptr1;
cout<<x;
}
(c) the address that points to ‘\0’ (d) the address that points to -1
void main()
void main()
(a) 16 (b) 7
44. The design of classes in a way that hides the details of implementation from the user is known as:
46. I want a nonmember function to have access to the private members of a class. The class must declare
that function:
(a) friend (b) inline
47. The ability to reuse objects already defined, perhaps for a different purpose, with
modification appropriate to the new purpose, is referred to as (a) Information hiding.
(b) Inheritance.
48. What do you think is the outcome of calling a redefined non-virtual function using a base-class
pointer?
49. A class member that is to be shared among all objects of a class is called
(a) A const member (b) A reference parameter
(a) Is visible only in the subclasses (and not in the class it is declared in).
(b) Is visible only in the class it is declared in.
(c) Is visible to all classes, but modifiable only in the class where it is declared.
(d) Is visible in the class it is declared in, and all of its subclasses.
(a) Each instance of a class will have its own copy of the variable.
(b) Changing the variable in one instance will have no effect on other instances of the class.
(c) There will be only one instance of the variable initialized for all classes.
(d) Every instance of the class must consider the value of the static variable before initializing.
(b) destructors
(d) The class may only exist during the planning phase
61.
#include<iostream.h> class
Base
{ int static i;
public:
Base(){}
};
void main()
Multi m;
In the above program, how many times Base’s constructor will be called?
(a) 1 (b) 2
62.
#include<iostream.h> namespace N1
} namespace N2
} void main()
{ using N1::f;
int i2=f(1.0);
63.
#include<iostream.h>
class Base
public : int a;
protected: int b;
private: int c;
};
};
class Friend
Derived derived;
};
In the above code, which of the following variables can be accessed in "Friend"?
{ public
:
obj(){count++;} ~obj(){count--;}
}; int
main()
{ obj G; }
cout<<count; return
0; }
(a) 0 (b) 5
(c) 1 (d) 6
{ for(int ii=0;ii<3;++ii)
case 1:cout<<"one
";continue; case
2:cout<<"two ";break;
} return 0;
}; int
main()
{ obj A,B;
{ obj D;
obj E; return 0;
}
(a) in in in out in out out out (b) in in in in out out out out
};
{};
};
int main()
(b) One cannot have a ‘Base’ pointer to ‘Derived’ since it is not derived publicly
int main()
{ myprofessor obj;
return 0;
public Parent
";}
}; void
main()
Child c;
private: int
n;
}; class D1:Base
D1
int i;
void Method(){i=2;}
};
int main()
D2 test;
return 0;