Read and download free pdf of CBSE Class 12 Computer Science Class And Objects Worksheet Set B. Students and teachers of Class 12 Computer Science can get free printable Worksheets for Class 12 Computer Science Class And Objects in PDF format prepared as per the latest syllabus and examination pattern in your schools. Class 12 students should practice questions and answers given here for Computer Science in Class 12 which will help them to improve your knowledge of all important chapters and its topics. Students should also download free pdf of Class 12 Computer Science Worksheets prepared by teachers as per the latest Computer Science books and syllabus issued this academic year and solve important problems with solutions on daily basis to get more score in school exams and tests
Worksheet for Class 12 Computer Science Class And Objects
Class 12 Computer Science students should refer to the following printable worksheet in Pdf for Class And Objects in Class 12. This test paper with questions and answers for Class 12 will be very useful for exams and help you to score good marks
Class 12 Computer Science Worksheet for Class And Objects
1 Write the definition for a class called Rectangle that has floating point data members length and width. The class has the following member functions:
void setlength(float) to set the length data member
void setwidth(float) to set the width data member
float perimeter() to calculate and return the perimeter of the rectangle
float area() to calculate and return the area of the rectangle
void show() to display the length and width of the rectangle
int sameArea(Rectangle) that has one parameter of type Rectangle. sameArea returns 1 if the two Rectangles have the same area, and returns 0 if they don't.
1. Write the definitions for each of the above member functions.
2. Write main function to create two rectangle objects. Set the length and width of the first rectangle to 5 and 2.5. Set the length and width of the second rectangle to 5 and 18.9. Display each rectangle and its area and perimeter.
3. Check whether the two Rectangles have the same area and print a message indicating the result. Set the length and width of the first rectangle to 15 and 6.3. Display each Rectangle and its area and perimeter again. Again, check whether the two Rectangles have the same area and print a message indicating the result.
1. Define a class STUDENT with the following specifications
Private members:
Grno long integer
Name 20 characters
Marks in 5 subjects, each out of 100 an array of 5 float values
Total, percentage float
Calculate() Function to calculate total & percentage
Public functions
takedata() Function to read Grno, name and 5 marks of a student
displaydata() to invoke Calculate() function and to display all the details of the student
Write a Program to implement the above class for a student.
2. Define a class EMPLOYEE with the following specifications
Private data members
Empno integer
Name 20 characters
Basicpay float
HRA, DA, PF float
Netpay double
Public functions
Getdata() Function to read empno, name and basicpay of an Employee
Compute() Function to compute HRA (10% of basicpay), DA (50% of basicpay), PF (8% of basicpay) and netpay as basicpay + HRA + DA – PF and return the calculated Netpay.
Printdata() to invoke Compute() function and to display all the details of an employee
Write a Program to read details (empno, name and basicpay) for n employees and compute netpay for them and display all the details.
CLASSES AND OBJECTS
Q1. What is class? What is its need? Classes
A class is a way to bind the data describing an entity and its associated functions together. In C++ , class makes a data type that is used to create objects of this type. Need for classes
Classes are needed to represent real-world entities that not only have data type properties (Characteristics) but also have associated operations (their behaviour)
Q2 . Differentiate between local and global class with help of example.
Answer : 1. Global Class
A class is said to be global it its declaration occurs outside the bodies of all functions in a program.
2. Local class
A class is said to be local if its occurs inside the function body
# include<iostream.h>
class x //x is a global class
{
members variable functions of class;
};
x ob1; //global object
int main ( )
{
class num // num is local class
{
public:
int a=10;
void num( ) // constructor (same name of class)
{
cout<<num;
};
x ob2; //local object of class x
num n1; // n1is a class object
n1.num( );
} // closing of main ()
Q3. What do you mean by nested class ?Explain.
Answer : Nested class
Declaration of one class in to another class is called is called nested of a class.
#include<iostream.h>
#include<conio.h> // for clrscr()
class score
{
int a; //private member variable
class batesman // nested class
{
int b;
public:
int c;
void total( )
{
cin>>b>>c;
int sum = b+c;
}
batesman( )
{
c=10;
}
}; // end of class batesman
batesman obj2; // object of class batesman
void second( void)
{
cout<<score :: second()<<endl;
cout<<”A =” <<a
}
score( )
{
a= 25;
}
}; //end of class score;
void main()
{
score ab;
batesman bc;
score :: batesman cd;
ab.second();
bc.total();
cd.total();
}
Q4. What are the advantages and disadvantages of inline functions?
Answer : The main advantages of inline functions is that they save on the overheads of a function call as the function is not invoked, rather its code is replaced in the program.
The major disadvantage of inline functions is that with more function calls, more memory is wasted as for every function call, the same function code is inserted in the program. Repeated occurrences of same function code waste memory space.
Q5. What do you understand by member function?
Answer : Member function have full access privilege to both the public and private members of the class. These are defined within the class scope that is they are not visible outside the scope of class.
But not member functions are visible outside the class (ordinary functions)
Q6. What are static class members?
Answer : A class can have static data members as well as static member functions The static data members are the class variables that are common for all the objects of the class. Only one copy of static data members is maintained which is shared by all the objects of the class. They are visible only with in the class
Q7. Identify the errors in the following code fragment:
class ab
{
int x;
static int ctr;
Public:
Void init(void) {
x=ctr=0; }
static void print(void) {
cout<<ctr<<x; } };
Answer : In the above code fragment, a static member function is trying to access a non static member that is ‘x’ which is the error
The correct code for static member function is
static void print(void)
{
cout<<ctr; }
Q8. What is the significance of access specifiers in a class?
Answer : A class provides three access specifiers namely private, public and protected
(a) A data member declared as private or protected remains hidden from outside world and it can only be accessed by the member functions of the class.
(b) A data member declared as public is made available to the outside world. That is, it can be accessed by any function, any expression in the program but only by using an object of the same class type.
These access labels enforce data hiding and abstraction also.
Q9 . Write the output of the following code
#include<iostream.h>
class counter {
private:
unsigned int count;
public:
counter() // constructor
{
count=0; }
void inc_count( ) // increment in count variable
{
count ++; }
int get_count( ) {
return count; }
};
void main()
{
counter c1,c2;
cout<< “ \n value for c1 is:” <<c1.get_count( );
cout<< “ \n value for c2 is:” <<c2.get_count( );
c1.inc_count();
c2.inc_count();
c2.inc_count();
cout<< “\t c1=” <<c1.get_count();
cout<< “\t c2=” <<c2.get_count(); }
Answer : The output will be
c1=0 c2=0 c1=1 c2=2
Chapter – 4 CONSTRUCTOR AND DESTRUCTORS
Q1. What is Constructor ?
Answer : Constructors:
A constructor is a special member function of a class that is automatically called, when an object is created of that class. A member function with the same name as its class is called constructor.
Q2. What is destructor ? What is its need ?
Answer : Destructor:
A destructor is also a member function whose name is the same as the class name but is preceded by tilde (‘~’)
A destructor takes no arguments and no return types can be specified for it. It is called automatically by the compiler when an object is destroyed. A destructor cleans up the storage ( memory area of the object) that is no longer accessible. Need for Destructors
Allocated resources (like constructor) must be de-allocated before the object is destroyed. It works as a de-allocating and releasing memory area and it perform our works as a clean up tasks. Therefore, a destructor is equally useful as a constructor is.
class stud
{
stud() //constructor
{
cout << “ welcome”
Worksheet for CBSE Computer Science Class 12 Class And Objects
We hope students liked the above worksheet for Class And Objects designed as per the latest syllabus for Class 12 Computer Science released by CBSE. Students of Class 12 should download in Pdf format and practice the questions and solutions given in the above worksheet for Class 12 Computer Science on a daily basis. All the latest worksheets with answers have been developed for Computer Science by referring to the most important and regularly asked topics that the students should learn and practice to get better scores in their class tests and examinations. Expert teachers of studiestoday have referred to the NCERT book for Class 12 Computer Science to develop the Computer Science Class 12 worksheet. After solving the questions given in the worksheet which have been developed as per the latest course books also refer to the NCERT solutions for Class 12 Computer Science designed by our teachers. We have also provided a lot of MCQ questions for Class 12 Computer Science in the worksheet so that you can solve questions relating to all topics given in each chapter.
You can download the CBSE Printable worksheets for Class 12 Computer Science Class And Objects for latest session from StudiesToday.com
There is no charge for the Printable worksheets for Class 12 CBSE Computer Science Class And Objects you can download everything free
Yes, studiestoday.com provides all latest NCERT Class And Objects Class 12 Computer Science test sheets with answers based on the latest books for the current academic session
CBSE Class 12 Computer Science Class And Objects worksheets cover all topics as per the latest syllabus for current academic year.
Regular practice with Class 12 Computer Science worksheets can help you understand all concepts better, you can identify weak areas, and improve your speed and accuracy.