[Solved] C Program Multiple Classes Header Files Source Files Basic Program Drawing Figures Console Q37169301









C++ Program with multiple classes with header files and source files. Basic Program for drawing some figures by console to the screen. Basic structure classes and stuff. PART ONE: C++ CLASSES Point: This is the most basic class that will be required in creation of the other classes. You need to add the following data members to this class: » AnintegertoholdtheXcoordinate » AnintegertoholdtheYcoordinate. Alabel to identify the point. (Ex: “P1”, “Point 10” etc.) We also need the following to be implemented for this class: A default constructor A constructor to initialize every data member, that is to say, the X and Y coordinates and the label A copy constructor An assignment operator A destructor Getter and setter functions for each of the member variables A function to calculate distance between two points A function to print all the details of member variables » Shape: Shapeclasswill bethebase classforalltheshapesthatweintendtodrawusingthis system. It will contain at least the following members: A list of points to describe the shape. Alabel to identifythe shape. (Ex: “Rectangle1”, “Line 5″ etc.) Afont character that will be used to draw it (Ex:*”) » . For shape class implement the following member functions: . A default constructor Aconstructor to initialize thelabel, the fontandalso take asinput how many points there will be in the shape A copy constructor A destructor Getter and setter functions for each of the member variables Afunction to add new points to this object A function to list the side lengths of the shape (You’ll do this by processing the points) » o Additionally, we need a function to draw this shape, called draw(). All shapes will require a different implementation of this function, but in the end the user should be able to seamlessly call draw on whatever shape they desire and see the proper output without knowing the details. This draw() function will take a reference to a “canvas”, which will be explained in the Renderer class. Line: A line will be the most primitive shape to be drawn. It will consist of 2 points only. Please note that this class should construct the list of points for maximum of 2 points only! Use similar logic to create the list ofpoints for other shapes. Quadrilateral: A quadrilateral will be defined as a shape. It will consist of only 4 points Triangle: A triangle will be defined as a shape. You are to assume that you’ll be given 3 points as inputs to construct this shape. Please notethatthis shape doesn’t necessarilyhave to be a righttriangle. Circle: A circle will be defined as a shape, however contrary to the other shapes listed, a circle only requires a single point to denote the center, and a radius. So, you’ll have to add an extra data member to store the radius. You’ll receive these two as inputs to construct this shape, on top of the usual inputs for a shape. Also note that the functiontolistthesidelengthsofanyshapewill have to bealteredheretojustshow the radius instead Image An image will be used in this case to denote a group of shapes that represent an object. This class will contain the following data members » Alistofshapes(Youcanassumemaximumof10shapeswillbeonanlmageat a time) . Alabel to identify the image (Ex: “Image1” or “Car”) » An integer value to denote the precedence for drawing For this class implement the following member functions e A default constructor » Aconstructor to initialise thethelabel and the precedence A destructor Getter and setter functions for the label and precedence A function to add new shapes Afunctiontodrawtheimage. Please note thatyouwillrequiretheRenderer class and its canvas for this function Afunction to draw onlycertain types ofshapes (Ex: Draw only Rectangles) Afunction to show the details of the shapes contained (The labels, side lengths, points etc.) Afunction to search for a shape using the shape label » » » » » » Renderer: Using the classes mentioned above create a renderer which will be used to draw groups of images. You need to keep track of a list of images. You can assume that the renderer will only support a maximum of 5 images A2D array of characters to represent a “canvas” A list ofimages A value to store rendering order » » This class should have the following methods: e A default constructor A destructor A function to add a new image A function to search for the details ofanimage and its contents using image label. If it doesn’t exist, say “Image not found” A function to list the details of every image A function to toggle drawing of certain images with use oftheir label A function to toggle the order of drawing images from front-to-back and back-to-front (You’l use precedences for this, and by default draw from back-to-front ie. lower precedence first) A function to draw all images. Remember that you must pay attention to the options defined above while drawing » » » » » » e A function to clear the “canvas” PART TWO: INTERFACE You need to implement a command line interface for managing these classes. Additionally, you must insert the following code snippets to ensure testing via. input from files 1. Describe an image 2. Render images 3. Exit This will be your main panel. You can be flexible with your outputs here and not necessarily follow the text strictly. However, you should still construct the objects as shown here, ie. receive required data members in some order. A sample output to get a line drawn from (0, 0) to (16 20) is as follows Welcome to Interactive Shape Drawing! Describe an Image 2- Render Images B Exit Enter a label for the image: > image 1 Enter the precedence for this image: 5 Enter shape type to add to this image: 1- Line 2. Quadrilater 3 Triangle 4. Circle 5- Finish Image 1 Enter a label for the shape: line 1 Enter the font to use: Enter point 1 Enter a label for the point: Enter point 2: 16 20 Enter a 1abel for the point: pl Enter shape type to add to this image: 1- Line 2- Quadrilateral 3 Triangle 4. Circle 5 Finish Imag Welcome to Interactive Shape Drawing ! Describe an Image 2. Render Images 3 Exit 1 Render images 2 Toggle display of an image 3 Render only specific shapes 4 Toggle rendering precedence 5 Details of images 6 Exit Pleasenotethatyourcanvasgoesfrom (0,0)attop-leftcorner,and(80,80)at bottom right corner. The line itself will look something like this ak sik oic otk atc You can find the algorithms required to draw a line and a circle below, in pseudocode. They are very easy to implement and aren’t very complicated. You need these in order to render the shapes properly. Please note that a triangle and a quadrilateral are really just 3 and4 lines, respectively. You can use this to shorten your code. Note that a pixel in the pseudocode referstoa locationon our canvas. function drawLine (x0, y0, x1, y1) define dx x1 -x0 define dy = yi -yo define xs = 1 define ys = 1 // allow negative slope This is the generalization on Bresenham’s Line Algorithm if dy less than 0 then set dy = -dy set ys =-1 if dx less than 0 then set dx = -dx set xs-1 set dy = 2 * set dx-2 * dx dy update pixel at x0 y0 define slope inc0 // the parts below are also generalizations on the direction we move, and how we move if dx is greater than ay then set slope inc -dy dx / 2 do while x0 !=x1 if slope inc greater or egual 0 set slope inc – (Ctrl) ▼1 – ax set slope inc-slope inc + dỵ update pixel at x0 y0 else set slope inc dx – dy / 2; do while y0 != y1 if slope inc greater or equal 0 set slope inc = slope inc -dy set slope inc = slope inc + dx; update pixel at x0 y0 function drawCircle (xc, yc, r) // This is the Bresenham Circle Algorithm define x0 define y = r define d = 3-2*r draw8 Points (xc, XC, x, y) ; do while y greater or equal x increment X if d greater than 0 then decrement y set d = d + 4 * (x-y) +10; else set d d + draw8 Points (xc, , x, y) ; // this is the function that takes advantage of the symmetry of the circle, both on the quadrants and around y = x line function draw8Points (xc, yc, x, y) update pixel at (xc + x) (XC + y) update pixel at (xc – x) (yc + y) update pixel at (xc + x) (ye-y) update pixel at (xc – x) (yc – y) update pixel at (xc + y) (yc x) update pixel at (xc – y (Yc x) update pixel at (xc + y) (yc – x) update pixel at (xc – y) (yc – x) General program consist of these: Point Clas:s Shape Class Line Class Rectangle Class Triangle Class Circle Class Image Class Renderer Interface FilelO Method Calls RULES: Header files should contain class definitions with prototypes only, no function implementations. Make sure to properly use virtual and const where applicable! You are notallowed to use ANY STL (Standard Template Library)containers in this assignmentincluding, but not limited to,std::vector andstd::string. . Show transcribed image text C++ Program with multiple classes with header files and source files. Basic Program for drawing some figures by console to the screen. Basic structure classes and stuff. PART ONE: C++ CLASSES Point: This is the most basic class that will be required in creation of the other classes. You need to add the following data members to this class: » AnintegertoholdtheXcoordinate » AnintegertoholdtheYcoordinate. Alabel to identify the point. (Ex: “P1”, “Point 10” etc.) We also need the following to be implemented for this class: A default constructor A constructor to initialize every data member, that is to say, the X and Y coordinates and the label A copy constructor An assignment operator A destructor Getter and setter functions for each of the member variables A function to calculate distance between two points A function to print all the details of member variables »
Shape: Shapeclasswill bethebase classforalltheshapesthatweintendtodrawusingthis system. It will contain at least the following members: A list of points to describe the shape. Alabel to identifythe shape. (Ex: “Rectangle1”, “Line 5″ etc.) Afont character that will be used to draw it (Ex:*”) » . For shape class implement the following member functions: . A default constructor Aconstructor to initialize thelabel, the fontandalso take asinput how many points there will be in the shape A copy constructor A destructor Getter and setter functions for each of the member variables Afunction to add new points to this object A function to list the side lengths of the shape (You’ll do this by processing the points) » o Additionally, we need a function to draw this shape, called draw(). All shapes will require a different implementation of this function, but in the end the user should be able to seamlessly call draw on whatever shape they desire and see the proper output without knowing the details. This draw() function will take a reference to a “canvas”, which will be explained in the Renderer class.
Line: A line will be the most primitive shape to be drawn. It will consist of 2 points only. Please note that this class should construct the list of points for maximum of 2 points only! Use similar logic to create the list ofpoints for other shapes. Quadrilateral: A quadrilateral will be defined as a shape. It will consist of only 4 points Triangle: A triangle will be defined as a shape. You are to assume that you’ll be given 3 points as inputs to construct this shape. Please notethatthis shape doesn’t necessarilyhave to be a righttriangle. Circle: A circle will be defined as a shape, however contrary to the other shapes listed, a circle only requires a single point to denote the center, and a radius. So, you’ll have to add an extra data member to store the radius. You’ll receive these two as inputs to construct this shape, on top of the usual inputs for a shape. Also note that the functiontolistthesidelengthsofanyshapewill have to bealteredheretojustshow the radius instead Image An image will be used in this case to denote a group of shapes that represent an object. This class will contain the following data members » Alistofshapes(Youcanassumemaximumof10shapeswillbeonanlmageat a time) . Alabel to identify the image (Ex: “Image1” or “Car”) » An integer value to denote the precedence for drawing For this class implement the following member functions e A default constructor » Aconstructor to initialise thethelabel and the precedence A destructor Getter and setter functions for the label and precedence A function to add new shapes Afunctiontodrawtheimage. Please note thatyouwillrequiretheRenderer class and its canvas for this function Afunction to draw onlycertain types ofshapes (Ex: Draw only Rectangles) Afunction to show the details of the shapes contained (The labels, side lengths, points etc.) Afunction to search for a shape using the shape label » » » » » »
Renderer: Using the classes mentioned above create a renderer which will be used to draw groups of images. You need to keep track of a list of images. You can assume that the renderer will only support a maximum of 5 images A2D array of characters to represent a “canvas” A list ofimages A value to store rendering order » » This class should have the following methods: e A default constructor A destructor A function to add a new image A function to search for the details ofanimage and its contents using image label. If it doesn’t exist, say “Image not found” A function to list the details of every image A function to toggle drawing of certain images with use oftheir label A function to toggle the order of drawing images from front-to-back and back-to-front (You’l use precedences for this, and by default draw from back-to-front ie. lower precedence first) A function to draw all images. Remember that you must pay attention to the options defined above while drawing » » » » » » e A function to clear the “canvas” PART TWO: INTERFACE You need to implement a command line interface for managing these classes. Additionally, you must insert the following code snippets to ensure testing via. input from files 1. Describe an image 2. Render images 3. Exit This will be your main panel. You can be flexible with your outputs here and not necessarily follow the text strictly. However, you should still construct the objects as shown here, ie. receive required data members in some order. A sample output to get a line drawn from (0, 0) to (16 20) is as follows
Welcome to Interactive Shape Drawing! Describe an Image 2- Render Images B Exit Enter a label for the image: > image 1 Enter the precedence for this image: 5 Enter shape type to add to this image: 1- Line 2. Quadrilater 3 Triangle 4. Circle 5- Finish Image 1 Enter a label for the shape: line 1 Enter the font to use: Enter point 1 Enter a label for the point: Enter point 2: 16 20 Enter a 1abel for the point: pl Enter shape type to add to this image: 1- Line 2- Quadrilateral 3 Triangle 4. Circle 5 Finish Imag Welcome to Interactive Shape Drawing ! Describe an Image 2. Render Images 3 Exit 1 Render images 2 Toggle display of an image 3 Render only specific shapes 4 Toggle rendering precedence 5 Details of images 6 Exit Pleasenotethatyourcanvasgoesfrom (0,0)attop-leftcorner,and(80,80)at bottom right corner. The line itself will look something like this
ak sik oic otk atc You can find the algorithms required to draw a line and a circle below, in pseudocode. They are very easy to implement and aren’t very complicated. You need these in order to render the shapes properly. Please note that a triangle and a quadrilateral are really just 3 and4 lines, respectively. You can use this to shorten your code. Note that a pixel in the pseudocode referstoa locationon our canvas. function drawLine (x0, y0, x1, y1) define dx x1 -x0 define dy = yi -yo define xs = 1 define ys = 1
// allow negative slope This is the generalization on Bresenham’s Line Algorithm if dy less than 0 then set dy = -dy set ys =-1 if dx less than 0 then set dx = -dx set xs-1 set dy = 2 * set dx-2 * dx dy update pixel at x0 y0 define slope inc0 // the parts below are also generalizations on the direction we move, and how we move if dx is greater than ay then set slope inc -dy dx / 2 do while x0 !=x1 if slope inc greater or egual 0 set slope inc – (Ctrl) ▼1 – ax set slope inc-slope inc + dỵ update pixel at x0 y0 else set slope inc dx – dy / 2; do while y0 != y1 if slope inc greater or equal 0 set slope inc = slope inc -dy set slope inc = slope inc + dx; update pixel at x0 y0
function drawCircle (xc, yc, r) // This is the Bresenham Circle Algorithm define x0 define y = r define d = 3-2*r draw8 Points (xc, XC, x, y) ; do while y greater or equal x increment X if d greater than 0 then decrement y set d = d + 4 * (x-y) +10; else set d d + draw8 Points (xc, , x, y) ; // this is the function that takes advantage of the symmetry of the circle, both on the quadrants and around y = x line function draw8Points (xc, yc, x, y) update pixel at (xc + x) (XC + y) update pixel at (xc – x) (yc + y) update pixel at (xc + x) (ye-y) update pixel at (xc – x) (yc – y) update pixel at (xc + y) (yc x) update pixel at (xc – y (Yc x) update pixel at (xc + y) (yc – x) update pixel at (xc – y) (yc – x)
General program consist of these: Point Clas:s Shape Class Line Class Rectangle Class Triangle Class Circle Class Image Class Renderer Interface FilelO Method Calls RULES: Header files should contain class definitions with prototypes only, no function implementations. Make sure to properly use virtual and const where applicable! You are notallowed to use ANY STL (Standard Template Library)containers in this assignmentincluding, but not limited to,std::vector andstd::string. .
Expert Answer
Answer to C++ Program with multiple classes with header files and source files. Basic Program for drawing some figures by console … . . .
OR

