Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
89 views
in Computer by (55.2k points)
closed by

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

1 Answer

+1 vote
by (57.2k points)
selected by
 
Best answer
#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

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...