Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Provided coding: // // checkpack.cpp // #include Domain.h #include using namespace std; int main() { Domain d; char type; int x,y,w,h,r; cin >> type; while

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Provided coding:

// // checkpack.cpp //

#include "Domain.h" #include using namespace std;

int main() { Domain d; char type; int x,y,w,h,r;

cin >> type; while (cin) { if ( type == 'C' ) { cin >> x >> y >> r; Shape* p = new Circle(Point(x,y),r); d.addShape(p); } else if ( type == 'R' ) { cin >> x >> y >> w >> h; Shape* p = new Rectangle(Point(x,y),w,h); d.addShape(p); } cin >> type; } d.draw(); }

// // Domain.h //

#include "Shape.h" #include #include

class Domain { public: Domain(void); ~Domain(void); void addShape(const Shape* p); void draw(void); private: int sizex, sizey; std::vector s; };

// // Point.h // #ifndef POINT_H #define POINT_H #include

class Point { public: Point(void) : x(0), y(0) {} Point(int xin, int yin) : x(xin), y(yin) {} int norm2(void) const { return x*x + y*y; } Point operator+(const Point& rhs) const; Point operator-(const Point& rhs) const; int x, y; };

std::ostream& operator>(std::istream& is, Point& p); #endif

// // Shape.h // #ifndef SHAPE_H #define SHAPE_H #include "Point.h" #include

class Circle; class Rectangle;

class Shape { public: virtual ~Shape(void) {} virtual bool overlaps(const Shape& s) const = 0; virtual bool overlaps(const Circle& r) const = 0; virtual bool overlaps(const Rectangle& r) const = 0; virtual bool fits_in(const Rectangle& r) const = 0; virtual void draw(void) const = 0; };

class Rectangle : public Shape { public: Rectangle(void): position(Point(0,0)), width(0), height(0) {} Rectangle(Point p, int w, int h) : position(p), width(w), height(h) {} virtual ~Rectangle(void); virtual bool overlaps(const Shape& r) const; virtual bool overlaps(const Circle& r) const; virtual bool overlaps(const Rectangle& r) const; virtual bool fits_in(const Rectangle& r) const; virtual void draw(void) const;

const Point position; // position of the lower left corner const int width, height; };

class Circle : public Shape { public: Circle(void): center(Point(0,0)), radius(0) {} Circle(Point c, int r) : center(c),radius(r) {} virtual ~Circle(void); virtual bool overlaps(const Shape& s) const; virtual bool overlaps(const Circle& r) const; virtual bool overlaps(const Rectangle& r) const; virtual bool fits_in(const Rectangle& r) const; virtual void draw(void) const;

Point center; int radius; }; #endif

// // testPoint.cpp //

#include "Point.h" #include using namespace std;

int main() { Point a(1,2); Point b(3,4);

cout > c; cout

// // testShape.cpp //

#include "Shape.h" #include using namespace std;

int main() { Point center(10,30); const int radius = 50; Circle c(center,radius); c.draw();

Point llcorner = Point(50,70); const int width = 25; const int height = 80; Rectangle r1(llcorner,width,height); r1.draw();

Rectangle r2(llcorner+Point(20,30),width,height); r2.draw();

Circle c1(Point(60,160),10); c1.draw(); Circle c2(llcorner-Point(5,-5),100); c2.draw();

cout ECS40 Spring 2018 2018-05-12 Homework 3 due Thu 2018-05-24 at 23:59 Use the handin directory hw3 to submit your work Packing circles and rectangles Description In this assignment, you are asked to implement a program (named checkpack) that, given a rectangular domain and a list of circles and rectangles, can check if the packing configuration is valid, in the sense that all shapes fit within the domain and there are no overlaps between shapes This problem occurs e.g. in electronic device design when packing electronic components on a printed circuit board The program should create a visual representation of the domain and shapes as a scalable vector graphics (svg) file. An svg file can be visualized using a browser such as Firefox, Safari, Chrome or Internet Explorer. See https://en.wikipedia.or ki/Scalable Vector Graphics The positions and sizes of the shapes are specified using integers. The domain is a rectangle of fixed size (600x500). Circles of arbitrary position and radius are read from standard input Rectangles of arbitrary position and sizes are read from input. Circles and Rectangles can appear in any order in the input. The program should write on standard output the svg representation of all the shapes, and include in addition the following diagnostic message - ok if the configuration is valid, i.e. all shapes fit in the domain and there are no overlaps between shapes. -overlap if the shapes fit in the domain but some of the shapes overlap - does not fitif any of the shapes does not fit in the domain. The diagnostic message should appear when rendering the svg file as in Figure 1 overlap Figure 1: Example of rendering of an svg file ECS40 Spring 2018 2018-05-12 Homework 3 due Thu 2018-05-24 at 23:59 Use the handin directory hw3 to submit your work Packing circles and rectangles Description In this assignment, you are asked to implement a program (named checkpack) that, given a rectangular domain and a list of circles and rectangles, can check if the packing configuration is valid, in the sense that all shapes fit within the domain and there are no overlaps between shapes This problem occurs e.g. in electronic device design when packing electronic components on a printed circuit board The program should create a visual representation of the domain and shapes as a scalable vector graphics (svg) file. An svg file can be visualized using a browser such as Firefox, Safari, Chrome or Internet Explorer. See https://en.wikipedia.or ki/Scalable Vector Graphics The positions and sizes of the shapes are specified using integers. The domain is a rectangle of fixed size (600x500). Circles of arbitrary position and radius are read from standard input Rectangles of arbitrary position and sizes are read from input. Circles and Rectangles can appear in any order in the input. The program should write on standard output the svg representation of all the shapes, and include in addition the following diagnostic message - ok if the configuration is valid, i.e. all shapes fit in the domain and there are no overlaps between shapes. -overlap if the shapes fit in the domain but some of the shapes overlap - does not fitif any of the shapes does not fit in the domain. The diagnostic message should appear when rendering the svg file as in Figure 1 overlap Figure 1: Example of rendering of an svg file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago