CS 237-OBJECT ORIENTED PROGRAMMING
PART A
1.Differentiate Object Oriented Object Based Programming Langauages.
2.Comment on the following overloaded function
Void inc(int i)
{
i=i+1;
}
Void inc(int i, int diff =1)
{
i=i+diff;
}
3.What is the ouput of the following program?
#include
main()
{
int i=3,j=5;
double x=33.5,y=10.0;
cout<<10+j%1<<”\n”;
cout<<<”\n”;
cout<<(19+i+j)/(2*j+2)<<”\n”);
cout<
cout<<<”\n;
}
4.What is error in the following class declarations?
Class string{
Char *str;
Unsigned len;
String();
String(string& s);
String(unsigned size char = ‘ ‘);
String(unsigned size);
String & assign (Strong& s);
~String();
Unsigned getlen() const;
Char * getString();
}
5.Differentiate Overloaded and overriden funcions.
6.Consider the following program
Class fun
{
Public:
fun(void)
{
Cout<<”1”;}
fun(fun &x)
{ cout<<”2”;}
fun operator-(fun y)
{ fun test; return(test); }
};
If the function main is coded as fun a,b; what is its output?
7.What is the main purpose of a template in C++? Give an example.
8.Give any two examples of expressions.
9.Differentiate instance members and static members.
10. In java, Can a class be defined inside a method? If so,what rule governs access to the variables of the enclosing method? If not, give reasons.
PART B
11 (i) Define a class Counter to model a counter in its general form, Define classes to model special forms like Cyclic counter,down counter and step 2 down counter. Provide methods for the following opeations-step,display,reset.Write a JAVA program to test the classes
(ii)Differentiate abstract classes and interfaces.
12(a) Explain the following characteristics of object oriented programming with examples.
(i) Data Encapsulation
(ii) Polymorphism
(iii) Genericity
(iv) Inheritance.
13(a) (i) What are the characteristics of constructor functions? Describe various of constructors with examples.
(ii) Create a class that keeps track of its number of instances.
(b) Define a C++ class Matrix to describe a matrix.Equip the class with functions for addition and multiplication.Overload operators suitably for input and output of the matrix.
14 (a) (i) What are friends functions? Give an example to highlight its need? What is its limitations?
(ii)What are virtual functions? Give an example to highlight its need?
(b) Give an applications that fits the following inheritance hierarchy and write the program for the same. Each class should have atleast two data members and two functions members.
15.(a) Give the syntax of functions template.Write template functions for bubble sort.Write a test program to illustrate its use.
(b) (i) Give the hierarchy of console stream classes.
(ii) Explain how exceptions are handled in C++, Give examples to support your answer.
No comments:
Post a Comment