Mega Code Archive
This program draws right triangles
#include
using namespace std;
class triangle {
int height, base;
public:
triangle(int h, int b) { height = h; base = b; }
friend ostream &operator<<(ostream &stream, triangle ob);
};
// Draw a triangle.
ostream &operator<<(ostream &stream, triangle ob)
{
int i, j, h, k;
i = j = ob.base-1;
for(h=ob.height-1; h; h--) {
for(k=i; k; k--)
stream << ' ';
stream << '*';
if(j!=i) {
for(k=j-i-1; k; k--)
stream << ' ';
stream << '*';
}
i--;
stream << '\n';
}
for(k=0; k