Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C + + Not sure how to set up to derive and override the line class from the shape class and how to get the
C Not sure how to set up to derive and override the line class from the shape class and how to get the line class to draw itself on the console window.
Add a Line class to the Graphics project. The Line class should derive from Shape.
Add PointD field called endPt. Add gettersetter methods for the field.
Add a constructor that takes a start PointD end PointD and console color. Make sure to call the base constructor. Dont duplicate what the base constructors do
Implement the pseudocode for the PlotLine see the pseudocode for PlotLine below NOTE: youll need to implement the Plot method it should move the cursor to the xy
position and prints a space.
Override the draw method of the Shape class that means you need to mark the base as virtual Do not call the base. Instead, set the background color, call PlotLine, then reset
the color.
PlotLinex y x y
dx absx x
sx x x :
dy absy y
sy y y :
error dx dy
while true
Plotx y
if x x && y y break
e error
if e dy
if x x break
error error dy
x x sx
end if
if e dx
if y y break
error error dx
y y sy
end if
end while
In main which is in Graphics.cpp add code to case of the menu switch. Generate random PointD points with an xy anywhere in the console. Use those points to create a
Line instance with any color you want. Call draw on the Line instance.
PointDh code
struct POINTD
int x;
int y;
POINTDint xpoint, int ypoint : xxpoint yypoint
;
Shape.h code
class Shape
private:
fields
POINTD startPt;
ConsoleColor color;
public:
first constructor
ShapePOINTD startPtpoint, ConsoleColor colorpoint : startPtstartPtpoint colorcolorpoint
nd constructor
Shapeint x int y ConsoleColor colorpoint : startPtx y colorcolorpoint
Getters for PointD & ConsoleColor
POINTD GetStartPt const
return startPt;
ConsoleColor GetColor const
return color;
Setters for PointD & ConsoleColor
void SetStartPtPOINTD startPtpoint
startPt startPtpoint;
void SetColorConsoleColor colorpoint
color colorpoint;
virtual void draw
SET BACKGROUND COLOR
Console::SetBackgroundColorMagenta;
MOVE CURSOR TO POINTD POSITION
Console::SetCursorPositionstartPtx startPt.y;
PRINT A SPACE
Console::Write;
RESET THE COLOR. CALL THE RESET METHOD ON THE CONSOLE CLASS.
Console::Reset;
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started