SlideShare a Scribd company logo
1 of 13
Download to read offline
Please make the complete program, distinguishing between each class and header file. I have two
.cpp files already and one .h
Section 1: Project Objectives
By given a class hierarchy, focus on Object-Oriented-Design concept, design and write multiple
classes.
Be able to apply the concepts of inheritance, polymorphism, abstract classes, pure virtual
functions, function overriding, etc.
Be familiar with common functions in vector class in C++.
Section 2: Background Introduction
Video game programmers often have to maintain a collection of figures that are simultaneously
moving in various directions on the screen. In this project, we will design a solution to a
simplified version of the problem.
We will maintain a collection of geometric shapes and simultaneously animate those shapes. The
functions used to directly access the screen and manage the timer are peculiar to Microsoft
Windows, but the principles used are very general and are applicable to all operating systems.
Section 3: Project Description
We begin with a class that represents a shape that is able to move in any of eight different
directions, with each direction being specified by a pair of integer (X, Y) coordinates. Upward or
downward motion is indicated by a Y component of ±1. A value of 0 for an X or Y coordinate
indicates lack of motion in that direction. Thus, a value of (0,-1) for (X, Y) indicates motion
straight up, a value of (-1, 0) indicates motion to the left, and (1, 1) indicates motion that is
simultaneously downward and to the right.
In this project, you will need to design five classes, namely Shape, ComplexShape, SimpleShape,
Box and Tent. These classes form the inheritance hierarchy as showing in the following figure.
Shape
ComplexShape
SimpleShape
Box
Tent
Figure 1
1
Section 3.1: Classes Description
The Shape class has a move() function that is pure virtual. This is because a shape is moved by
erasing it at its current position and redrawing it at new position and it is not possible to know
how to draw a shape without knowing what type of shape it is.
The SimpleShape class represents objects that can be drawn at a given position in a specified
color. Accordingly, it has member variables for representing position and color and member
functions for setting and accessing those values. The SimpleShape class inherits from Shape,
notice that the SimpleShape class is still abstract because if provides no implementation for the
draw() method. The class does implement the move() method, though. The is because the move()
method works the same way for all subclasses of SimpleShape: erase the shape at its current
position, compute its new position, and draw the shape at the new position. The draw() method,
however, works differently for each concrete subclass that implements it. Because draw() is
virtual, the move() method will always call the appropriate version of draw(), even when the call
to draw() is through a pointer to the abstract class Shape.
The Box and Tent classes are the concrete classes at the tip of the inheritance hierarchy. They
define a specific concrete shape and implement the member function draw() that draws the shape
at its current position using the shape’s specified color.
The Box class defines a rectangular shape by specifying the positon of its tope left-hand corner
together with its width and height. The Tent class defines a triangle with a horizontal base whose
two other sides are equal in length and whose height is half the length of the base. A Tent object
is specified by giving the position of the left end point of its base together with the length of the
base. For example, a tent whose base has length 5 would look like this:
*
* *
* * * *
The CompletShape class provides a mechanism for assembling a collection of simple shapes to
form a single shape that can be moved using a single command. The class maintains a vector of
pointers to Shape objects, and implements its move() method is by calling the move() methods of
all the Shape objects in its collections. Likewise, ComplexShape has a setDirection() method that
can be used to cause all of its constituent shapes to move in the same direction.
Program TestShape.cpp is the driver’s program which we will use to test all of above classes.
The program starts out by creating two simple shapes - a tent and a box. The tent is created at the
left edge of the screen while the box is near the right edge. The program moves the tent to the
right at the same time that it is moving the box to the left, stopping the motion when the two
shapes are within a few coordinates of each other. Line 27-39 create a complex shape out of the
two simple shapes, and then moves the complex shape diagonally downward and to the right.
Finally, the program moves the box horizontally to the right.
2
Section 3.2: UML Diagrams for Each Class
1. Shape class
Shape
-dRow : int -dCol : int
+setDirection(int, int ) : void +getDirection(int &, int &) : void +move() : void = 0
Member
Data Type
Description
Variable
dRow
int
This represents the direction of row motion.
dCol
int
This represents the direction of row motion.
Member Function
void setDirection(int drow, int dcol)
Function Description
This function should initialize all member variable by the initial value defined inside the UML.
This function need to be override later by inherited classes, i.e. it need to be declared virtual.
void getDirection(int &drow, int &dcol)
virtual void move() = 0
This function initializes member variable dRow, dCol with the input parameter.
This is a pure virtual function
2. SimpleShape class (inherited from Shape class)
A SimpleShape is drawn at a give position in a specified color
SimpleShape
-rowPos : int -ColPos : int -color : int
+getPosition(int &, int &) : void +setPosition(int, int ) : void +getColor() : int
+setColor(int ) : void +move() : void
Member
Data Type
Description
Variable
rowPos
int
This represents the X position of the shape that to be drawn.
colPos
int
This represents the Y position of the shape that to be drawn.
color
int
This represents the color of the shape
3
Member Function
Function Description
void getPosition(int &row, int &col)
void setPosition(int row, int col )
int getColor()
Void setColor(int c)
This function should initialize member variable rowPos & colPos with the input parameters.
This is the mutator for member variable rowPos & colPos.
This is the accessor for member variable color. This is the mutator for member variable color.
3. Box class (inherited from SimpleShape class)
A Box is a rectangular type of shape
Box
-width : int -height : int
+Box(int, int, int, int) +draw() : virtual void
Member Function
Box(int rowPos, int colPos, int width, int height)
virtual void draw()
Function Description
This is the constructor, it sets the color, position and dimensions for a box shape, and draws the
box at its initial position
This function draw the lines that make up the box (a rectangle shape of *
4. Tent class (inherited from SimpleShape class)
A Tent is an isosceles triangle whose horizontal base has a given length and whose height is half
the length of the base. The position of the triangle is the left end point of the base.
Tent
-baseLength : int
+Tent(int, int, int) +draw() : virtual void
Member Function
Tent(int baseRowPos, int baseColPos, int baseLength)
virtual void draw()
Function Description
This is the constructor, it sets the color for a Tent shape, sets the position of the tent as well as
the length of its base and draw it at its initial position.
This function draw the lines that make up the tent.
4
5. ComplexShape class (inherited from Shape class)
A ComplexShape is made up of simpler shapes. It is represented as a vector of pointers to the
simpler shapes that make it up.
ComplexShape
-shapes : vector
+ComplexShape(Shape **, int) +move() : virtual void
+setDirection(int, int) : virtual void
Member Function
ComplexShape(Shape ** shapeCollection, int shapesCount))
Virtual void move()
virtual void setDirection(int dRow, int dCol)
6. TestShape class
Function Description
This is the constructor, it builds a complex shape by assembling a vector of constituent shapes.
Moves a complex shape by moving the constituent shapes.
Sets the direction of a complex shape by setting the direction of all constituent shapes
This is the driver’s program used to test on the various Shape classes and subclasses and do the
graphic animation. TestShape class contains only main() function, within main() function, you’re
required to do the following:
Create a Tent object with initial row & column position at 11, 5 respectively. Also initialize its
base length to be 13.
Crate a Box object with initial row & column position at 5, 65 respectively. Also initialize its
width and height to be 4, 7 respectively.
Draw above created Tent and Box objects by calling their draw() function
Set above Tent object’s initial direction of motion, let it move horizontally to the right.
Set above Box object’s initial direction of motion, let it move horizontally to the left.
Simultaneously move the tent and the box. Note: this will make them move towards each other.
Create a complex shape composed of the tent and the box.
Set the direction for the complex shape and move the complex shape: this moves both the tent
and the box diagonally to the right.
Move the box by itself horizontally to the right.
5
Section 3.3: Miscellaneous Programming Requirements
You’re given the skeleton of three source codes, namely ShapeAnimator.h, ShapeAnimator.cpp
and TestShape.cpp.
For simplicity, please put all class declaration inside the ShapeAnimator.h file, i.e. put all classes
shown in Figure 1’s declaration inside this file.
ShapeAnimator.cpp will be the class definition file for ShapeAnimator.h
As we mentioned on pp.1, inside TestShape.cpp, within the main( ), we used certain functions
that are peculiar to Microsoft Windows OS that directly access the screen and manage the timer,
as we write the code by using a Windows machine. If you use *nix system, the same principle
applies, but you might need to change the code a little bit.
Section 4: Grading Rubric
Student correctly designed the ShapeAnimator.h file, each class definition is worth 4 pts [Total
16 pts]
Student correctly implements the ShapeAnimator.cpp file. Each function’s full definition is
worth 4 pts [Total 24 pts]
In TestShape.cpp, students correctly finished the all the codes [5 pts]
The program student submitted compiles, runs, and produces the correct output [5 pts]
--------------------------------------------------------------------------------------------------------------------
----------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------
ComplexShape
SimpleShape
Solution
main.cpp
#include "ShapeAnimator.h"
int main()
{
// Create a tent and a box
Tent tent(20, 10, 13);
Box box( 5, 10, 4, 7);
// Draw the tent and the box
tent.draw();
box.draw();
// Set direction of motion for the two shapes
tent.setDirection(-1, 0); // Tent moves straight up
box.setDirection(0, 1); // Box moves horizontally to the right
// Simultaneously move the tent and the box
for (int k = 0; k < 12; k++)
{
Sleep(75);
tent.move();
box.move();
}
box.move(); tent.move();
// Move the box farther to the right
for (int k = 0; k < 48; k++)
{
Sleep(75);
box.move();
}
// Create a complex shape composed of the tent and the box
Shape *myShapes[] = {&tent, &box};
ComplexShape cS(myShapes, 2);
// Set directions for the two shapes
tent.setDirection(1, 0);
box.setDirection(0, -1);
// Move the complex shape: this moves both the tent and the box
for (int k = 0; k < 12; k++)
{
Sleep(75);
cS.move();
}
// Continue moving the box by itself
for (int k = 0; k < 36; k ++)
{
Sleep(75);
box.move();
}
return 0;
}
ShapeAnimator.h
#include
#include
#include
#include
using namespace std;
const HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE);
// A shape has a direction and is able to move in that direction.
// The move is a virtual member function.
class Shape
{
public:
void setDirection(int drow, int dcol)
{dRow = drow; dCol = dcol;}
void getDirection(int &drow, int &dcol) const
{drow = dRow; dcol = dCol;}
virtual void move()= 0;
private:
int dCol, dRow; // Direction of motion
};
// A SimpleShape can be drawn at a given position in a specified color
class SimpleShape : public Shape
{
public:
virtual void draw() const = 0;
void getPosition(int &row, int &col) const
{
row = rowPos; col = colPos;
}
void setPosition(int row, int col)
{
rowPos = row; colPos = col;
}
void setColor(int c){ color = c; }
int getColor() const {return color; }
virtual void move();
private:
int color;
int rowPos, colPos;
};
// A Box is a rectangular type of shape
class Box : public SimpleShape
{
public:
virtual void draw() const;
Box(int rowPos, int colPos, int width, int height);
private:
int width, height;
};
class Tent : public SimpleShape
{
public:
virtual void draw() const;
Tent(int baseRowPos, int baseColPos, int length);
private:
int length;
};
// A ComplexShape is made up of simpler shapes. It is represented
// as a vector of pointers to the simpler shapes that make it up
class ComplexShape : public Shape
{
public:
ComplexShape(Shape ** shapeCollection, int shapesCount);
virtual void move();
private:
vector shapes;
};
ShapeAnimator.cpp
#include "ShapeAnimator.h"
void SimpleShape::move()
{
int dRow, dCol; // Direction of motion
int savedColor = color;
color = 0; // Drawing in color 0 erases the shape
draw();
// Compute the new postion for the shape by adding a step in
// the proper direction to the current position
getDirection(dRow, dCol);
rowPos += dRow;
colPos += dCol;
// Draw the shape at its new position in its specified color
color = savedColor;
draw();
}
//***********************************
// Draws a tent at its position *
//***********************************
void Tent:: draw() const
{
int rowPos, colPos;
COORD pos;
int currentLength = length;
// Set the color attribute
SetConsoleTextAttribute(outHandle, getColor());
getPosition(rowPos, colPos);
pos.Y = rowPos; pos.X = colPos;
// Draw the lines that form the tent beginning with
// the base and moving up toward the point
for (int r = 0; r < length/2; r++)
{
SetConsoleCursorPosition(outHandle,pos);
for (int k = 0; k < currentLength; k++)
{
cout << "*";
}
cout << endl;
pos.Y--;
pos.X ++;
currentLength -= 2;
}
// Restore normal attribute
SetConsoleTextAttribute(outHandle, 7);
}
//**********************************
// Draws a box shape *
//**********************************
void Box::draw() const
{
int rowPos, colPos;
COORD pos;
// Set the color attribute for the box
SetConsoleTextAttribute(outHandle, getColor());
getPosition(rowPos, colPos);
pos.X = colPos; pos.Y = rowPos;
// Draw the lines that make up the box
for (int r = 0; r < height; r++)
{
SetConsoleCursorPosition(outHandle, pos);
for (int c = 0; c < width; c++)
{
cout << "*";
}
cout << endl;
pos.Y++;
}
// Restore normal text attribute
SetConsoleTextAttribute(outHandle, 7);
}
//***********************************************
// Constructor sets the color, position, and *
// dimensions for a box shape, and draws *
// the box at its initial position *
//***********************************************
Box::Box(int rowPos, int colPos, int width, int height)
{
setColor(4);
setPosition(rowPos, colPos);
this->width = width;
this->height = height;
draw();
}
//***********************************************
// Constructor sets the color for a Tent shape, *
// sets the position of the tent as well as the *
// length of its base and draws it at its *
// initial position *
//***********************************************
Tent::Tent(int baseRowPos, int baseColPos, int length)
{
setColor(2);
setPosition(baseRowPos, baseColPos);
this->length = length;
draw();
}
//*********************************************************************
// Constructor builds a complex shape by assembling a vector of *
// constituent shapes *
//*********************************************************************
ComplexShape::ComplexShape(Shape ** shapeCollection, int shapesCount)
{
Shape *p;
for (int k = 0; k < shapesCount; k++)
{
p = shapeCollection[k];
shapes.push_back(p);
}
}
//**************************************
// Moves a complex shape by moving the *
// constituent shapes *
//**************************************
void ComplexShape::move()
{
for (int k = 0; k < shapes.size(); k++)
shapes[k]->move();
}

