Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://pastebin.com/u/TheWhiteFang
- // Tutorial7 Q4 [Top level method]
- #include <iostream>
- #include <math.h>
- using namespace std;
- #define PI 3.141
- class CCylinder{
- float m_Radius;
- float m_Height;
- float m_SurfaceArea;
- public:
- CCylinder (float inRadius = 0.0 , float inHeight = 0.0){
- m_Radius = inRadius;
- m_Height = inHeight;
- m_SurfaceArea = ( 2 * PI * inRadius*inRadius) + (2 * PI * inRadius * inHeight);
- }
- friend CCylinder operator+ (const CCylinder &inVal1, const CCylinder &inVal2);
- friend ostream &operator<<(ostream &output, const CCylinder &source);
- };
- //top level function
- CCylinder operator+ (const CCylinder &inVal1, const CCylinder &inVal2)
- {
- CCylinder temp;
- temp.m_SurfaceArea = (PI*inVal2.m_Radius*inVal2.m_Radius)-(PI*inVal1.m_Radius*inVal1.m_Radius);
- temp.m_SurfaceArea += (PI*inVal2.m_Radius*inVal2.m_Radius) + (PI*inVal1.m_Radius*inVal1.m_Radius);
- temp.m_SurfaceArea += (2*PI*inVal1.m_Radius*inVal1.m_Height)+(2*PI*inVal2.m_Radius*inVal2.m_Height);
- return temp;
- }
- //ostream operator
- ostream &operator<<(ostream &output, const CCylinder &source){
- output << "Surface Area = "<< source.m_SurfaceArea << " cm2 )" << endl;
- return output;
- }
- int main()
- {
- CCylinder cyObj1((float)2.5, (float)3.5);
- CCylinder cyObj2((float)3.5, (float)4.5);
- cout<< "Cylinder 1 (" << cyObj1 << /*")" <<*/ endl;
- cout<< "Cylinder 2 (" << cyObj2 <</* ")" <<*/ endl;
- CCylinder cyObj3 = cyObj1 + cyObj2;
- cout << "Cylinder 1 + Cylinder 2 = ";
- cout << "(" << cyObj3 <</* ")" <<*/ endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement