Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use the same Circle UML as below and make extensions as marked and as needed. Given below is a UML for the Painting Class. You will need to write PaintingHeader.h and Painting.cpp. The Painting Class UML contains a very basic skeleton. You will need to flesh out this UML and add more instance variables and methods as needed.
You do NOT need to write a driver. Use the one provided in the template. Name it PaintingMain.cpp
-----------------main.cpp-----------
#include
#include "Circle.h"
#include
#include
#include
#include
#include
#include
#include "Painting.h"
using namespace std;
int main(){
shared_ptr circleOnePtr = make_shared(0,0,15);
shared_ptr circleTwoPtr = make_shared(0,0,7);
// < is the overloaded less than operator
if (!(*circleOnePtr < circleTwoPtr))
cout<<" Circle One is bigger
"< else
cout<<" Circle Two is bigger
"<
Painting p("dataLab7.txt");
cout<<"Printing Painting p"<
cout< Painting q=p;
cout<<"Printing Painting q"<
cout<
cout<<"Changing Painting q"<
q.setRadius(0,99);
cout<<"Printing Painting p"<
cout<
cout<<"Printing Painting q"< cout<
return 0;
}
--------------circle.h--------------
#include
#include
#include
#include
using namespace std;
#ifndef CIRCLE_H// this is optional
#define CIRCLE_H // works with or without it
class Circle{
//private
static int count;
int radius;
int x,y;
public:
Circle();
-----------painting.cpp-----------
#include "Circle.h"
#include
#include
class Painting{
vector> paintingVector;
Painting(){
}
public:
//regular constructor
Painting(string filename){
ifstream inputFile(filename);
istringstream instream;
string data;
int count =0;
int x,y,radius;
try{
if (inputFile){
while (!inputFile.eof()){
getline(inputFile,data);
istringstream
instream(data);
instream>>x;
instream>>y;
instream>>radius;
shared_ptr circle =
make_shared(x,y,radius);
paintingVector.push_back(circle);
count++;
}
}
else throw string("File Not Found");
}
catch (string message){
cout< exit(0);
}
}
public:
//returns a circle at the given index in the painting vector
shared_ptr getCircle(int index) const{
return paintingVector[index];
}
//gets the size of the painting vector
int getSize()const{
return paintingVector.size();
}
//copy constructor for the Painting Class
Painting(const Painting &other) {
// ****write this code
}
//returns a string containing the painting vector
string toString(){
//****write this code
}
void setRadius(int index,int radius ){
paintingVector[index]->setRadius(radius);
}
~Painting(){
//delete paintingVector;
}
};
--------------------painting.h-----------
#include "Circle.h"
#include
#include
class Painting{
vector> paintingVector;
Painting();
public:
//regular constructor
Painting(string filename){
ifstream inputFile(filename);
public:
//try to remove const and see what happens
shared_ptr getCircle(int index) const{
return paintingVector[index];
}
//try to remove const and see what happens
int getSize()const;
//copy constructor for the Painting class
Painting(const Painting &other);
}
//return a string of the painting
string toString();
void setRadius(int index,int radius ){
paintingVector[index]->setRadius(radius);
}
//destructor
~Painting(){
//delete paintingVector;
}
};
Circle(int xcoord,int ycoord, int r);
Circle(const shared_ptr &other);
int getY();
int getX();
int getRadius();
static int getCount();
double getArea();
double getCircumference();
double getDistance(Circle other);
bool intersects(Circle other);
Circle resize(int scale);//to copy self to other;
void resize(double scale);//for self
void setX(int xcoord);
void setY(int xcoord);
void setRadius(int r);
bool greaterThan(shared_ptr other);
bool operator<(shared_ptr other);
string toString();
~Circle();
//regular functions
//void inputData(vector);
};
#endif
-------------circle.cpp-----------------
//#include
//#include // no need for this as is in header
#include "Circle.h"
#include
#include
Circle::Circle(){
//if you have regular constructor you must
//define default constructor
//C++ will not auto create for you
x=0;
y=0;
radius=1;
count++;
}
Circle::Circle(int xcoord,int ycoord, int r){
x=xcoord;
y=ycoord;
radius=r;
count++;
}
//copy constructor for the Circle Class
//************* Examine this code ********
Circle::Circle( const shared_ptr &other){
shared_ptr temp = make_shared();
temp->setX(other->getX());
temp->setY(other->getY());
temp->setRadius(other->getRadius());
x=temp->getX();
y=temp->getY();
radius=temp->getRadius();
}
int Circle::getX(){
return x;
}
int Circle::getY(){
return y;
}
int Circle::getRadius(){
return radius;
}
int Circle::getCount(){
return count;
}
void Circle::setX(int xcoord){
x=xcoord;
}
void Circle::setY(int xcoord){
x=xcoord;
}
void Circle::setRadius(int r){
radius=r;
}
double Circle::getArea(){
return M_PI*pow(radius,2);
}
double Circle::getCircumference(){
return M_PI*radius/2;
}
double Circle::getDistance(Circle other){
return
sqrt(pow(x-other.getX(),2)+pow((y-other.getY()),2));
}
bool Circle::intersects(Circle other){
return
(this->getDistance(other)<=radius);
}
void Circle::resize(double scale){
radius = scale*radius;
}
Circle Circle::resize(int scale){
Circle c(x,y,radius*scale);
return c;
}
string Circle::toString(){
return "("
+to_string(x)+","+to_string(y)+"):"+to_string(radius);
}
bool Circle::greaterThan(shared_ptr other){
return radius>other->getRadius();
}
bool Circle::operator< (shared_ptr other){
return this->radius<
other->getRadius();
}
Circle::~Circle(){
}
int Circle::count=0;
DataLab7.txt
0 0 4
0 0 12
-2 -9 11
4 5 7
7 8 9
2 -5 11
The output
circle one is bigger
Printing Painting p
[ (0,0):4 (0,0):12 (-2,-9):11 (4,5):7 (7,8):9 (2,-5):11 ]
printing Painting q
[ (0,0):4 (0,0):12 (-2,-9):11 (4,5):7 (7,8):9 (2,-5):11 ]
changing Painting q
printing Painting p
[ (0,0):4 (0,0):12 (-2,-9):11 (4,5):7 (7,8):9 (2,-5):11 ]
printing Painting q
[ (0,0):99 (0,0):12 (-2,-9):11 (4,5):7 (7,8):9 (2,-5):11 ]
///////////////////////////////////// Circle.h
#pragma once
#include<string>
#include <vector>
#include <memory>
#include<iostream>
using namespace std;
#ifndef CIRCLE_H
#define CIRCLE_H
class Circle {
static int count;
int radius;
int x, y;
public:
Circle();
Circle(int xcoord, int ycoord, int r);
Circle(const shared_ptr<Circle>
&other);
int getY();
int getX();
int getRadius();
static int getCount();
double getArea();
double getCircumference();
double getDistance(Circle other);
bool intersects(Circle other);
Circle resize(int scale);
void resize(double scale);
void setX(int xcoord);
void setY(int xcoord);
void setRadius(int r);
bool greaterThan(shared_ptr<Circle>
other);
bool operator<(shared_ptr<Circle>
other);
string toString();
~Circle();
};
#endif
///////////////////////////////////// Circle.cpp
#define _USE_MATH_DEFINES
#include "Circle.h"
#include <cmath>
#include <iostream>
using namespace std;
Circle::Circle()
{
x = 0;
y = 0;
radius = 1;
count++;
}
Circle::Circle(int xcoord, int ycoord, int r)
{
x = xcoord;
y = ycoord;
radius = r;
count++;
}
Circle::Circle(const shared_ptr<Circle> &other)
{
shared_ptr<Circle> temp =
make_shared<Circle>();
temp->setX(other->getX());
temp->setY(other->getY());
temp->setRadius(other->getRadius());
x = temp->getX();
y = temp->getY();
radius = temp->getRadius();
}
int Circle::getX() {
return x;
}
int Circle::getY() {
return y;
}
int Circle::getRadius() {
return radius;
}
int Circle::getCount() {
return count;
}
void Circle::setX(int xcoord) {
x = xcoord;
}
void Circle::setY(int xcoord) {
x = xcoord;
}
void Circle::setRadius(int r) {
radius = r;
}
double Circle::getArea() {
return M_PI*pow(radius, 2);
}
double Circle::getCircumference() {
return M_PI*radius / 2;
}
double Circle::getDistance(Circle other) {
return sqrt(pow(x - other.getX(), 2) + pow((y -
other.getY()), 2));
}
bool Circle::intersects(Circle other) {
return (this->getDistance(other) <=
radius);
}
void Circle::resize(double scale) {
radius = scale*radius;
}
Circle Circle::resize(int scale) {
Circle c(x, y, radius*scale);
return c;
}
string Circle::toString() {
return "(" + to_string(x) + "," + to_string(y) + "):"
+ to_string(radius);
}
bool Circle::greaterThan(shared_ptr<Circle> other) {
return radius>other->getRadius();
}
bool Circle::operator< (shared_ptr<Circle> other) {
return this->radius<
other->getRadius();
}
Circle::~Circle() {
}
int Circle::count = 0;
///////////////////////////////////// Painting.h
#pragma once
#include "Circle.h"
#include <fstream>
#include <sstream>
#include <string>
class Painting {
vector<shared_ptr<Circle>>
paintingVector;
Painting();
public:
Painting(string filename);
shared_ptr<Circle> getCircle(int index)
const;
int getSize()const;
Painting(const Painting &other);
string toString();
void setRadius(int index, int radius);
~Painting();
};
///////////////////////////////////// Painting.cpp
#pragma once
#include "Circle.h"
#include"Painting.h"
#include <fstream>
#include <sstream>
using namespace std;
Painting::Painting(string filename) {
ifstream inputFile(filename);
istringstream instream;
string data;
int count = 0;
int x, y, radius;
try {
if (inputFile.fail() == false)
{
while
(!inputFile.eof()) {
getline(inputFile, data);
istringstream instream(data);
instream >> x;
instream >> y;
instream >> radius;
shared_ptr<Circle> circle =
make_shared<Circle>(x, y, radius);
paintingVector.push_back(circle);
count++;
}
}
else throw string("File Not
Found");
}
catch (string message) {
cout << message <<
endl;
exit(0);
}
}
shared_ptr<Circle> Painting::getCircle(int index) const
{
return paintingVector[index];
}
int Painting::getSize()const {
return paintingVector.size();
}
Painting::Painting(const Painting &other) {
// get vector size
int n = other.getSize();
// clear vector content
paintingVector.clear();
for (int i = 0;i < n;i++) {
int x =
other.getCircle(i)->getX();
int y =
other.getCircle(i)->getY();
int radius =
other.getCircle(i)->getRadius();
// new object create
shared_ptr<Circle> circle =
make_shared<Circle>(x, y, radius);
// add in vector
paintingVector.push_back(circle);
}
}
string Painting::toString() {
string result = "[";
for (shared_ptr<Circle> s_vector :
paintingVector)
{
result +=
s_vector->toString();
result += " ";
}
result += "]";
return result;
}
void Painting::setRadius(int index, int radius) {
paintingVector[index]->setRadius(radius);
}
Painting::~Painting() {
//delete paintingVector;
}
///////////////////////////////////// main.cpp
#include<iostream>
#include "Circle.h"
#include <fstream>
#include <vector>
#include <memory>
#include<cstdlib>
#include <fstream>
#include <sstream>
#include "Painting.h"
using namespace std;
int main() {
shared_ptr<Circle> circleOnePtr =
make_shared<Circle>(0, 0, 15);
shared_ptr<Circle> circleTwoPtr =
make_shared<Circle>(0, 0, 7);
// < is the overloaded less than operator
if (!(*circleOnePtr < circleTwoPtr))
cout << " Circle One is
bigger " << endl;
else
cout << " Circle Two is
bigger " << endl;
Painting p("dataLab7.txt");
cout << "Printing Painting p" <<
endl;
cout << p.toString() << endl;
Painting q = p;
cout << "Printing Painting q" <<
endl;
cout << q.toString() << endl;
cout << "Changing Painting q" <<
endl;
q.setRadius(0, 99);
cout << "Printing Painting p" <<
endl;
cout << p.toString() << endl;
cout << "Printing Painting q" <<
endl;
cout << q.toString() << endl;
system("pause");
return 0;
}
/////////////////////////////////////

![Circle One is bigger Printing Painting p [(0,0):4 (0,0):12 (-2,-9):11 (4,5):7 (7,8):9 (2,-5):11 ] Printing Painting a [(0,0):](http://img.homeworklib.com/questions/4678da00-be68-11eb-abc8-97addebeba44.png?x-oss-process=image/resize,w_560)
![Circle One is bigger Printing Painting p [(0,0):4 (0,0):12 (-2,-9):11 (4,5):7 (7,8):9 (2,-5):11 ] Printing Painting a [(0,0):](http://img.homeworklib.com/questions/46d42d60-be68-11eb-97db-5da4f396369d.png?x-oss-process=image/resize,w_560)
Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use...
Keep getting this error message when trying to compile in main1.cpp. Need help figuring out how to make it compile. Thank you for your time. Error Message: main.cpp:(.text+0x13): undefined reference to `circle::circle()' main.cpp:(.text+0x32): undefined reference to `circle::circle(double)' main.cpp:(.text+0x3e): undefined reference to `circle::getArea() const' main.cpp:(.text+0x53): undefined reference to `circle::getRadius() const' main.cpp:(.text+0xb3): undefined reference to `circle::getArea() const' main.cpp:(.text+0xc8): undefined reference to `circle::getRadius() const' main.cpp:(.text+0x157): undefined reference to `circle::setRadius(double)' main.cpp:(.text+0x163): undefined reference to `circle::getArea() const' main.cpp:(.text+0x178): undefined reference to `circle::getRadius() const' main.cpp:(.text+0x207): undefined...
class Circle { public: enum Color {UNDEFINED, BLACK, BLUE, GREEN, CYAN, RED}; Circle(int = 0, int = 0, double = 0.0, Color = UNDEFINED); void setX(int); void setY(int); void setRadius(double); void setColor(Color); int getX() const; int getY() const; double getRadius() const; Color getColor() const; private: int x; int y; ...
#include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...
Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...
Need C++ Code (Please put //comments on there too) 1. Complete the following code: Design a class called Circle. The class should have an integer member variable named radius and three member functions; setRadius, getRadius, calArea; the functions' prototypes should be done inside the class declaration and the functions' definitions should come after the main function #include <iostream> using namespace std; const double PI = 3.14; // fill in the declaration of the class Circle here int main() { Circle...
C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class...
Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant...
A library maintains a collection of books. Books can be added to
and deleted from and checked out and checked in to this
collection.
Title and author name identify a book. Each book object
maintains a count of the number of copies available and the number
of copies checked out. The number of copies must always be greater
than or equal to zero. If the number of copies for a book goes to
zero, it must be deleted from the...
Hi I've a problem with this code. When I add more than 1 song to the list, it doesn't show the first one, only shows the latest one, when I called the function displaysong, let's say when you add 2 songs ID 1 then ID 2, it shows only ID 1. Can you fix it. Everything else is fine.. #include <iostream> #include<string> using namespace std; //class Song class Song{ private: int songID; string title; string artist; string album; int year; public:...
You are given a partial implementation of two classes. GroceryItem is a class that holds the information for each grocery item. GroceryInventory is a class that holds an internal listing of GroceryItems as well as the tax rate for the store. Your inventory could be 100 items it could be 9000 items. You won’t know until your program gets the shipment at runtime. For this you should use the vector class from the C++ standard library. I've completed the GroceryItem.h...