Repository navigation
Expand file tree
/
Copy pathshape_Main.cpp
More file actions
179 lines (158 loc) · 4.82 KB
/
Copy pathshape_Main.cpp
File metadata and controls
179 lines (158 loc) · 4.82 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/************************************************************/
/* Author: Julian Memis */
/* Major: Computer Science */
/* Creation Date: November 28th, 2023 */
/* Due Date: December 3rd, 2023 */
/* Course: CS100-01 */
/* Professor Name: Professor Shimkanon */
/* Assignment: #6 Classes (Shape) */
/* Filename: shape_Main.cpp */
/* Purpose: This program allows the user to add a shape */
/* to a linked list. The user can then choose various actions from a menu */
/* and add a shape, delete a shape, or receive calculations of the shapes (perimeter and area). */
/************************************************************/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
#include "shape.hpp"
#include "LinkedList.hpp"
using namespace std;
int main()
{
//Variables:
char menuChoice; //Menu Choice
string shapeName; //Shape name user selected
int numSides; //Number of sides
float sideLength; //Length of sides
Shape myShape; //Shape object
LinkedList<Shape> list; //Create Linked List
//Display First Menu:
cout << "I) Insert shape object" << endl;
cout << "E) Exit the program" << endl;
cout << "- User Choice: ";
cin >> menuChoice;
//Insert Shape or Exit:
if(menuChoice == 'I')
{
cout << "--> Insert\n";
cout << "\nEnter a new name for the shape: ";
cin >> shapeName;
cout << "Enter the number of sides: ";
cin >> numSides;
while(numSides < 3) //Shape side check
{
cout << "Shape must have 3 or more sides.\n\n" << "Number of sides: ";
cin >> numSides;
}
cout << "Enter the length of each side: ";
cin >> sideLength;
}
else if (menuChoice == 'E')
{
cout << "--> Exit";
return 0;
}
else
{
cout << "--> Invalid Selection. Program Shutdown";
return 0;
}
//Set Shape and add to Linked List:
myShape.setSides(numSides);
myShape.setLength(sideLength);
myShape.setName(shapeName);
list.insertShape(myShape); //Insert Shape
//Menu:
do {
cout << "\nV) View linked list" << endl;
cout << "I) Insert shape object (into linked list)" << endl;
cout << "D) Delete shape object (from linked list)" << endl;
cout << "Q) Query an individual shape" << endl;
cout << "T) Calculate the total perimeter or area of the shapes" << endl;
cout << "E) Exit the program" << endl;
cout << "\n- User Choice: ";
cin >> menuChoice;
switch(menuChoice)
{
case 'V': //View
cout << "--> View\n" << endl;
list.printList();
break;
case 'I': //Insert
cout << "--> Insert" << endl;
cout << "\nEnter a new name for the shape: ";
cin >> shapeName;
cout << "Enter the number of sides: ";
cin >> numSides;
while(numSides < 3) //Shape side check
{
cout << "Shape must have 3 or more sides. \n\n" << "Number of sides: ";
cin >> numSides;
}
cout << "Enter the length of each side: ";
cin >> sideLength;
//Set Shape and add to Linked List:
myShape.setSides(numSides);
myShape.setLength(sideLength);
myShape.setName(shapeName);
list.insertShape(myShape);//Insert Shape
break;
case 'D': //Delete
cout << "--> Delete\n\n" << endl;
cout << "Enter the name of the shape you want to delete: ";
cin >> shapeName;
myShape = list.findNode(shapeName);
list.deleteNode(myShape);
break;
case 'Q': //Query
cout << "--> Query\n\nEnter the name of the shape you want: ";
cin >> shapeName;
myShape = list.findNode(shapeName);
//Menu Query:
do {
cout << "\nP) Perimeter" << endl;
cout << "A) Area" << endl;
cout << "B) Back" << endl;
cout << "E) Exit" << endl;
cout << "\n- User Choice: ";
cin >> menuChoice;
switch(menuChoice)
{
case 'P': //Perimeter
cout << "--> Perimeter \n\nPerimeter: " << myShape.computePerimeter(myShape.getSides(), myShape.getLength()) << "\n";
break;
case 'A': //Area
cout << "--> Area \n\nArea: " << myShape.computeArea(myShape.getSides(), myShape.getLength()) << "\n";
break;
case 'B': //Back
cout << "--> Back \n\n";
break;
case 'E': //Exit
cout << "--> Exit";
return 0;
}
} while(menuChoice != 'B');
break;
case 'T': //Calculate
cout << "--> Calculate\n\nCalculate total area (A) or total perimeter (P): ";
cin >> menuChoice;
if(menuChoice == 'A')
{
cout << "--> Area\n";
list.totalArea();
}
else if(menuChoice == 'P')
{
cout << "--> Perimeter\n";
list.totalPerimeter();
}
break;
default:
cout << "\n--> Invalid Selection. Program Shutdown" << endl;
return 0;
}
} while(menuChoice != 'E');
return 0;
}