RBSE Solutions for Class 12 Computer Science Chapter 12 इनहेरिटेंस

Rajasthan Board RBSE Class 12 Computer Science Chapter 12 इनहेरिटेंस

RBSE Class 12 Computer Science Chapter 12 पाठ्यपुस्तक के प्रश्न

RBSE Class 12 Computer Science Chapter 12 वस्तुनिष्ठ प्रश्न

प्रश्न 1.
इनहेरिटेंस में पहले से तैयार क्लास को क्या कहा जाता है?
(अ) बेस क्लास
(ब) पेरेंट क्लास
(स) सुपर क्लास
(द) ये सभी
उत्तर:
(द) ये सभी

प्रश्न 2.
इनहेरिटेंस में नई क्लास को क्या कहा जाता है?
(अ) डिराइव्ड क्लास
(ब) चाइल्ड क्लास
(स) सब क्लास
(द) ये सभी
उत्तर:
(द) ये सभी

प्रश्न 3.
डिफॉल्ट विजिबिलिटी मोड क्या होता है?
(अ) पब्लिक
(ब) प्राईवेट
(स) प्रोटेक्टेड
(द) इनमें से कोई नहीं
उत्तर:
(ब) प्राईवेट

प्रश्न 4.
इनहेरिटंस जिसमें एक बेस क्लास और एक डिराइव्ड क्लास होती है, उसे क्या कहा जाता है?
(अ) सिंगल इनहेरिटेंस
(ब) मल्टीलेवल इनहेरिटेंस
(स) मल्टीपल इनहेरिटेंस
(द) हायराकिकल इनहेरिटेंस
उत्तर:
(अ) सिंगल इनहेरिटेंस

प्रश्न 5.
जब एक क्लास दो या दो से अधिक क्लासों के फीचर को इनहेरिट करती है, उसे क्या कहा जाता है?
(अ) सिंगल इनहेरिटेंस
(ब) मल्टीलेवल इनहेरिटेंस
(स) मल्टीपल इनहेरिटेंस
(द) हायरार्किकल इनहेरिटेंस
उत्तर:
(स) मल्टीपल इनहेरिटेंस

RBSE Class 12 Computer Science Chapter 12 अतिलघु उत्तरीय प्रश्न

प्रश्न 1.
इनहेरिटेंस किसे कहा जाता है?
उत्तर-
पहले से तैयार क्लासों से नई क्लास बनाने की प्रक्रिया को इनहेरिटेंस कहा जाता है।

प्रश्न 2.
सिंगल इनहेरिटेंस किसे कहते हैं?
उत्तर-
सिंगल इनहेरिटेंस में एक बेस क्लास और एक डिराइव्ड क्लास होती है। सिंगल इनहेरिटेंस डिराइव्ड क्लास को एक बेस क्लास से प्रोपर्टीज (properties) और बिहेवियर (behavior) लेने में सक्षम बनाता है।

प्रश्न 3.
मल्टीलेवल इनहेरिटेंस किसे कहते हैं?
उत्तर-
मल्टीलेवल इनहेरिटेंस में लेवल की कोई सीमा नहीं होती है, इनमें एक क्लास को किसी दूसरी डिराइव्ड क्लास से भी डिराइव किया जा सकता है।
RBSE Solutions for Class 12 Computer Science Chapter 12 इनहेरिटेंस image - 1

प्रश्न 4.
मल्टीपल इनहेरिटेंस किसे कहते हैं?
उत्तर-
जब कोई क्लास दो या दो से अधिक क्लासों के फीचर्स को इनहेरिट करती है, उसे मल्टीपल इनहेरिटेंस कहा जाता है।
RBSE Solutions for Class 12 Computer Science Chapter 12 इनहेरिटेंस image - 2

प्रश्न 5.
हायरार्किकल इनहेरिटेंस किसे कहते हैं?
उत्तर-
जब एक बेस क्लास को दो या दो से अधिक डिराइब्ड क्लासों द्वारा इनहेरिट किया जाता है, तो उसे हायराकिकल इनहेरिटेंस कहा जाता है।
RBSE Solutions for Class 12 Computer Science Chapter 12 इनहेरिटेंस image - 3

