forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
87 lines (73 loc) · 2.03 KB
/
main.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***************************************************************************
* @file main.cpp
* @author Alan.W
* @date 23 Jan 2014
* @remark This code is for the exercises from C++ Primer 5th Edition
* @note
***************************************************************************/
//
// Exercise 15.21:
// Choose one of the following general abstractions containing a family of
// types (or choose one of your own). Organize the types into an inheritance
// hierarchy:
// (a) Graphical file formats (such as gif, tiff, jpeg, bmp)
// (b) Geometric primitives (such as box, circle, sphere, cone)
// (c) C++ language types (such as class, function, member function)
//
// Exercise 15.22:
// For the class you chose in the previous exercise, identify some of the
// likely virtual functions as well as public and protected members.
//
#include <iostream>
#include <string>
#include "quote.h"
#include "bulk_quote.h"
#include "limit_quote.h"
#include "disc_quote.h"
// just for 2D shape
class Shape
{
public:
typedef std::pair<double, double> Coordinate;
Shape() = default;
Shape(const std::string& n) :
name(n) { }
virtual double area() const = 0;
virtual double perimeter() const = 0;
virtual ~Shape() = default;
private:
std::string name;
};
class Rectangle : public Shape
{
public:
Rectangle() = default;
Rectangle(const std::string& n,
const Coordinate& a,
const Coordinate& b,
const Coordinate& c,
const Coordinate& d) :
Shape(n), a(a), b(b), c(c), d(d) { }
~Rectangle() = default;
protected:
Coordinate a;
Coordinate b;
Coordinate c;
Coordinate d;
};
class Square : public Rectangle
{
public:
Square() = default;
Square(const std::string& n,
const Coordinate& a,
const Coordinate& b,
const Coordinate& c,
const Coordinate& d) :
Rectangle(n, a, b, c, d) { }
~Square() = default;
};
int main()
{
return 0;
}