Question: Write a class called polygon which can initialise regular2 Two-Dimensional (2D) polygons, and translate them in the +/-x and +/-y directions (or both x and

Write a class called polygon which can initialise regular2 Two-Dimensional (2D) polygons, and translate them in the +/-x and +/-y directions (or both x and y). It should also be able to rotate them by any number of degrees about any point. Come up with your own names for all class members except N and r. The following members must be included in your class, exactly as instructed, and must serve a meaningful purpose in your program: Private members: o Member of type std::string, to store a user-defined polygon name (e.g. t_1) Note: the user-defined polygon name must always take the form l_i where l is a letter, i an integer; this also applies in ProgramB. o Member (r) of type double, to store the radius o Member (N) of type integer, to store the number of vertices o Member of type std::vector, to store the x-coordinates of the polygon vertices o Member of type std::vector, to store the y-coordinates of the polygon vertices o Member function which prints any objects name, number of vertices and coordinates (as a coordinate pair for each vertex) on screen using the standard output stream. The printed output must take the following exact form (although obviously the user- defined polygon name, the coordinates and the number of coordinate pairs will vary). All numerical printed output should be rounded to 5 decimal places: t_1=polygon((1.73205,-1),(0,2),(-1.73205,-1))

Public members: o Constructor function which, firstly, accepts and stores the name, r and N. Secondly, it then uses this data to initialise and store the coordinates of the polygon vertices. When initialised, each polygon must be centred on the origin (0,0), and its base must be horizontal (parallel with the x axis). o Member function to translate any object, and efficiently print the object name and coordinates before and after translation, and the translation vector applied, in the following exact form: Before translation: t_1=polygon((1.73205,-1),(0,2),(-1.73205,-1)) After translation by [-4,0]: t_1=polygon((-2.26795,-1),(-4,2),(-5.73205,-1)) o Member function to rotate an object of this class about any point, and efficiently print the object name and coordinates before and after rotation; also, how many degrees of rotation were applied and what point the rotation was around. (Positive rotation is anticlockwise.) In the following exact form: Before rotation: t_1=polygon((1.73205,-1),(0,2),(-1.73205,-1)) After rotation 90 degrees anticlockwise about (1,2): t_1=polygon((4,2.73205),(1,1),(4,-0.73205)) Therefore write a program incorporating the above class in the global scope. In your main function, instantiate a triangle, a square and an -gon (you choose > 4) using your constructor function created above. For each polygon, following instantiation, call sequentially first the translation, then the rotation function. Rotatation must be by 90o about (a,b) and translation by (a,-b), where a and b are the (3,1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!