HW5 - Solutions

# HW5 - Solutions - EC327IntroductiontoSoftwareEngineering...

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)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/09/2010 for the course ECE 327 taught by Professor Babakkia during the Fall '09 term at BU.

### Page1 / 4

HW5 - Solutions - EC327IntroductiontoSoftwareEngineering...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online