प्रश्न 6.
हाइब्रिड इनहेरिटेंस किसे कहते हैं?
उत्तर-
दो या दो से अधिक इनहेरिटेंस के प्रारूपों के सम्मिलित रूप को हाइब्रिड इनहेरिटेन्स कहा जाता है।
RBSE Solutions for Class 12 Computer Science Chapter 12 इनहेरिटेंस image - 4

प्रश्न 7.
एबस्ट्रेक्ट क्लास किसे कहते हैं?
उत्तर-
जिस क्लास में कम से कम एक प्योर वर्चुअल फंक्शन हो, उस क्लास को एबस्ट्रेक्ट क्लास कहा जाता है। इसका प्रयोग केवल बेस क्लास के रूप में किया जाता है। जिसे दूसरी क्लासों द्वारा इनहेरिट किया जाता है।

RBSE Class 12 Computer Science Chapter 12 लघु उत्तरीय प्रश्न

प्रश्न 1.
विजिबिलिटी मोड का इनहेरिटेंस में प्रभाव का वर्णन कीजिए।
उत्तर-
विजिबिलिटी मोड प्राईवेट, प्रोटेक्टेड या पब्लिक हो सकता है। डिफॉल्ट विजिबिलिटी मोड प्राईवेट होता है। विजिबिलिटी मोड यह बताता है कि बेस क्लास के फीचर को प्राईवेटली, प्रोटेक्टेडली या पब्लिकली इनहेरिट किया गया है। अगर बेस क्लास को डिराइव्ड क्लास के द्वारा प्राईवेटली इनहेरिट किया गया है तब बेस क्लास के पब्लिक और प्रोटेक्टेड मेम्बर डिराइव्ड क्लास के प्राइवेट मेम्बर बन जाते हैं। बेस क्लास के प्राईवेट मेम्बर को कभी भी इनहेरिट नहीं किया जा सकता है।

अगर बेस क्लास को डिराइव्ड क्लास के द्वारा प्रोटेक्टेडली इनहेरिट किया गया है, तब बेस क्लास के प्रोटेक्टेड और पब्लिक मेम्बर डिराव्हड क्लास के प्रोटेक्टेड मेम्बर बन जाते हैं।

अगर बेस क्लास को डिराइव्ड क्लास के द्वारा पब्लिकली इनहेरिट किया गया है, तब बेस क्लास के प्रोटेक्टेड मेम्बर डिराइव्ड क्लास के प्रोटेक्टेड मेम्बर बन जाते हैं और बेस क्लास के पब्लिक मेम्बर डिराइव्ड क्लास के पब्लिक मेम्बर बन जाते हैं।

प्रश्न 2.
वर्चुअल बेस क्लास की अवधारणा क्या है?
उत्तर-
वर्चुअल बेस क्लास-एक हाइब्रिड इनहेरिटेंस का उदाहरण लेते हैं जिसमें इनहेरिटेस के तीनों प्रारूप मल्टीलेवल, मल्टीपल और हायरार्किकल सम्मिलित हैं जैसा कि निम्नांकित चित्र में दर्शाया गया है।

क्लास ‘TA’ (शिक्षक सहायक) की दो प्रत्यक्ष बेस क्लासेज ‘teacher’ और ‘student’ हैं। जिनकी एक समान बेस क्लास ‘person’ है। ‘TA’ क्लास ‘person’ क्लास के फीचर को दो तरीकों से इनहेरिट करती है। यह स्थिति एक समस्या उत्पन्न करती है। ‘person’ क्लास के सभी प्रोटेक्टेड और पब्लिक मेम्बर ‘TA’ क्लास में दो बार इनहेरिट हो जाते हैं पहला क्लास ‘teacher’ होते हुए और दूसरा क्लास ‘student’ होते हुए। यह एक अस्पष्टता की स्थिति उत्पन्न करती है और उसे दूर करना चाहिए।
RBSE Solutions for Class 12 Computer Science Chapter 12 इनहेरिटेंस image - 5
यह अस्पष्टता एक समान बेस क्लास को वर्चुअल बेस क्लास बनाकर प्रत्यक्ष बेस क्लासों को घोषित करने के दौरान दूर की जा सकती है जैसा नीचे दर्शाया गया है :

