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"

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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:

  1. Declare a vector of circles
  2. 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
  3. 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.
  4. Read the coordinates for the center and the radius from instream to create the circles
  5. 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
  6. Display all the circles in this vector using the toString method
  7. Use an iterator to iterate through the vector to display these circles
  8. Display the count of all the circles in the vector using the getCount method
  9. Display the count of all the circles in the vector using the vector size method
  10. -> Erase all circles which have a radius greater than 8
  11. -> Display the number of circles remaining using vector size method
  12. -> Display all the circles remaining using toString()
  13. -> create Circle object circle1 at (3,4) and radius 7
  14. -> make a Circle object circle2 at (-2,-4) and radius 4
  15. -> insert these circles into the vector at positions 2 and 3 respectively
  16. -> Display the vector of circles
  17. -> 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

Your output without destructor message needs to look like this
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
The circles created are:
(0,0):4
(0,0):12
(-2,-9):11
(4,5):7
(7,8):9
(2,-5):11
The number of circles, using getCount method is 6
The number of circles, using vetor size method is 6
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
The number of circles remaining is 2
The circles left are :
The saber of clacles sining in 2
Your output with the destructor message needs to look like this. The number of destructor message will vary depending
on the location of memory release in your code
(0,0):4
(4,5):7
Inside Destructor
Inside Destructor
The circles vector now has these circles :
the eireles vector now has these clecles
(0,0):4
(3,4):7
(-2,-4):4
(4,5):7
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Inside Destructor
Transcribed Image Text:Your output without destructor message needs to look like this Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor The circles created are: (0,0):4 (0,0):12 (-2,-9):11 (4,5):7 (7,8):9 (2,-5):11 The number of circles, using getCount method is 6 The number of circles, using vetor size method is 6 Inside Destructor Inside Destructor Inside Destructor Inside Destructor The number of circles remaining is 2 The circles left are : The saber of clacles sining in 2 Your output with the destructor message needs to look like this. The number of destructor message will vary depending on the location of memory release in your code (0,0):4 (4,5):7 Inside Destructor Inside Destructor The circles vector now has these circles : the eireles vector now has these clecles (0,0):4 (3,4):7 (-2,-4):4 (4,5):7 Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor Inside Destructor
Circle.h:
#ifndef CIRCLE_H
#define CIRCLE_H
#include <iostream>
#include <cmath>
using namespace std;
class Circle{
private:
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
public:
Circle(); // default constructor that sets origin to (0,0) and radius to 1
Circle(int x, int y, int radius); // regular constructor
int getX();
int getY();
int getRadius();
void setX(int newX);
void setY(int newY);
void setRadius(int newRadius);
double getArea(); // returns the area
double getCircumference(); // returns the circumference
string toString(); // returns the circle as a string in the form (x,y): radius
double getDistance (Circle other); //returns the distance between the center of this circle and the other circle
void moveTo(int newX,int newY); // move the center of the circle to the new coordinates
bool intersects (Circle other); // returns true if the center of the other circle lies inside this circle else returns false
void resize(double scale); // multiply the radius by the scale
Circle resize(int scale); // returns a new Circle with the same center as this circle but radius multiplied by scale
int getCount(); //returns the number of circles created
};
#endif
Transcribed Image Text:Circle.h: #ifndef CIRCLE_H #define CIRCLE_H #include <iostream> #include <cmath> using namespace std; class Circle{ private: 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 public: Circle(); // default constructor that sets origin to (0,0) and radius to 1 Circle(int x, int y, int radius); // regular constructor int getX(); int getY(); int getRadius(); void setX(int newX); void setY(int newY); void setRadius(int newRadius); double getArea(); // returns the area double getCircumference(); // returns the circumference string toString(); // returns the circle as a string in the form (x,y): radius double getDistance (Circle other); //returns the distance between the center of this circle and the other circle void moveTo(int newX,int newY); // move the center of the circle to the new coordinates bool intersects (Circle other); // returns true if the center of the other circle lies inside this circle else returns false void resize(double scale); // multiply the radius by the scale Circle resize(int scale); // returns a new Circle with the same center as this circle but radius multiplied by scale int getCount(); //returns the number of circles created }; #endif
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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

Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY