Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://pastebin.com/u/TheWhiteFang
- // Tutorial 7 Q3 [Top-level method]
- #include <iostream>
- #include <math.h>
- using namespace std;
- class CCube{
- float m_EdgeLength;
- float m_SurfaceArea;
- public:
- CCube(float inEdge = 0.0){
- m_EdgeLength = (float)inEdge;
- m_SurfaceArea = 6 * (inEdge*inEdge);
- // To be completed
- }
- friend CCube operator+ (const CCube &inVal1, const CCube &inVal2);
- friend ostream &operator<<(ostream &output, const CCube &source);
- };
- CCube operator+ (const CCube &inVal1, const CCube &inVal2)
- {
- CCube temp;
- temp.m_SurfaceArea = (5 * pow(inVal1.m_EdgeLength, 2)) + (5 * pow(inVal2.m_EdgeLength, 2));
- temp.m_SurfaceArea += inVal2.m_EdgeLength - inVal1.m_EdgeLength;
- //if (inVal2.m_EdgeLength > inVal1.m_EdgeLength){
- // temp.m_SurfaceArea += inVal2.m_EdgeLength - inVal1.m_EdgeLength;
- //}
- //else if (inVal1.m_EdgeLength > inVal2.m_EdgeLength){
- // temp.m_SurfaceArea += inVal1.m_EdgeLength - inVal2.m_EdgeLength;
- //}
- return temp;
- }
- ostream &operator<<(ostream &output, const CCube &source){ //return ostream by reference //only thing that changes is classname
- output << "Surface Area = "<< source.m_SurfaceArea << " cm2 )" << endl;
- return output;
- }
- int main()
- {
- CCube cubeObj1((float)2.5);
- CCube cubeObj2((float)3.5);
- cout << "Cube 1 (" << cubeObj1 << /*")" <<*/ endl;
- cout << "Cube 2 (" << cubeObj2 << /*")" <<*/ endl;
- CCube cubeObj3 = cubeObj1 + cubeObj2;
- cout << "Cube 1 + Cube 2 = ";
- cout << "(" << cubeObj3 << /*")" <<*/endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement