C++ don't use previous answers they have missing info Please expand my code and call the destructor that prints something a bunch of times and follow guidelines. TYSM 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 -> make 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"
C++
don't use previous answers they have missing info
Please expand my code and call the destructor that prints something a bunch of times and follow guidelines. TYSM
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
- -> make 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
TXT FILE:
0 0 4
0 0 12
-2 -9 11
4 5 7
7 8 9
2 -5 11
Previous lab code:
my code:
Main.cpp:
#include "Circle.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
using namespace std;
void inputData(vector<Circle> &circles, string fileName);
int main()
{
vector<Circle> circles;
inputData(circles, "dataLab4.txt");
vector<Circle>::iterator circleIterator;
cout << "The circles created are:" << endl;
for(circleIterator = circles.begin(); circleIterator < circles.end(); circleIterator++) {
cout << (*circleIterator).toString() << endl;
}
cout << "The number of circles, using getCount method is " << circles[0].getCount() << endl;
cout << "The number of circles, using vector size method is " << circles.size() << endl;
cout << "Erasing the Vector of Circles" << endl;
circles.clear();
cout << "Creating a new Circle" << endl;
Circle c;
cout << "The number of circles, using getCount method is " << c.getCount() << endl;
cout << "The number of circles remaining is " << circles.size() << endl;
return 0;
}
void inputData(vector<Circle> &circles, string fileName){
try{
ifstream inFile;
inFile.open(fileName);
string str;
while (!inFile.eof())
{
getline(inFile,str);
if(str == ""){
break;
}
istringstream instream(str);
int x, y, radius;
instream >> x >> y >> radius;
Circle circle(x,y,radius);
circles.push_back(circle);
}
inFile.close();
}catch(std::exception const& e){
cout << "File open error" << e.what() << endl;
}
}
Circle.h:
Is in attachments!
Circle.cpp:
#include "Circle.h"
int Circle::count = 0;
Circle :: Circle(){
this->x = 0;
this->y = 0;
this->radius = 1;
Circle::count += 1;
}
Circle :: Circle(int x, int y, int radius){
this->x = x;
this->y = y;
this->radius = radius;
Circle::count += 1;
}
int Circle :: getX(){
return x;
}
int Circle :: getY(){
return y;
}
int Circle :: getRadius(){
return radius;
}
void Circle :: setX(int newX){
this->x = newX;
}
void Circle :: setY(int newY){
this->y = newY;
}
void Circle :: setRadius(int newRadius){
this->radius = newRadius;
}
double Circle :: getArea(){
return 3.14 * radius * radius;
}
double Circle :: getCircumference(){
return 2 * 3.14 * radius;
}
string Circle :: toString(){
return "(" + to_string(x) + "," + to_string(y) +")" +":"+to_string(radius);
}
double Circle :: getDistance(Circle other){
return sqrt(pow(other.getX() - this->x, 2 ) + pow(other.getY() - this->y, 2 ));
}
void Circle :: moveTo(int newX,int newY){
this->x = newX;
this->y = newY;
}
bool Circle :: intersects(Circle other){
return (this->getDistance(other)) < (this->radius + other.getRadius());
}
void Circle :: resize(double scale){
this->radius *= scale;
}
Circle Circle :: resize(int scale){
return Circle(this->x,this->y,this->radius * scale);
}
int Circle :: getCount(){
return count;
}
OUTPUT MUST LOOK LIKE THIS:
IN ATTACHMENTS



Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images

The code has errors and does not run, could you please fix and resubmit. Thanks.








