-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.cpp
More file actions
64 lines (54 loc) · 1.66 KB
/
Shape.cpp
File metadata and controls
64 lines (54 loc) · 1.66 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "Shape.h"
#include <iostream>
#include <sstream>
using namespace std;
int Shape::nextId = 1;
Shape::Shape(const string &nameOfShape, const string &desc) : shapeName(nameOfShape), description(desc), idNum(nextId++) {
if (desc.empty())
description = "Generic " + shapeName;
}
const Shape &Shape::operator=(const Shape &rhs) {
if (this == &rhs) return *this;
shapeName = rhs.shapeName;
description = rhs.description;
return *this;
}
int Shape::getIdNum() const {
return idNum;
}
string Shape::getShapeName() const {
return shapeName;
}
string Shape::getDescription() const {
return description;
}
string Shape::toString() const {
string temp{"Shape Information\n-----------------"};
temp += "\nStatic Type: ";
temp.append(typeid(this).name());
temp += "\nDynamic Type: ";
temp.append(typeid(*this).name());
temp += "\nShape name: " + getShapeName();
temp += "\nDescription: " + getDescription();
temp += "\nid: ";
temp.append(to_string(getIdNum()));
return temp;
}
string Shape::doubleToString(double d, int p) const {
ostringstream s;
s.precision(p);
s << fixed << d;
string temp{s.str()};
return temp;
}
ostream &operator<<(ostream &ostr, const Shape &rhs) {
const Shape *rhsPtr = &rhs;
ostr << "Shape Information"
<< "\n-----------------"
<< "\nStatic Type: " << typeid(rhsPtr).name()
<< "\nDynamic Type: " << typeid(*rhsPtr).name()
<< "\nGeneric name: " + rhs.getShapeName()
<< "\nDescription: " + rhs.getDescription()
<< "\nid: " + to_string(rhs.getIdNum());
return ostr;
}