I made figures with * and when i display it once it works fine but if i try to display it again and again it, the botton of the figure is the only thing that shows I am not sure what is wrong with the loops?
maybe someone can see what is wrong
thanks in advance
#pragma once
/*GOYO
*/
class Shape
{
public:
virtual void Draw ()=0;
virtual void Clear()=0;
virtual void Center()=0;
};
#include"Shape.h"
#include"Triangle.h"
#include"Rectangle.h"
#include"Square.h"
using namespace std;
int main()
{
Square squar;
Rectangle rect;
//rect.Draw();
Triangle tri;
//tri.Draw();
void menu();
char shape;
while(true)
{
void menu(char&shape);
{
cout<<"please select one of the following"<<endl;
cout<<"E Erase shape:\n"
<<"S Square:\n"
<<"R Rectangle:\n"
<<"T Triangle:\n"<<endl;
cin>>shape;
shape = static_cast<char>(toupper(shape));
while(shape != 'E' && shape != 'R'
&& shape && shape != 'T'&& shape !='S')
{
cout<<"please select one of the following"<<endl;
cout<<"E Erase shape:\n"
<<"S Square:\n"
<<"R Rectangle:\n"
<<"T Triangle:\n"<<endl;
cin>>shape;
shape = static_cast<char>(toupper(shape));
}///end while
switch(shape)
{
case 'E':
tri.Clear();
break;
case 'S':
squar.Draw();
break;
case 'R':
rect.Draw();
break;
case 'T':
tri.Draw();
break;
}// end switch
}//menu;
}
return 0;
}
#include<iostream>
#include"Shape.h"
using namespace std;
/*
RECTANGLE
*/
class Rectangle : public Shape
{
public:
Rectangle ();
virtual void Draw ();
virtual void Clear();
virtual void Center();
private:
int height;
int row;
int col;
};
Rectangle::Rectangle()
{ height = 5;
row = 0;
col = 0;
}
void Rectangle::Draw()
{
// draw top line
while (col < height * 2)
{
cout << '*';
++col;
}
cout << endl;
++row;
// draw middle lines
while (row < height - 1)
{
col = 0;
while (col <= height * 2)
{
++col;
if (col == 1)
cout << '*';
else {
if (col == height * 2)
cout << '*';
else
cout << ' ';
}
}
cout << endl;
++row;
}
// draw bottom line
col = 0;
while (col < height * 2)
{
cout << '*';
++col;
}
// new line after figure
cout << endl;
// blank line between figures
cout << endl;
}
void Rectangle::Clear()
{
system("cls");
}
void Rectangle::Center()
{
Clear();
Draw();
}
/* triangle */
#include"Shape.h"
#include<iostream>
using namespace std;
class Triangle : public Shape
{
public:
Triangle();
virtual void Draw();
virtual void Clear();
virtual void Center();
private:
int col;
int row;
int height;
};
Triangle::Triangle()
{
col=0;
height = 5;
row =0;
}
void Triangle::Draw()
{
// draw rows above base
while (row < height - 1)
{
col = 0;
while (col < height + row) {
++col;
if (col == height - row)
cout << '*';
else {
if (col == height + row)
cout << '*';
else
cout << ' ';
}
}
cout << endl;
++row;
}
// draw the base
col = 0;
while (col < height * 2 - 1) {
cout << '*';
++col;
}
// new line after figure
cout << endl;
}
void Triangle::Clear()
{
system("cls");
}
void Triangle::Center()
{
Clear();
Draw();
}