class person
{
...........
...........
};
class teacher : virtual public person
{
...........
...........
};
class student : virtual public person
{
...........
...........
};
class TA : public teacher, public student
{
...........
...........
};

जब एक क्लास को वर्चुअल बेस क्लास घोषित करते हैं, तब केवल उस क्लास के पब्लिक और प्रोटेक्टेड मेम्बर की. एक ही प्रतिलिपि इनहेरिट होती है।

RBSE Class 12 Computer Science Chapter 12 निबंधात्मक प्रश्न

प्रश्न 1.
एक shape क्लास बनाइए जिसमें एक प्योर वर्चुअल फंक्शन volume हो। shape क्लास को तीन क्लासों cone, cylinder और cube द्वारा इनहेरिट किया गया हो। ये डिराइव्ड क्लासेज प्योर वर्चुअल फंक्शन को आयतन की गणना के लिए परिभाषित करेंगे?
उत्तर:

#include<iostream.h>
using namespace std; 
const float PI = 3.14; 
class shape
{
protected :
float radius; 
float height; 
float side; 
public : 
virtual float volume () = 0; || pure virtual function 
void getdata (float r, float h)
{
radius = r; 
height = h;
}
void getdata1 (side)
{
side = S;
}
};
class Cone : public shape
{
public : 
float volume ()
{
return (1/3*PI*radius^2*height);
}
};
class Cylinder : public shape
{
public : 
float volume ()
{
return(PI*radius^2*height);
}
};
class Cube : public shape
{
public : 
float volume ()
{
return (side*side*side);
}
};
int main (void)
{
Cone con; 
Cylinder cyl; 
Cube cub; 
con.getdata (5,9) 
cout << "volume of cone :"<< con. volume () << "\n"; 
cyl. getdata (4,5) 
cout << "volume of cylinder :"<<cyl. volume ()<<"\n"; 
cub.getdatal (3) 
cout << "volume of cube :"<<cub.volume () <<"\n"; 
return 0;
}

प्रोग्राम का आउटपुट होगा
Volume of cone=235.5
Volume of cylinder =251.2
Volume of cube = 27

RBSE Class 12 Computer Science Chapter 12 अन्य महत्त्वपूर्ण प्रश्न

RBSE Class 12 Computer Science Chapter 12 अतिलघु उत्तरीय प्रश्न

प्रश्न 1.
इनहेरिटेंस का क्या उपयोग है?
उत्तर-
इनहेरिटेंस के द्वारा प्रोग्रामर समय और ऊर्जा को बचा सकता है।

प्रश्न 2.
बेस क्लास, पेरेंट क्लास या सुपर क्लास किसे कहते हैं?
उत्तर-
पहले से तैयार क्लास को बेस क्लास, पेरेंट क्लास या सुपर क्लास कहते हैं।

प्रश्न 3.
डिराइव्ड क्लास, चाइल्ड क्लास या सब क्लास किसे कहते हैं?
उत्तर-
वह क्लास जो दूसरी क्लास से प्रोपर्टीज (properties) इनहेरिट (inherit) करती है, वह डिराइब्ड क्लास, चाइल्ड क्लास या सब क्लास कहलाती है।

प्रश्न 4.
डिफॉल्ट विजिबिलिटी मोड क्या होता है?
उत्तर-
डिफॉल्ट विजिबिलिटी मोड प्राइवेट होता है।

