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 A. Extend the driver class to do the following: Declare a vector of circles Call a function with signature inputData(vector &, string filename) that reads data from a file called dataLab4.txt into the vector. The following 3-5 are done in this function Use istringstream to create an input string stream called instream. Initialize it with each string that is read from the data file using the getline method. Read the coordinates for the center and the radius from instream to create the circles Include a try catch statement to take care of the exception that would occur if there was a file open error. Display the message “File Open Error” and exit if the exception occurs Display all the circles in this vector using the toString method Use an iterator to iterate through the vector to display these circles Display the count of all the circles in the vector using the getCount method Display the count of all the circles in the vector using the vector size method -> Erase all circles which have a radius greater than 8 -> Display the number of circles remaining using vector size method -> Display all the circles remaining using toString() -> create Circle object circle1 at (3,4) and radius 7 -> create a Circle object circle2 at (-2,-4) and radius 4 -> insert these circles into the vector at positions 2 and 3 respectively -> Display the vector of circles -> Write a simple destructor in the Circle.cpp class that simple displays “In Destructor” B. Write functions in your main driver cpp file that perform the actions 10-17 Your code should be modular and your main program should consist primarily of function calls
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
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
|
A. Extend the driver class to do the following:
- Declare a
vector of circles - Call a function with signature inputData(vector<Circle> &, string filename) that reads data from a file called dataLab4.txt into the vector. The following 3-5 are done in this function
- Use istringstream to create an input string stream called instream. Initialize it with each string that is read from the data file using the getline method.
- Read the coordinates for the center and the radius from instream to create the circles
- Include a try catch statement to take care of the exception that would occur if there was a file open error. Display the message “File Open Error” and exit if the exception occurs
- Display all the circles in this vector using the toString method
- Use an iterator to iterate through the vector to display these circles
- Display the count of all the circles in the vector using the getCount method
- Display the count of all the circles in the vector using the vector size method
- -> Erase all circles which have a radius greater than 8
- -> Display the number of circles remaining using vector size method
- -> Display all the circles remaining using toString()
- -> create Circle object circle1 at (3,4) and radius 7
- -> create a Circle object circle2 at (-2,-4) and radius 4
- -> insert these circles into the vector at positions 2 and 3 respectively
- -> Display the vector of circles
- -> Write a simple destructor in the Circle.cpp class that simple displays
“In Destructor”
B. Write functions in your main driver cpp file that perform the actions 10-17 Your code should be modular and your main program should consist primarily of function calls
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images