More Related Content

Similar to Please make the complete program, distinguishing between each class .pdf

A graphic library and an application for simple curve manipolation
A graphic library and an application for simple curve manipolationA graphic library and an application for simple curve manipolation
A graphic library and an application for simple curve manipolationgraphitech
 
A graphic library and an application for simple curve manipolation
A graphic library and an application for simple curve manipolationA graphic library and an application for simple curve manipolation
A graphic library and an application for simple curve manipolationgraphitech
 
2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica2D & 3D Modelling with Mathematica
2D & 3D Modelling with MathematicaMiles Ford
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_projectManish Jauhari
 
Analysing simple pendulum using matlab
Analysing simple pendulum using matlabAnalysing simple pendulum using matlab
Analysing simple pendulum using matlabAkshay Mistri
 
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaSierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
 
Image to text Converter
Image to text ConverterImage to text Converter
Image to text ConverterDhiraj Raj
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfcontact41
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programmingsrijavel
 
Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3JenniferBall44
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.comDavisMurphyB81
 
Write a Java program that creates a drawing area of appropriate size.pdf
Write a Java program that creates a drawing area of appropriate size.pdfWrite a Java program that creates a drawing area of appropriate size.pdf
Write a Java program that creates a drawing area of appropriate size.pdfboothlynntur11512
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysBlue Elephant Consulting
 
Interactive Mouse (Report On Processing)
Interactive Mouse (Report On Processing)Interactive Mouse (Report On Processing)
Interactive Mouse (Report On Processing)TongXu520
 

Similar to Please make the complete program, distinguishing between each class .pdf (20)

A graphic library and an application for simple curve manipolation
A graphic library and an application for simple curve manipolationA graphic library and an application for simple curve manipolation
A graphic library and an application for simple curve manipolation
 
A graphic library and an application for simple curve manipolation
A graphic library and an application for simple curve manipolationA graphic library and an application for simple curve manipolation
A graphic library and an application for simple curve manipolation
 
2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica2D & 3D Modelling with Mathematica
2D & 3D Modelling with Mathematica
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_project
 
CPP homework help
CPP homework helpCPP homework help
CPP homework help
 
Auto cad manual
Auto cad manualAuto cad manual
Auto cad manual
 
Analysing simple pendulum using matlab
Analysing simple pendulum using matlabAnalysing simple pendulum using matlab
Analysing simple pendulum using matlab
 
Image to Text Converter
Image to Text ConverterImage to Text Converter
Image to Text Converter
 
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaSierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
 
Image to text Converter
Image to text ConverterImage to text Converter
Image to text Converter
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
 
AUTOCAD
AUTOCADAUTOCAD
AUTOCAD
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3
 