प्रश्न 5.
क्या बेस क्लास के प्राइवेट मेम्बर को इनहेरिट किया जा सकता है?
उत्तर-
नहीं, बेस क्लास के प्राइवेट मेम्बर को कभी भी इनहेरिट नहीं किया जा सकता है।

प्रश्न 6.
मल्टीलेवल इनहेरिटेंस में कितने लेवल होते हैं?
उत्तर-
मल्टीलेवल इनहेरिटेंस में लेवल की कोई सीमा नहीं होती है।

प्रश्न 7.
वर्चुअल फंक्शन किसे कहते हैं?
उत्तर-
अगर एक ही नाम के फंक्शन्स बेस और डिराइब्ड, दोनों क्लासों में प्रयोग किया जाता है, तब बेस क्लास के फंक्शन को वर्चुअल घोषित किया जाता है। उसे ही वर्चुअल फंक्शन कहा जाता है। एक बिना स्टेटमेंट के वर्चुअल फंक्शन को प्योर वर्चुअल फंक्शन कहा जाता है।

RBSE Class 12 Computer Science Chapter 12 लघु उत्तरीय प्रश्न

प्रश्न 1.
डिराइव्ड क्लास को परिभाषित करने का सिन्टेक्स बताइए।
उत्तर-
डिराइब्ड क्लास को परिभाषित करने का सिन्टेक्स इस प्रकार है :

class derived-class-name : Visibility-mode base-class-name
{
members of derived class 
};

प्रश्न 2.
सिंगल इनहेरिटेन्स का उदाहरण दीजिए।
उत्तर-

#include<iostream> 
using namespace std; 
class data
{
protected:
int x,y; 
public:
void getdata (int a, int b)
{
x=a; 
y=b;
}
void showdata (void)
{
cout<<"x="<<x<<"\n"; 
cout<<"y="<<y<<"\n"; .
}
}; 
class maximum: public data
{
public:
void max (void)
{
if (x>y) 
cout<<"Maximum is:"<<x; 
else 
cout<<"Maximum is:"<<y;
}
};
int main()
{
maximum m; 
m.getdata (4,9); 
m.showdata(); 
m.max () ; 
return 0;
}

प्रोग्राम का आउटपुट होगा
x=4
y=9
Maximum is: 9

प्रश्न 3.
मल्टीलेवल इनहेरिटेंस का एक प्रोग्राम लिखिए।
उत्तर:

#include<iostream>
using namespace std; 
class datal
{
protected: 
int x; 
public: 
void get_x(int a)
{
x=a;
}
void show_x (void)
{
cout<<"x="<<x<<"\n";
}
}; 
class data2:public data1
{
protected:
int y; 
public: 
void get_y(int b)
{
y=b;
}
void show_y (void)
{
cout<<"y="<<y<<"\n";
}
};
class addition: public data2
{
int z; 
public:
void sum (void)
{
z=x+y;
}
void show_z (void)
{
cout<<"z="<<z<<"\n";
}
}; 
int main()
{
addition a; 
a.get_x (4); 
a.get_y(7); 
a.sum(); 
a. show_x(); 
a.show_y(); 
a.show_z(); 
return 0;
}

प्रोग्राम का आउटपुट होगा
x=4
y=7
z=11

प्रश्न 4.
मल्टीपल इनहेरिटेंस का एक उदाहरण दीजिए।
उत्तर:

#include<iostream> 
using namespace std; 
class B1
{
protected:
int x; 
public:
void get_x(int a)
{
x=a;
}
}; 
class B2
{
protected:
int y; 
public:
void get y(int b).
{
y=b;
}
};
class D : public B1, public B2
{
int z; 
public:
void multiply (void)
{
z=x*y;
}
void display(void)
{
cout<<"x="<<x<<"\n"; 
cout<<"y="<<y<<"\n"; 
cout<<"z="<<z«<"\n";
}
};
int main()
}
D d; 
d.get_x (5); 
d.get_y(3); 
d.multiply(); 
d.display(); 
return 0;
}

प्रोग्राम का आउटपुट होगा
x=5
y=3
z=15

