This repository was 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.cpp
101 lines (96 loc) · 3.19 KB
/
polygon.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @file: polygon.cpp
* @type: C++ (source file)
* @date: 01_AUGUST_2022
* @author: Karlina Ray Beringer
* @license: PUBLIC_DOMAIN
*/
/**
* Include the C++ header file which contains preprocessing directives,
* variable declarations, and function prototypes for the POLYGON class.
*/
#include "polygon.h"
/**
* 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::POLYGON()
{
color = "orange";
}
/**
* The virtual methods get_area() and get_perimeter() must be defined by
* classes which are derived from POLYGON.
*/
double POLYGON::get_area() { return 0.0; }
double POLYGON::get_perimeter() { return 0.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 POLYGON::print(std::ostream & output)
{
output << "\n\n---------------------";
output << "\nmemory_address := " << this << ".";
output << "\ncategory := " << category << ".";
output << "\ncolor := " << color << ".";
output << "\n---------------------";
}
/**
* 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.
*/
std::ostream & operator << (std::ostream & output, POLYGON & polygon)
{
polygon.print(output);
return output;
}