Chapter10.pptx
Chapter10.pptxChapter10.pptx
Chapter10.pptx
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.com
 
Write a Java program that creates a drawing area of appropriate size.pdf
Write a Java program that creates a drawing area of appropriate size.pdfWrite a Java program that creates a drawing area of appropriate size.pdf
Write a Java program that creates a drawing area of appropriate size.pdf
 
State Monad
State MonadState Monad
State Monad
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & Arrays
 
Interactive Mouse (Report On Processing)
Interactive Mouse (Report On Processing)Interactive Mouse (Report On Processing)
Interactive Mouse (Report On Processing)
 

More from faxteldelhi

How dose the FAA provide oversight to insure compliance of the Safet.pdf
How dose the FAA provide oversight to insure compliance of the Safet.pdfHow dose the FAA provide oversight to insure compliance of the Safet.pdf
How dose the FAA provide oversight to insure compliance of the Safet.pdffaxteldelhi
 
For Cooperative Diversity (CD) system, please talk about its potenti.pdf
For Cooperative Diversity (CD) system, please talk about its potenti.pdfFor Cooperative Diversity (CD) system, please talk about its potenti.pdf
For Cooperative Diversity (CD) system, please talk about its potenti.pdffaxteldelhi
 
Dr. Kellie Leitch glanced at the data on wait times collected from t.pdf
Dr. Kellie Leitch glanced at the data on wait times collected from t.pdfDr. Kellie Leitch glanced at the data on wait times collected from t.pdf
Dr. Kellie Leitch glanced at the data on wait times collected from t.pdffaxteldelhi
 
Arthur Burton established Astro Airlines in 1980; two years after th.pdf
Arthur Burton established Astro Airlines in 1980; two years after th.pdfArthur Burton established Astro Airlines in 1980; two years after th.pdf
Arthur Burton established Astro Airlines in 1980; two years after th.pdffaxteldelhi
 
ASTRONOMY Martian polar caps, Dont Change with Martian the seas.pdf
ASTRONOMY Martian polar caps, Dont Change with Martian the seas.pdfASTRONOMY Martian polar caps, Dont Change with Martian the seas.pdf
ASTRONOMY Martian polar caps, Dont Change with Martian the seas.pdffaxteldelhi
 
why penicilina cant be use for walking ammonia SolutionI gu.pdf
why penicilina cant be use for walking ammonia SolutionI gu.pdfwhy penicilina cant be use for walking ammonia SolutionI gu.pdf
why penicilina cant be use for walking ammonia SolutionI gu.pdffaxteldelhi
 
Why is a monophasic recording a better representation of overall ner.pdf
Why is a monophasic recording a better representation of overall ner.pdfWhy is a monophasic recording a better representation of overall ner.pdf
Why is a monophasic recording a better representation of overall ner.pdffaxteldelhi
 
Which of the following are state functions (Select all that apply.) .pdf
Which of the following are state functions (Select all that apply.) .pdfWhich of the following are state functions (Select all that apply.) .pdf
Which of the following are state functions (Select all that apply.) .pdffaxteldelhi
 
Which of the following are NOT correctly matchedprotease lipid di.pdf
Which of the following are NOT correctly matchedprotease lipid di.pdfWhich of the following are NOT correctly matchedprotease lipid di.pdf
Which of the following are NOT correctly matchedprotease lipid di.pdffaxteldelhi
 
When add NH4OH into the solution which contains Co2+, Ni2+, Cr3+, Fe.pdf
When add NH4OH into the solution which contains Co2+, Ni2+, Cr3+, Fe.pdfWhen add NH4OH into the solution which contains Co2+, Ni2+, Cr3+, Fe.pdf
When add NH4OH into the solution which contains Co2+, Ni2+, Cr3+, Fe.pdffaxteldelhi
 
What is the role of PL SQL and why is it important Support your ans.pdf
What is the role of PL SQL and why is it important Support your ans.pdfWhat is the role of PL SQL and why is it important Support your ans.pdf
What is the role of PL SQL and why is it important Support your ans.pdffaxteldelhi
 
What does it mean to be alive What environmental, economic, politic.pdf
What does it mean to be alive What environmental, economic, politic.pdfWhat does it mean to be alive What environmental, economic, politic.pdf
What does it mean to be alive What environmental, economic, politic.pdffaxteldelhi
 
What do expect to find in the cells of lobsters to explain their imm.pdf
What do expect to find in the cells of lobsters to explain their imm.pdfWhat do expect to find in the cells of lobsters to explain their imm.pdf
What do expect to find in the cells of lobsters to explain their imm.pdffaxteldelhi
 
