1. Please write the following c++ program. 2. Also, please show all outputs. Bum
ID: 3775797 • Letter: 1
Question
1. Please write the following c++ program.
2. Also, please show all outputs.
Bumper shapes
Write a program that creates two rectangular shapes and then animates them. The two shapes should start on opposite ends of the screen and then move toward each other. When they meet in the middle of the screen, each shape reverses course and moves toward the edge of the screen. The two shape keep oscillating and bouncing off of each other in the middle of the screen. The program terminates when the shape meet each other in the middle for the tenth times.
Your program must use concepts of Object Oriented Programming (Class, polymorphism and virtualfunctions)
Your program must be documented (indentation, comments, good use of variables). Use two different colors to show rectangular shape.
Explanation / Answer
program
#include<iostream.h>
#include<vector>
#include<string>
#include<windows.h>
using namespace std;
const HANDLE outhandle = GetstdHandle(STD_OUTPUT_HANDLE)
class shape
{
public:
virtual void setDirection(int drow, int dcol)
{
dRow=drow;
dCol=dcol;
}
void getDirection(int &drow, int dcol)
{
drow=dRow;
dcol=dcol;
}
virtual void move() =0;
private:
int dRow,dCol;
}
class SimpleShape : public Shape
{
public:
virtual void draw()=0;
void getPosition(int &row, int &col )
{
row=rowPos;
col=colPos;
}
void setPosition(int row, int col )
{
row=rowPos;
col=colPos;
}
void setColor(int c)
{
color=c;
}
int getCOlor()
{
return color;
}
virtual void move();
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.