RBSE Class 12 Computer Science Chapter 12 निबंधात्मक प्रश्न

प्रश्न 1.
हायरार्कीकल इनहेरिटेंस का एक उदाहरण लिखिए।
उत्तर:

#include<iostream>
#include<string.h> 
using namespace std; 
class person
{
protected: 
char name [20]; 
int age; 
public: 
void get_person (const char *n, int a)
{
strcpy (name, n); 
age=a;
}
void show_person (void)
{
cout<<"Name:"<<name<<"\n"; 
cout<<"Age:"<<age<<"\n";
}
};
class teacher:public person 
{
char post[10]; 
public: 
void get_post (const char*p)
{
strcpy (post,p) 
}
void show_teacher (void)
{
show_person(); 
cout<<"post:"<<post<<"\n";
}
};
class student : public person
{
int standard; 
public:
void get_standard (int s)
{
standard=s; 
}
void show student (void)
{
show_person(); 
cout<<"Standard:"<<standard<<"\n";
}
};
int main()
{
teacher t; 
t.get_person ("Ram", 30);
t.get post("TGT"); 
student s; 
s.get person ("Shyam", 17); 
s.get_standard (12); 
t.show teacher(); 
s.show student (); 
return 0;
}

प्रोग्राम का आउटपुट होगा
Name: Ram
Age: 30
Post: TGT
Name: Shyam
Age: 17
Standard : 12

प्रश्न 2.
हाइब्रिड इनहेरिटेंस का एक प्रोग्राम लिखिए।
उत्तर:

#include<iostream> 
using namespace std; 
class arithmetic
{
protected:
int num1, num2; 
public:
void getdata (void)
{
cout<<"For Addition:"; 
cout<<"\n Enter the first number:"; 
cin>>num1; 
cout<<"\n Enter the second number:"; 
cin>>num2;
}
};
class addition:public arithmetic
{
protected:
int sum; 
public:
void add (void)
{
sum=num1+num2;
}
};
class subtract
{
protected:
int n1, n2, diff; 
public: 
void sub (void)
{
cout<<"\nFor Subtraction:"; 
cout<<"\nEnter the first number:"; 
cin<<"n1;
cout<<"\nEnter the second number:"; 
cin>>"n2; 
diff=n1-n2;
}
};
class result:public addition, public subtract
{
public:
void display(void)
{
cout<<"\n Sum of"<<numl<<"and "<<num2<<"= "<<sum; 
cout<<"\n Difference of"<<n1<<"and"<<n2<<"="<<diff;
}
};
int main()
{
result z; 
z.getdata(); 
z.add(); 
z. sub (); 
z.display(); 
return 0;
}

प्रोग्राम का आउटपुट होगा
For Addition:
Enter the first number: 5
Enter the second number: 7
For Subtraction:
Enter the first number: 10
Enter the second number: 3
Sum of 5 and 7 is 12
Difference of 10 and 3 is 7

प्रश्न 3.
एबस्ट्रेक्ट क्लास का उदाहरण दीजिए।
उत्तर:

#include<iostream> 
using namespace std; 
class shape
{
protected:
int width;
int height; 
public:
virtual int area ( ) =0; // pure virtual function 
void getdata (int w, int h) 
{
width=w; 
height=h;
}
}; 
class Rectangle:public Shape
{
public:
int area ()
{
return (width * height);
}
};
class Triangle: public Shape
{
public:
int area () 
{ 
return (width * height)/2;
}
}; 
int main(void)
{
Rectangle Rect; 
Triangle Tri; 
Rect.getdata (5,7); 
cout<< " Area of Rectangle : " Rect.area () <<"\n"; 
Tri.getdata (6,7); 
cout<< " Area of Triangle: " << Tri.area () <<"\n"; 
return 0;
}

प्रोग्राम का आउटपुट होगा
Area of Rectangle: 35
Area of Triangle: 21

RBSE Solutions for Class 12 Computer Science