Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program in C++ Points will be described by the Point structure: struct Point { double x, y; }; Using the point structure, create a class

Program in C++

Points will be described by the Point structure:

struct Point {

double x, y;

};

Using the point structure, create a class called "Shape". Shape can contain an array or vector of Points. Use the following class definition for the shape class:

class Shape{ private: vector points; public: void addPoint(Point); Point getPoint(int); int getNumPoints(void); };

This shape class only contains member function prototypes. You will need to define the member functions themselves. The functions should behave as follows:

addPoint should push a new point struct to the vector of points

getPoint should retrieve a point at the specified index. Be sure to check for boundary conditions!

getNumPoints should return the current vector length

^(10 Points)

Three files are provided containing a series of points in the format "x, y". Each file has a new point on each new line. When launching your program, add a file name as a command line parameter. The program should open the file, read all the points contained within, then initialize a Shape object containing the points. If no filename is passed to the function, print an error message and exit.

pointset1.txtimage text in transcribed pointset2.txtimage text in transcribed pointset3.txtimage text in transcribed

^(15 Points)

Each file contains points which form either a square, triangle, and rectangle. Create a derived class for each shape which uses the "Shape" class as a base. Add a virtual "area" and "perimeter" function to the base the class and implementation for each of these in the derived square, triangle, and rectangle classes. Feel free to add any additional data member objects for these shapes as you find helpful (such as a side length for squares, length and width for rectangles.) Create an overloaded constructor which uses 3 points as input for the triangle class, and 4 points for the square and rectangle.

^(20 Points)

When reading in a set of points from the file, write some code which determines which shape the set of points should belong to (yes, squares are types of rectangles, but if you read points which form a square, use the square class). When the proper shape is determined, initialze that class using those points.

Once you have completed this, call the area and perimeter member fuctions of your classes and print these values to the terminal.

^(15 Points)

Add functionality so that multiple files can be passed as input parameters. Initialize each set of points within the proper shape class. Create an array of Shape pointers which point to each derived class and utilize the virtual area and perimeter functions to retrive the area and perimeter for each shape.

^(20 Points)

pointset1.txt contains

0,0

2,0

0,2

2,2

pointset2.txt contains

0,0

2,0

1,1

pointset3.txt contains

0,0

2,0

0,4

2,4

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

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

Identify who may be responsible for performance appraisal.

Answered: 1 week ago

Question

Explain the performance appraisal period.

Answered: 1 week ago