Using empathy when encoding a message is the most important elem.pdf
Using empathy when encoding a message is the most important elem.pdfUsing empathy when encoding a message is the most important elem.pdf
Using empathy when encoding a message is the most important elem.pdffaxteldelhi
 
This is a definition of which type of attack A technique used to ga.pdf
This is a definition of which type of attack A technique used to ga.pdfThis is a definition of which type of attack A technique used to ga.pdf
This is a definition of which type of attack A technique used to ga.pdffaxteldelhi
 
The left and right ventricles are referred to as systemic and pulmona.pdf
The left and right ventricles are referred to as systemic and pulmona.pdfThe left and right ventricles are referred to as systemic and pulmona.pdf
The left and right ventricles are referred to as systemic and pulmona.pdffaxteldelhi
 
the following is tnac ing two items 1-a Certificate of Deposit (CD),.pdf
the following is tnac ing two items 1-a Certificate of Deposit (CD),.pdfthe following is tnac ing two items 1-a Certificate of Deposit (CD),.pdf
the following is tnac ing two items 1-a Certificate of Deposit (CD),.pdffaxteldelhi
 
The first fundamental form is an intrinsic quantity. Explain what thi.pdf
The first fundamental form is an intrinsic quantity. Explain what thi.pdfThe first fundamental form is an intrinsic quantity. Explain what thi.pdf
The first fundamental form is an intrinsic quantity. Explain what thi.pdffaxteldelhi
 
The business cycle peak associated with the Great Recession was in Se.pdf
The business cycle peak associated with the Great Recession was in Se.pdfThe business cycle peak associated with the Great Recession was in Se.pdf
The business cycle peak associated with the Great Recession was in Se.pdffaxteldelhi
 
4. Explain the effect of temperature on the solubility of CO2 in wate.pdf
4. Explain the effect of temperature on the solubility of CO2 in wate.pdf4. Explain the effect of temperature on the solubility of CO2 in wate.pdf
4. Explain the effect of temperature on the solubility of CO2 in wate.pdffaxteldelhi
 

More from faxteldelhi (20)

How dose the FAA provide oversight to insure compliance of the Safet.pdf
How dose the FAA provide oversight to insure compliance of the Safet.pdfHow dose the FAA provide oversight to insure compliance of the Safet.pdf
How dose the FAA provide oversight to insure compliance of the Safet.pdf
 
For Cooperative Diversity (CD) system, please talk about its potenti.pdf
For Cooperative Diversity (CD) system, please talk about its potenti.pdfFor Cooperative Diversity (CD) system, please talk about its potenti.pdf
For Cooperative Diversity (CD) system, please talk about its potenti.pdf
 
Dr. Kellie Leitch glanced at the data on wait times collected from t.pdf
Dr. Kellie Leitch glanced at the data on wait times collected from t.pdfDr. Kellie Leitch glanced at the data on wait times collected from t.pdf
Dr. Kellie Leitch glanced at the data on wait times collected from t.pdf
 
Arthur Burton established Astro Airlines in 1980; two years after th.pdf
Arthur Burton established Astro Airlines in 1980; two years after th.pdfArthur Burton established Astro Airlines in 1980; two years after th.pdf
Arthur Burton established Astro Airlines in 1980; two years after th.pdf
 
ASTRONOMY Martian polar caps, Dont Change with Martian the seas.pdf
ASTRONOMY Martian polar caps, Dont Change with Martian the seas.pdfASTRONOMY Martian polar caps, Dont Change with Martian the seas.pdf
ASTRONOMY Martian polar caps, Dont Change with Martian the seas.pdf
 
why penicilina cant be use for walking ammonia SolutionI gu.pdf
why penicilina cant be use for walking ammonia SolutionI gu.pdfwhy penicilina cant be use for walking ammonia SolutionI gu.pdf
why penicilina cant be use for walking ammonia SolutionI gu.pdf
 
Why is a monophasic recording a better representation of overall ner.pdf
Why is a monophasic recording a better representation of overall ner.pdfWhy is a monophasic recording a better representation of overall ner.pdf
Why is a monophasic recording a better representation of overall ner.pdf
 
Which of the following are state functions (Select all that apply.) .pdf
Which of the following are state functions (Select all that apply.) .pdfWhich of the following are state functions (Select all that apply.) .pdf
Which of the following are state functions (Select all that apply.) .pdf
 
Which of the following are NOT correctly matchedprotease lipid di.pdf
Which of the following are NOT correctly matchedprotease lipid di.pdfWhich of the following are NOT correctly matchedprotease lipid di.pdf
Which of the following are NOT correctly matchedprotease lipid di.pdf
 
When add NH4OH into the solution which contains Co2+, Ni2+, Cr3+, Fe.pdf
When add NH4OH into the solution which contains Co2+, Ni2+, Cr3+, Fe.pdfWhen add NH4OH into the solution which contains Co2+, Ni2+, Cr3+, Fe.pdf
When add NH4OH into the solution which contains Co2+, Ni2+, Cr3+, Fe.pdf
 
What is the role of PL SQL and why is it important Support your ans.pdf
What is the role of PL SQL and why is it important Support your ans.pdfWhat is the role of PL SQL and why is it important Support your ans.pdf
What is the role of PL SQL and why is it important Support your ans.pdf
 
