COP3530/Project3/Project3.cpp
2023-06-23 19:29:02 -04:00

92 lines
1.9 KiB
C++

//Corey Williams
//COP3530 01Z
//Project 4
/*Write a C++ or Java application that creates a linked list of Circle objects/structures (i.e., class must be created).
The application can use the "IntSLLNode" and "IntSLList" classes (pp. 78 - 83) as a guide.
The application must provide the following features.
Allow insertion of multiple "Circle" objects/structures.
The Circle contains a "radius" data member.
The Circle also uses functions/methods "setRadius", "getRadius" and calculateArea (returns a double data type).
Invoke a method/function "DisplayAllElements" (i.e., must be written, traversal required; refer to "isInList" method, pg. 80) that receives
a "reference/pointer" formal parameter. This formal parameter specifies the "head" of the list.
The function/method must display all elements "position", "radius" , and "area"
*/
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
using namespace std;
class Circle {
private:
double radius;
public:
Circle(double r) {
radius = r;
}
double getRadius() {
return radius;
}
void setRadius(double r) {
radius = r;
}
double calculateArea() {
return M_PI * radius * radius;
}
};
class CirSLLNode {
public:
CirSLLNode() {
next = 0;
}
CirSLLNode(int el, CirSLLNode* ptr = 0) {
info = el; next = ptr;
}
int info;
CirSLLNode* next;
};
class CirSLList {
public:
CirSLList() {
head = tail = 0;
}
~CirSLList();
int isEmpty() {
return head == 0;
}
void addNode(Circle);
private:
CirSLLNode* head, * tail;
};
int main()
{
double r;
string userResp;
do {
cout << "Enter radius for first circle: ";
cin >> r;
Circle tmpCir(r);
//add tmpCir to linked list
cout << "Would you like to add another circle? Y/N: ";
cin >> userResp;
} while (userResp != "N" and userResp != "n");
}