C++ make extensions to my code to do the following: 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 c-e 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 Clear the vector Create a circle called c using the default constructor Display the current count of all the circles using the getCount method on c Display the current count of all the circles using the vector size method   Write functions in your main driver cpp file that perform the actions b-l. Your code should be modular and your main program should consist primarily of function calls

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
100%

C++

make extensions to my code to do the following:

  1. 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 c-e 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. Clear the vector
    11. Create a circle called c using the default constructor
    12. Display the current count of all the circles using the getCount method on c
    13. Display the current count of all the circles using the vector size method

 

  1. Write functions in your main driver cpp file that perform the actions b-l. Your code should be modular and your main program should consist primarily of function calls

My code:

Circle:

#include <iostream>
#include "CircleHeader.h"
#include <string.h>
#include <math.h>
using namespace std;

//default constructor
Circle::Circle()
{
x=0;
y=0;
radius=1;
}
//regular constructor
Circle::Circle(int x, int y, int radius)
{
this->x=x;
this->y=y;
this->radius=radius;
}

//getters
int Circle::getX()
{
return x;
}
int Circle::getY()
{
return y;
}
int Circle::getRadius()
{
return radius;
}

//setters
void Circle::setX(int newX)
{
x=newX;
}
void Circle::setY(int newY)
{
y=newY;
}
void Circle::setRadius(int newRadius)
{
radius=newRadius;
}

//def to find area
double Circle::getArea()
{
double area=M_PI*radius*radius;
return area;
}
//def to find Circumference
double Circle::getCircumference()
{
double Circumference=2*M_PI*radius;
return Circumference;
}

//def to return cirlce as a string
string Circle::toString()
{
string s;
s="("+to_string(getX())+","+to_string(getY())+"):"+to_string(getRadius());
return s;
}

double Circle::getDistance(Circle other)
{
    return sqrt((x - other.getX())*(x - other.getX()) + (y - other.getY()) * (y - other.getY()));
}

void Circle::moveTo(int newX,int newY)
{
    x += newX;
    y += newY;
}


bool Circle::intersects(Circle other)
{
        int radSumSq = (radius + other.getRadius()) * (radius + other.getRadius());
        if (getDistance(other) >= radSumSq)
            return true;
        else
            return false;
}
void Circle::resize(double scale)
{
    radius = radius*scale;
}

Circle Circle::resize(int scale)
{
    Circle c(x, y, (radius*scale));
    return c;
}

 

CircleHeader:

#ifndef CircleHeader_H

#define CircleHeader_H
#include<string.h>
#include<iostream>
using namespace std;

//declaring class
class Circle
{
//private
int x;
int y;
int radius;
public:
//default constructor
Circle();
  
//p constructor
Circle(int X, int Y, int Radius);
  
//declaration of setters
int getX();
int getY();
int getRadius();
  
//declaration of getters
void setX(int newX);
void setY(int newY);
void setRadius(int newRadius);
  
//declaration of functions to find area and Circumference
double getArea();
double getCircumference();
string toString();
double getDistance(Circle other);
void moveTo(int newX,int newY);
bool intersects(Circle other);
void resize(double scale);
Circle resize(int scale);
};

#endif

Main CPP:

#include "CircleHeader.h"
#include <iostream>

using namespace std;

int main()
{
//first circle
Circle circleOne;
  
Circle circleTwo(0,0,4);
  
cout<<"Circle one is : "<<"("<<circleOne.toString()<<endl;
cout<<"Circle Two is : "<<"("<<circleTwo.toString()<<endl;
  
cout<<"Distance Between Circle one and Circle two: "<<circleOne.getDistance(circleTwo)<<endl;Circle circleThree = circleTwo.resize(10);
  
cout<<"circle Three is : "<<circleThree.toString()<<endl;

circleThree.moveTo(4,5);

cout<<"Circle Three is : "<<"("<<circleThree.toString()<<endl;


cout<<"circleTwo intersects circleThree: "<<circleTwo.intersects(circleThree)<<endl;


Circle circleFour(4,5,1);
cout<<"Circle Four is : "<<"("<<circleFour.toString()<<endl;


cout<<"circleFour intersects circleOne: "<<circleFour.intersects(circleOne)<<endl;


circleThree.resize(9.5);


cout<<"circle Three is : "<<circleThree.toString()<<endl;

//showing area of all circles
cout<<"Area of circle One is : "<<circleOne.getArea()<<endl;
cout<<"Area of circle Two is : "<<circleTwo.getArea()<<endl;
cout<<"Area of circle Three is : "<<circleThree.getArea()<<endl;
  
//showing Circumference of all circles
cout<<"Circumference of circle One is : "<<circleOne.getCircumference()<<endl;
cout<<"Circumference of circle Two is : "<<circleTwo.getCircumference()<<endl;
cout<<"Circumference of circle Three is : "<<circleThree.getCircumference()<<endl;
return 0;
}

 

Output must look like attached picture

 

> ./main
The circles created are:
(0,0):4
(0,0):6
(-2,-9):6
(4,5):7
(7,8):9
The number of circles, using getCount method is 5
The numher of circles, using vetor size method is 5
Erasing the Vector of Circles
Creating a new Circle
The number of circles, using getCount method is 6
The number of circles remaining is 0
Transcribed Image Text:> ./main The circles created are: (0,0):4 (0,0):6 (-2,-9):6 (4,5):7 (7,8):9 The number of circles, using getCount method is 5 The numher of circles, using vetor size method is 5 Erasing the Vector of Circles Creating a new Circle The number of circles, using getCount method is 6 The number of circles remaining is 0
Expert Solution
Step 1

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

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
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