-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshape.cpp
More file actions
49 lines (37 loc) · 897 Bytes
/
shape.cpp
File metadata and controls
49 lines (37 loc) · 897 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "shape.h"
#include <vector>
#include <sstream>
using std::vector;
Shape::Shape(string name)
:_name(name), _boundingBox(0, 0, 0, 0){}
string Shape::name() {
return _name;
}
string Shape::print() {
return name();
}
int Shape::area() const {
return 0;
}
//Global Functions
string printShape(vector<Shape *> shapes){
std::ostringstream oss;
for (int i = 0; i < shapes.size(); ++i)
oss << shapes[i]->print() << "\n";
return oss.str();
}
int totalArea(vector<Shape *> shapes){
int area = 0;
for (int i = 0; i < shapes.size(); ++i)
area += shapes[i]->area();
return area;
}
double areaSum(vector<Shape*> shapes){
double returnArea = 0;
for (vector<Shape*>::iterator iterator = shapes.begin(); iterator != shapes.end(); iterator++)
returnArea += (*iterator)->area();
return returnArea;
}
ostream & operator << (ostream & os, Shape & s) {
return os << s.print();
}