-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.cpp
More file actions
29 lines (28 loc) · 970 Bytes
/
Copy pathShape.cpp
File metadata and controls
29 lines (28 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Assignment C++: 3
Author: Ron Zilber
*/
#include "Shape.h"
Shape::Shape(const char * aColor){
if(strcmp(aColor,"red")!=0 && strcmp(aColor,"green")!=0 && strcmp(aColor,"blue")!=0)
throw "Exception: color must be red green or blue";
else{
color = new char[sizeof(aColor)];
strcpy(color,aColor);
}
}
Shape::Shape(const Shape & otherShape){ // Copy constructor
if(strcmp(otherShape.getColor(),"red")!=0 && strcmp(otherShape.getColor(),"green")!=0 && strcmp(otherShape.getColor(),"blue")!=0)
throw "Exception: color must be red green or blue";
else{
color = new char[sizeof(otherShape.getColor())];
strcpy(color,otherShape.getColor());
}
}
Shape::~Shape(){
delete color;
}
const char * Shape:: getColor()const{
return color;
}
void Shape::printShape(ostream&)const{cout << color;}
// Redefined in Square, Circle & OrthogonalTriangle classes