Project • Write a C++ programme that reads a set of shapes for a given file. • The shapes are defined in the file by a n
Posted: Thu May 05, 2022 1:03 pm
data 2:
Project • Write a C++ programme that reads a set of shapes for a given file. • The shapes are defined in the file by a name string, a colour string, followed by a set of x,y points that describe the shape or some other data depending on the shape. All coordinate should be positive! •. There are two files to test your programme with: 'datal.dat' and 'data2.dat'. 'data2.dat' contains errors in some lines that your programme should cope with. Start with 'datal.dat' • Colour is restricted to the following: red, green, blue, yellow, white, black. Your classes should store this in an appropriate manner. • Add a function void print_name() to print the name of the shape. • Add a function that calculates and returns the width of the object. To do this you need loop over the vectors to find the minimum and maximum x-point. • Add a function that calculates and return the height of the object. To do this you need loop over the vectors to find the minimum and maximum x-point. • Add a function that calculates the area (as define by the bounding box, i.e., use the width and height and calculate the area from this.) • Print all the shape names, widths, heights and areas • Sort the order of the shapes by area. Data formats Shape name data Point Line Polyline Rectangle Circle int x, inty colour, Point, Point colour, An unknown number of Points colour, Point, Point, Point, Point colour, Point centre, double radius
Line red 1 2 3 4 Line green 3 4 5 6 Rectangle black 1 1 1 3 3 3 3 1 Polyline white 1 1 1 3 4 5 5 6 6 7 Circle blue 3 4 10 0
Line red 1 2 3 4 Linef green 3 4 5 6 Rectangle black 1 1 1 3 3 3 3 1 1 Polyline white 1g 1 1 3 4 5 5 6 67 Circle blue 3 4 10 0 Line red 1 2 -3 4 Line blue 10 20 30 40
Project • Write a C++ programme that reads a set of shapes for a given file. • The shapes are defined in the file by a name string, a colour string, followed by a set of x,y points that describe the shape or some other data depending on the shape. All coordinate should be positive! •. There are two files to test your programme with: 'datal.dat' and 'data2.dat'. 'data2.dat' contains errors in some lines that your programme should cope with. Start with 'datal.dat' • Colour is restricted to the following: red, green, blue, yellow, white, black. Your classes should store this in an appropriate manner. • Add a function void print_name() to print the name of the shape. • Add a function that calculates and returns the width of the object. To do this you need loop over the vectors to find the minimum and maximum x-point. • Add a function that calculates and return the height of the object. To do this you need loop over the vectors to find the minimum and maximum x-point. • Add a function that calculates the area (as define by the bounding box, i.e., use the width and height and calculate the area from this.) • Print all the shape names, widths, heights and areas • Sort the order of the shapes by area. Data formats Shape name data Point Line Polyline Rectangle Circle int x, inty colour, Point, Point colour, An unknown number of Points colour, Point, Point, Point, Point colour, Point centre, double radius
Line red 1 2 3 4 Line green 3 4 5 6 Rectangle black 1 1 1 3 3 3 3 1 Polyline white 1 1 1 3 4 5 5 6 6 7 Circle blue 3 4 10 0
Line red 1 2 3 4 Linef green 3 4 5 6 Rectangle black 1 1 1 3 3 3 3 1 1 Polyline white 1g 1 1 3 4 5 5 6 67 Circle blue 3 4 10 0 Line red 1 2 -3 4 Line blue 10 20 30 40