Extend the code from Lab5A. Use the same UML as below and make extensions as necessary
Circle |
-int x //x coord of the center -int y // y coord of the center -int radius -static int count // static variable to keep count of number of circles created |
+ Circle() //default constructor that sets origin to (0,0) and radius to 1 +Circle(int x, int y, int radius) // regular constructor +getX(): int +getY(): int +getRadius(): int +setX(int newX: void +setY(int newY): void +setRadius(int newRadius):void +getArea(): double // returns the area using formula pi*r^2 +getCircumference // returns the circumference using the formula 2*pi*r +toString(): String // return the circle as a string in the form (x,y) : radius +getDistance(Circle other): double // * returns the distance between the center of this circle and the other circle +moveTo(int newX,int newY):void // * move the center of the circle to the new coordinates +intersects(Circle other): bool //* returns true if the center of the other circle lies inside this circle else returns false +resize(double scale):void// * multiply the radius by the scale +resize(int scale):Circle // * returns a new Circle with the same center as this circle but radius multiplied by scale +getCount():int //returns the number of circles created //note that the resize function is an overloaded function. The definitions have different signatures |
int main(){
// #include
// declare two pointers to circles and create them using “new ” memory from the heap
Circle *One = new Circle(0,0,0); // new gets memory for the circle object from the heap. The circle object is constructed by calling the constructor Circle(0,0,0) and the address of this object is stored in the memory location called One.
Circle *Two = new Circle(1,1,1);
if (One->greaterThan(Two))
std::cout<<” Circle One is bigger “<<>
else
std::cout<<” Circle Two is bigger “<<>
// create an array of pointers to circles
Circle *circlePointerArray[SIZE];
//populate the pointer array with circles from the data file and return the number of circles created
int count = inputData(circlePointerArray, “dataLab4.txt”);
//rest of the code
}
**************** Static Function in Driver ************************
//pointer to pointer works
//Circle * circlePointer[] of course works
int inputData(Circle **circlePointerArray, string filename) // function header for inputting data from data file into Circle array
*****************Instance Method in Circle Class*********************
bool Circle::greaterThan(Circle * other){ // method that compares two circles using radius as key and
return this->radius > other->getRadius(); // returns true if “this circle” is greater than the “other circle”.
// Note the use of ->
}
Testing and Verification
Test your program thoroughly. Make sure that it compiles and runs correctly. I will be inspecting your code to make sure that it addresses the prompt correctly. So it is not sufficient for you to demonstrate that the output matches the required one.
Your output needs to look like this
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more