What does it mean to be alive What environmental, economic, politic.pdf
What does it mean to be alive What environmental, economic, politic.pdfWhat does it mean to be alive What environmental, economic, politic.pdf
What does it mean to be alive What environmental, economic, politic.pdf
 
What do expect to find in the cells of lobsters to explain their imm.pdf
What do expect to find in the cells of lobsters to explain their imm.pdfWhat do expect to find in the cells of lobsters to explain their imm.pdf
What do expect to find in the cells of lobsters to explain their imm.pdf
 
Using empathy when encoding a message is the most important elem.pdf
Using empathy when encoding a message is the most important elem.pdfUsing empathy when encoding a message is the most important elem.pdf
Using empathy when encoding a message is the most important elem.pdf
 
This is a definition of which type of attack A technique used to ga.pdf
This is a definition of which type of attack A technique used to ga.pdfThis is a definition of which type of attack A technique used to ga.pdf
This is a definition of which type of attack A technique used to ga.pdf
 
The left and right ventricles are referred to as systemic and pulmona.pdf
The left and right ventricles are referred to as systemic and pulmona.pdfThe left and right ventricles are referred to as systemic and pulmona.pdf
The left and right ventricles are referred to as systemic and pulmona.pdf
 
the following is tnac ing two items 1-a Certificate of Deposit (CD),.pdf
the following is tnac ing two items 1-a Certificate of Deposit (CD),.pdfthe following is tnac ing two items 1-a Certificate of Deposit (CD),.pdf
the following is tnac ing two items 1-a Certificate of Deposit (CD),.pdf
 
The first fundamental form is an intrinsic quantity. Explain what thi.pdf
The first fundamental form is an intrinsic quantity. Explain what thi.pdfThe first fundamental form is an intrinsic quantity. Explain what thi.pdf
The first fundamental form is an intrinsic quantity. Explain what thi.pdf
 
The business cycle peak associated with the Great Recession was in Se.pdf
The business cycle peak associated with the Great Recession was in Se.pdfThe business cycle peak associated with the Great Recession was in Se.pdf
The business cycle peak associated with the Great Recession was in Se.pdf
 
