{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW5 - Solutions

# HW5 - Solutions - HW#5Solutions Problem1[90points/Solution...

This preview shows pages 1–3. Sign up to view the full content.

EC327 Introduction to Software Engineering HW #5 Solutions Problem 1 [90 points] //Solution to EC327, HW5 //Jiaxi Jin #include <stdafx.h> #include <iostream.h> class Error { public : void output() { cout<< "Invalid Input! The number should be larger than zero." <<endl; } }; Error er; class CPoly { public : virtual float perimeter( void ){ return 1;} virtual double area( void ){ return 1;} protected : test = 123; }; class CTriangle: public CPoly { public : CTriangle( float a) { if (a<=0) throw er; length = a; } float perimeter( void ){ return length*3;} double area ( void ){ return length * length * 0.433; } ~CTriangle(){ cout<< "Triangle says goodbye." <<endl; } protected : float length; }; class CSquare: public CPoly { public : CSquare( float a) { if (a<=0) throw er; length = a; } float perimeter( void ){ return length*4; } double area ( void ){ return length * length; } virtual ~CSquare(){ cout<< "Square says goodbye." <<endl; } private : float length; };

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
class CCube: private CSquare { public : CCube( float a):CSquare(a){;} float perimeter( void ){ return length*length*length; } double area ( void ){ return length * length; } ~CCube(){ cout<< "Cube says goodbye." <<endl; } }; class CPentagon: public CPoly { public : CPentagon( float a) { if (a<=0) throw er; length = a; } float perimeter( void ){ return length*5;} double area ( void ){ return length * length * 1.72; }
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern