1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
class Shape
{
private :
int x;
int y;
public :
Shape();
Shape(int newx, int newy);
int getX ();
int getY();
void setX(int newx);
void setY (int newy);
virtual void draw();
};
Shape :: Shape (){}
Shape :: Shape(int newx, int newy){}
int Shape :: getX(){return x;}
int Shape :: getY(){return y;}
void Shape :: setX(int newx){x= newx;}
void Shape :: setY(int newy){y= newy;}
void Shape :: draw(){
{
for(int i=0; i<x; i++)
{
for(int j=0; j<y; j++)
cout << ".";
cout<<endl;
}
}
}
class Rectangle : public Shape
{
private:
int width;
int height;
public:
Rectangle();
Rectangle(int newx, int newy, int widthR, int heightR);
int getWidth();
int getHeight();
void setWidth(int widthR);
void setHeight(int heightR);
void draw();
};
Rectangle :: Rectangle (){};
Rectangle::Rectangle(int newx, int newy, int widthR, int heightR): Shape(newx, newy) {
setWidth(widthR);
setHeight(heightR);
}
int Rectangle :: getWidth(){return width;}
int Rectangle :: getHeight(){return height;}
void Rectangle::setWidth(int widthR) { width = widthR; }
void Rectangle::setHeight(int heightR) { height = heightR;}
void Rectangle::draw() {
for(int i=0; i<height; i++)
{
for(int j=0; j<width; j++)
cout << "B";
cout<<endl;
}
}
class Square: public Shape
{
private:
int width_square;
int height_square;
public:
Square();
Square(int newx, int newy, int heightS,int widthS);
int getHeightS();
int getWidthS();
void setHeightS(int heightS);
void setWidthS(int widthS);
void draw();
};
Square :: Square (){};
Square::Square(int newx, int newy, int heightS, int widthS): Shape(newx, newy) {
setHeightS(heightS);
setWidthS(widthS);
}
int Square :: getHeightS(){return height_square;}
int Square :: getWidthS(){return width_square;}
void Square::setHeightS(int heightS) { height_square = heightS;}
void Square::setWidthS (int widthS) { width_square = widthS; }
void Square :: draw ()
{
for (int i=1; i<=width_square; i++)
{
for (int j=1; j<=width_square; j++)
cout << "C";
cout << endl;
}
}
class Triangle: public Shape
{
private:
int height_T;
int width_T;
public:
Triangle();
Triangle(int newx, int newy, int heightT,int widthT);
int getHeightT();
int getWidthT();
void setHeightT(int heightT);
void setWidthT(int widthT);
void draw();
};
Triangle::Triangle(int newx, int newy, int heightT, int widthT): Shape(newx, newy) {
setHeightT(heightT);
setWidthT(widthT);
}
int Triangle :: getHeightT(){return height_T;}
int Triangle:: getWidthT(){return width_T;}
void Triangle::setHeightT(int heightT) { height_T = heightT;}
void Triangle::setWidthT (int widthT) { width_T = widthT; }
void Triangle :: draw ()
{
for(int i = 1, k = 0; i <= width_T; ++i, k = 0)
{
for(height_T = 1; height_T <= width_T-i; ++height_T)
{
cout <<" ";
}
while(k != 2*i-1)
{
cout << "* ";
++k;
}
cout << endl;
}
}
int main()
{
int height = 0;
int length= 0;
int count = 0;
Shape temp(0,0);
ifstream source("Batch.txt");
if (source.is_open())
{
while (source >>height >> length)
{
Shape s;
s.setX(height);
s.setY(length);
s.draw();
Rectangle r;
r.setWidth(length);
r.setHeight(height);
r.draw();
}
}
else
cout << "Source file failed to open.\n";
source.close();
return 0;
}
|