4. Explain the effect of temperature on the solubility of CO2 in wate.pdf
4. Explain the effect of temperature on the solubility of CO2 in wate.pdf4. Explain the effect of temperature on the solubility of CO2 in wate.pdf
4. Explain the effect of temperature on the solubility of CO2 in wate.pdf
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Please make the complete program, distinguishing between each class .pdf

  • 1. Please make the complete program, distinguishing between each class and header file. I have two .cpp files already and one .h Section 1: Project Objectives By given a class hierarchy, focus on Object-Oriented-Design concept, design and write multiple classes. Be able to apply the concepts of inheritance, polymorphism, abstract classes, pure virtual functions, function overriding, etc. Be familiar with common functions in vector class in C++. Section 2: Background Introduction Video game programmers often have to maintain a collection of figures that are simultaneously moving in various directions on the screen. In this project, we will design a solution to a simplified version of the problem. We will maintain a collection of geometric shapes and simultaneously animate those shapes. The functions used to directly access the screen and manage the timer are peculiar to Microsoft Windows, but the principles used are very general and are applicable to all operating systems. Section 3: Project Description We begin with a class that represents a shape that is able to move in any of eight different directions, with each direction being specified by a pair of integer (X, Y) coordinates. Upward or downward motion is indicated by a Y component of ±1. A value of 0 for an X or Y coordinate indicates lack of motion in that direction. Thus, a value of (0,-1) for (X, Y) indicates motion straight up, a value of (-1, 0) indicates motion to the left, and (1, 1) indicates motion that is simultaneously downward and to the right. In this project, you will need to design five classes, namely Shape, ComplexShape, SimpleShape, Box and Tent. These classes form the inheritance hierarchy as showing in the following figure. Shape ComplexShape SimpleShape Box Tent Figure 1 1 Section 3.1: Classes Description The Shape class has a move() function that is pure virtual. This is because a shape is moved by erasing it at its current position and redrawing it at new position and it is not possible to know how to draw a shape without knowing what type of shape it is.
  • 2. The SimpleShape class represents objects that can be drawn at a given position in a specified color. Accordingly, it has member variables for representing position and color and member functions for setting and accessing those values. The SimpleShape class inherits from Shape, notice that the SimpleShape class is still abstract because if provides no implementation for the draw() method. The class does implement the move() method, though. The is because the move() method works the same way for all subclasses of SimpleShape: erase the shape at its current position, compute its new position, and draw the shape at the new position. The draw() method, however, works differently for each concrete subclass that implements it. Because draw() is virtual, the move() method will always call the appropriate version of draw(), even when the call to draw() is through a pointer to the abstract class Shape. The Box and Tent classes are the concrete classes at the tip of the inheritance hierarchy. They define a specific concrete shape and implement the member function draw() that draws the shape at its current position using the shape’s specified color. The Box class defines a rectangular shape by specifying the positon of its tope left-hand corner together with its width and height. The Tent class defines a triangle with a horizontal base whose two other sides are equal in length and whose height is half the length of the base. A Tent object is specified by giving the position of the left end point of its base together with the length of the base. For example, a tent whose base has length 5 would look like this: * * * * * * * The CompletShape class provides a mechanism for assembling a collection of simple shapes to form a single shape that can be moved using a single command. The class maintains a vector of pointers to Shape objects, and implements its move() method is by calling the move() methods of all the Shape objects in its collections. Likewise, ComplexShape has a setDirection() method that can be used to cause all of its constituent shapes to move in the same direction. Program TestShape.cpp is the driver’s program which we will use to test all of above classes. The program starts out by creating two simple shapes - a tent and a box. The tent is created at the left edge of the screen while the box is near the right edge. The program moves the tent to the right at the same time that it is moving the box to the left, stopping the motion when the two shapes are within a few coordinates of each other. Line 27-39 create a complex shape out of the two simple shapes, and then moves the complex shape diagonally downward and to the right. Finally, the program moves the box horizontally to the right. 2 Section 3.2: UML Diagrams for Each Class 1. Shape class
  • 3. Shape -dRow : int -dCol : int +setDirection(int, int ) : void +getDirection(int &, int &) : void +move() : void = 0 Member Data Type Description Variable dRow int This represents the direction of row motion. dCol int This represents the direction of row motion. Member Function void setDirection(int drow, int dcol) Function Description This function should initialize all member variable by the initial value defined inside the UML. This function need to be override later by inherited classes, i.e. it need to be declared virtual. void getDirection(int &drow, int &dcol) virtual void move() = 0 This function initializes member variable dRow, dCol with the input parameter. This is a pure virtual function 2. SimpleShape class (inherited from Shape class) A SimpleShape is drawn at a give position in a specified color SimpleShape -rowPos : int -ColPos : int -color : int +getPosition(int &, int &) : void +setPosition(int, int ) : void +getColor() : int +setColor(int ) : void +move() : void Member Data Type Description Variable rowPos int This represents the X position of the shape that to be drawn. colPos
  • 4. int This represents the Y position of the shape that to be drawn. color int This represents the color of the shape 3 Member Function Function Description void getPosition(int &row, int &col) void setPosition(int row, int col ) int getColor() Void setColor(int c) This function should initialize member variable rowPos & colPos with the input parameters. This is the mutator for member variable rowPos & colPos. This is the accessor for member variable color. This is the mutator for member variable color. 3. Box class (inherited from SimpleShape class) A Box is a rectangular type of shape Box -width : int -height : int +Box(int, int, int, int) +draw() : virtual void Member Function Box(int rowPos, int colPos, int width, int height) virtual void draw() Function Description This is the constructor, it sets the color, position and dimensions for a box shape, and draws the box at its initial position This function draw the lines that make up the box (a rectangle shape of * 4. Tent class (inherited from SimpleShape class) A Tent is an isosceles triangle whose horizontal base has a given length and whose height is half the length of the base. The position of the triangle is the left end point of the base. Tent -baseLength : int +Tent(int, int, int) +draw() : virtual void Member Function
  • 5. Tent(int baseRowPos, int baseColPos, int baseLength) virtual void draw() Function Description This is the constructor, it sets the color for a Tent shape, sets the position of the tent as well as the length of its base and draw it at its initial position. This function draw the lines that make up the tent. 4 5. ComplexShape class (inherited from Shape class) A ComplexShape is made up of simpler shapes. It is represented as a vector of pointers to the simpler shapes that make it up. ComplexShape -shapes : vector +ComplexShape(Shape **, int) +move() : virtual void +setDirection(int, int) : virtual void Member Function ComplexShape(Shape ** shapeCollection, int shapesCount)) Virtual void move() virtual void setDirection(int dRow, int dCol) 6. TestShape class Function Description This is the constructor, it builds a complex shape by assembling a vector of constituent shapes. Moves a complex shape by moving the constituent shapes. Sets the direction of a complex shape by setting the direction of all constituent shapes This is the driver’s program used to test on the various Shape classes and subclasses and do the graphic animation. TestShape class contains only main() function, within main() function, you’re required to do the following: Create a Tent object with initial row & column position at 11, 5 respectively. Also initialize its base length to be 13. Crate a Box object with initial row & column position at 5, 65 respectively. Also initialize its width and height to be 4, 7 respectively. Draw above created Tent and Box objects by calling their draw() function Set above Tent object’s initial direction of motion, let it move horizontally to the right. Set above Box object’s initial direction of motion, let it move horizontally to the left. Simultaneously move the tent and the box. Note: this will make them move towards each other. Create a complex shape composed of the tent and the box.
  • 6. Set the direction for the complex shape and move the complex shape: this moves both the tent and the box diagonally to the right. Move the box by itself horizontally to the right. 5 Section 3.3: Miscellaneous Programming Requirements You’re given the skeleton of three source codes, namely ShapeAnimator.h, ShapeAnimator.cpp and TestShape.cpp. For simplicity, please put all class declaration inside the ShapeAnimator.h file, i.e. put all classes shown in Figure 1’s declaration inside this file. ShapeAnimator.cpp will be the class definition file for ShapeAnimator.h As we mentioned on pp.1, inside TestShape.cpp, within the main( ), we used certain functions that are peculiar to Microsoft Windows OS that directly access the screen and manage the timer, as we write the code by using a Windows machine. If you use *nix system, the same principle applies, but you might need to change the code a little bit. Section 4: Grading Rubric Student correctly designed the ShapeAnimator.h file, each class definition is worth 4 pts [Total 16 pts] Student correctly implements the ShapeAnimator.cpp file. Each function’s full definition is worth 4 pts [Total 24 pts] In TestShape.cpp, students correctly finished the all the codes [5 pts] The program student submitted compiles, runs, and produces the correct output [5 pts] -------------------------------------------------------------------------------------------------------------------- ---------------------------------- -------------------------------------------------------------------------------------------------------------------- ---------------------------------- -------------------------------------------------------------------------------------------------------------------- ---------------------------------- ComplexShape SimpleShape Solution main.cpp #include "ShapeAnimator.h" int main() {
  • 7. // Create a tent and a box Tent tent(20, 10, 13); Box box( 5, 10, 4, 7); // Draw the tent and the box tent.draw(); box.draw(); // Set direction of motion for the two shapes tent.setDirection(-1, 0); // Tent moves straight up box.setDirection(0, 1); // Box moves horizontally to the right // Simultaneously move the tent and the box for (int k = 0; k < 12; k++) { Sleep(75); tent.move(); box.move(); } box.move(); tent.move(); // Move the box farther to the right for (int k = 0; k < 48; k++) { Sleep(75); box.move(); } // Create a complex shape composed of the tent and the box Shape *myShapes[] = {&tent, &box}; ComplexShape cS(myShapes, 2); // Set directions for the two shapes tent.setDirection(1, 0); box.setDirection(0, -1); // Move the complex shape: this moves both the tent and the box for (int k = 0; k < 12; k++) { Sleep(75); cS.move(); } // Continue moving the box by itself
  • 8. for (int k = 0; k < 36; k ++) { Sleep(75); box.move(); } return 0; } ShapeAnimator.h #include #include #include #include using namespace std; const HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE); // A shape has a direction and is able to move in that direction. // The move is a virtual member function. class Shape { public: void setDirection(int drow, int dcol) {dRow = drow; dCol = dcol;} void getDirection(int &drow, int &dcol) const {drow = dRow; dcol = dCol;} virtual void move()= 0; private: int dCol, dRow; // Direction of motion }; // A SimpleShape can be drawn at a given position in a specified color class SimpleShape : public Shape { public: virtual void draw() const = 0; void getPosition(int &row, int &col) const { row = rowPos; col = colPos; }
  • 9. void setPosition(int row, int col) { rowPos = row; colPos = col; } void setColor(int c){ color = c; } int getColor() const {return color; } virtual void move(); private: int color; int rowPos, colPos; }; // A Box is a rectangular type of shape class Box : public SimpleShape { public: virtual void draw() const; Box(int rowPos, int colPos, int width, int height); private: int width, height; }; class Tent : public SimpleShape { public: virtual void draw() const; Tent(int baseRowPos, int baseColPos, int length); private: int length; }; // A ComplexShape is made up of simpler shapes. It is represented // as a vector of pointers to the simpler shapes that make it up class ComplexShape : public Shape { public: ComplexShape(Shape ** shapeCollection, int shapesCount); virtual void move(); private:
  • 10. vector shapes; }; ShapeAnimator.cpp #include "ShapeAnimator.h" void SimpleShape::move() { int dRow, dCol; // Direction of motion int savedColor = color; color = 0; // Drawing in color 0 erases the shape draw(); // Compute the new postion for the shape by adding a step in // the proper direction to the current position getDirection(dRow, dCol); rowPos += dRow; colPos += dCol; // Draw the shape at its new position in its specified color color = savedColor; draw(); } //*********************************** // Draws a tent at its position * //*********************************** void Tent:: draw() const { int rowPos, colPos; COORD pos; int currentLength = length; // Set the color attribute SetConsoleTextAttribute(outHandle, getColor()); getPosition(rowPos, colPos); pos.Y = rowPos; pos.X = colPos; // Draw the lines that form the tent beginning with // the base and moving up toward the point for (int r = 0; r < length/2; r++) {
  • 11. SetConsoleCursorPosition(outHandle,pos); for (int k = 0; k < currentLength; k++) { cout << "*"; } cout << endl; pos.Y--; pos.X ++; currentLength -= 2; } // Restore normal attribute SetConsoleTextAttribute(outHandle, 7); } //********************************** // Draws a box shape * //********************************** void Box::draw() const { int rowPos, colPos; COORD pos; // Set the color attribute for the box SetConsoleTextAttribute(outHandle, getColor()); getPosition(rowPos, colPos); pos.X = colPos; pos.Y = rowPos; // Draw the lines that make up the box for (int r = 0; r < height; r++) { SetConsoleCursorPosition(outHandle, pos); for (int c = 0; c < width; c++) { cout << "*"; } cout << endl; pos.Y++; } // Restore normal text attribute
  • 12. SetConsoleTextAttribute(outHandle, 7); } //*********************************************** // Constructor sets the color, position, and * // dimensions for a box shape, and draws * // the box at its initial position * //*********************************************** Box::Box(int rowPos, int colPos, int width, int height) { setColor(4); setPosition(rowPos, colPos); this->width = width; this->height = height; draw(); } //*********************************************** // Constructor sets the color for a Tent shape, * // sets the position of the tent as well as the * // length of its base and draws it at its * // initial position * //*********************************************** Tent::Tent(int baseRowPos, int baseColPos, int length) { setColor(2); setPosition(baseRowPos, baseColPos); this->length = length; draw(); } //********************************************************************* // Constructor builds a complex shape by assembling a vector of * // constituent shapes * //********************************************************************* ComplexShape::ComplexShape(Shape ** shapeCollection, int shapesCount) { Shape *p; for (int k = 0; k < shapesCount; k++)
  • 13. { p = shapeCollection[k]; shapes.push_back(p); } } //************************************** // Moves a complex shape by moving the * // constituent shapes * //************************************** void ComplexShape::move() { for (int k = 0; k < shapes.size(); k++) shapes[k]->move(); }