This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolygon.h
143 lines (131 loc) · 4.62 KB
/
polygon.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* @file: polygon.h
* @type: C++ (header file)
* @date: 01_AUGUST_2022
* @author: Karlina Ray Beringer
* @license: PUBLIC_DOMAIN
*/
/**
* If polygon.h has not already been linked to a source file (.cpp),
* then link this header file to the source file(s) which include this header file.
*/
#ifndef POLYGON_H
#define POLYGON_H
/**
* Include the C++ header file which contains preprocessing directives,
* variable declarations, and function prototypes for the POINT class.
*/
#include "point.h"
/**
* Include the C++ library for instantiating strings.
*/
#include <string>
/**
* POLYGON is abstract class whose members are the essential components of polygons
* such as TRILATERAL, RIGHT_TRILATERAL, QUADRILATERAL, TRAPEZOID, RECTANGLE, and SQUARE.
*
* An abstract class has at least one virtual function.
*
* The POLYGON class includes the POINT class via composition and
* not via inheritance.
*
* Class members which are set to the protected access specifier
* are accessible to the encompassing base class and to classes which
* are derived from that base class.
*
* Class members which are set to the private access specifier
* are only accessible to their ecompassing base class.
*
* Class members which are set to the public access specifier
* are accessible to any scope within the program where
* the base class and its derived classes are implemented.
*/
class POLYGON
{
protected:
/**
* category is a description of the POLYGON instance.
* category is set to a const (i.e. const (i.e. immutable)) value.
*/
const std::string category = "POLYGON";
/**
* color is an arbitrary value.
* color is used to demonstrate how abstract constructors work.
*/
std::string color;
public:
/**
* The default POLYGON constructor sets the color value to some arbitrary value.
*
* Note that the POLYGON cannot be instantiated as an object which takes
* up some allotment of physical memory because the POLYGON class is
* abstract.
*
* This constructor is implemented only by classes which are
* descendents of the POLYGON class.
*
* It is possible, however, to make POLYGON-type pointers which
* store the memory of objects which are instantiated from classes
* which are derived from the POLYGON class. (See the example below).
*
******************************************************************************
*
* Source Code Example of how to indirectly call the print method of POLYGON...
*
******************************************************************************
*
* // Does not work because POLYGON is an abstract class.
* // POLYGON polygon;
*
* // Can point to instances of non-abstract derived classes of
* // POLYGON such as QUADRILATERAL.
* POLYGON * pointer_to_polygon;
*
* // Assign memory to a dynamic QUADRILATERAL instance
* // (i.e. and dynamic implies that the variable was assigned memory during
* // program runtime instead of during program compile time).
* pointer_to_polygon = new QUADRILATERAL;
*
* // Indirectly call the POLYGON print method.
* pointer_to_polygon -> print(output);
*
******************************************************************************
*
* Source Code Example output...
*
******************************************************************************
*
* ---------------------
* memory_address := 0x56046761b4b0.
* category := POLYGON.
* color := orange.
* ---------------------
*
******************************************************************************
*/
POLYGON();
/**
* The virtual methods get_area() and get_perimeter() must be defined by
* classes which are derived from POLYGON.
*/
virtual double get_area() = 0;
virtual double get_perimeter() = 0;
/**
* The descriptor method prints a description of the POLYGON to the output stream.
* If no parameter is supplied, output is set to the command line.
*/
void print(std::ostream & output = std::cout);
/**
* The friend function is an alternative to the print method.
* The friend function overloads the ostream operator (i.e. <<).
*
* The friend function is not a member of the POLYGON class,
* but it does have access to all ot the members of POLYGON as
* though it were a member function of the POLYGON class.
*/
friend std::ostream & operator << (std::ostream & output, POLYGON & polygon);
};
/**
* End of header file
*/
#endif