#include <iostream>
using namespace std;
class Shape
{
protected:
double X,Y,Z;
public:
Shape()
{
X = 0.0;
Y = 0.0;
Z = 0.0;
}
Shape(double x,double y,double z)
{
X = x;
Y = y;
Z = z;
}
virtual void move(double x,double y,double z){}
};
class ThreeDimensionalShape : public Shape
{
protected:
double volume,surfaceArea;
public:
ThreeDimensionalShape(double x,double y,double z) :
Shape(x,y,z)
{
}
virtual void calcArea(){}
virtual void calcVolume(){}
double getX()
{
return X;
}
double getY()
{
return Y;
}
double getZ()
{
return Z;
}
double getVolume()
{
return volume;
}
double getSurfaceArea()
{
return surfaceArea;
}
void move(double x,double y,double z)
{
X = X+x;
Y = Y+y;
Z = Z+z;
}
};
class Sphere : public ThreeDimensionalShape
{
private:
double radius;
public:
Sphere() : ThreeDimensionalShape(0,0,0)
{
radius = 0.0;
calcArea();
calcVolume();
}
Sphere(double x,double y,double z,double radius) :
ThreeDimensionalShape(x,y,z)
{
this->radius = radius;
calcArea();
calcVolume();
}
void setRadius(double radius)
{
this->radius = radius;
}
double getRadius()
{
return radius;
}
void calcArea()
{
surfaceArea = 4 * 3.14*
radius*radius;
}
void calcVolume()
{
volume = 4.0/3 * 3.14*
radius*radius *radius;
}
Sphere operator +(Sphere s)
{
this->radius = this->radius +
s.radius;
return *this;
}
friend ostream &operator<<( ostream
&,const Sphere &s );
};
ostream &operator<<( ostream &output,Sphere &s
)
{
output << "\nSphere :
("<<s.getX()<<",
"<<s.getY()<<","<<s.getZ()<<")"<<"
radius : "<<s.getRadius();
return output;
}
int main() {
Sphere s(2,3,4,6);
cout<<s;
cout<<"\nArea of sphere :
"<<s.getSurfaceArea();
cout<<"\nVolume of sphere :
"<<s.getVolume();
Sphere s1(4,5,6,5.5);
Sphere s2;
s2 = s +s1;
cout<<s2;
return 0;
}
Output:
Sphere : (2, 3,4) radius : 6 Area of sphere : 452.16 Volume of sphere : 904.32 Sphere : (2, 3,4) radius : 11.5
Do ask if any doubt. Please upvote.
Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO MAKE SURE IT IS WRITTEN IN C++! thank you so much in advance and I will upvote when done right...
Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO MAKE SURE IT IS WRITTEN IN C++! thank you so much in advance and I will upvote when done right! (8 points) Create a class called resizeableArray. Include an int pointer arrayPtr variable that points to a dynamic array, a capacity variable that holds the dynamic array maximum size and a currentSize variable that has the current number of elements assigned in the dynamic...
C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement the constructors and member function of each of the classes (Marks 15) class Fraction{ private: int numerator; int denominator; public: Fraction(int, int); float fractionValue();//determines the value of numerator/denominator }; class Problem{ private: Fraction f[3]; public: Problem(int, int, int, int, int, int); Fraction largestFraction();//Returns the fraction having largest fraction value }; Question 2: In the following Inheritance problem #include<iostream> #include<string> using namespace std; class Animal{...
Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly. please put comment with code! and please do not just copy other solutions. Instructions 1. Read instructions carefully! 2. Use C++ syntax only, C syntax will not be accepted. 3. Always use braces to define blocks. 4. Indent all lines within a block. Each block requires one more tab. 5. Organize your code well with proper formatting and a single...