KENDRIYA VIDYALAYA, BELLARY XII COMPUTER SCIENCE MONTHLY TEST Max. Marks 25 1.
Explain the difference between Object Oriented Programming and Procedural Programming (3) 2. Design a class motor_car having the following specifications: Data Members: License number Car Manufacturer Car Model Number Bought On Price Speed Member Functions: Getdata() Get the license number, manufacturer, model number Car_Bought() Get the buying data and the price Start_car() Gets the speed of the car Accelerate() Increase the speed of the car by 4m/s
(4)
3. Explain using a suitable example how data hiding/encapsulation is implemented in C++. (4) 4. Identify and correct the error in the following piece of code. Underline your corrections: #include<iostream.h> #include<stdio.h> class employee { privat: int empno; char name[25]; double salary; void getdata() { cin >> Enter employee number : ; Cout << empno; Cin >> Enter name; gets(name): Cin >> Enter salary : ; cout >> salary; } Void inc_sal(double x) { Employee.salary += double } int display();
}; Void main() { Employee.getdata(); Employee.inc_sal(); Employee.display(); } (4)
5. Explain the need for constructors with example. 6. When are copy constructors called. Explain with examples.
(3) (3)
7. Design a class shapes with the following specification: Data Members: It should contain three variables which can hold three floating point values dim1, dim2, dim3. A string should also be there to hold which of the shapes Circle, Rectangle, Parallelopiped. Member Functions: Define three constructors. First Constructor should accept only one float parameter and it should set dim1 to the parameter and set the shape to Circle Second constructor should accept two float parameters and it should set dim1,dim2 to the parameters and set the shape to Rectangle Third constructor should accept three float parameters and it should set dim1, dim2, dim3 to the three parameters and also set the shape to Parallelopiped Member function surface_area() calculates the surface area depending on the shapes. Circle=pi*radius*radius, Rectangle=length*breadth, Parallelopiped=2(l*b+b*h+l*h) (4)