depends on the operating system if you want GUI shapes what look like the shape should. But if you are a beginner that is way to far advanced for you. But if you're looking for punishment, you can use Windows GDI functions
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
you could make approximate drawings using character based graphics.
#include<iostream>
#include<string>
#include <cassert>
struct shape
{
virtual void draw() const = 0 ;
virtual ~shape() {}
};
struct rectangle : shape
{
explicit rectangle( int h = 10, int w = 10 ) : height(h), width(w)
{ assert( h>2 && w>2 ) ; }
virtual void draw() const ; // override
private:
int height ;
int width ;
};
void rectangle::draw() const
{
std::string top_bottom( width, '*' ), middle( width, ' ' ) ;
middle[0] = middle[width-1] = '*' ;
std::cout << top_bottom << '\n' ;
for( int i=0 ; i<(height-2) ; ++i ) std::cout << middle << '\n' ;
std::cout << top_bottom << '\n' ;
}
int main()
{
shape* s = new rectangle( 8, 12 ) ;
s->draw() ;
delete s ;
}
note: a circle would be much more interesting
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
yes rectangles are pretty simple, arcs and circles are much more difficult and don't look good because of squared-off corners.
you can check out graphics.h that is supported by Boaland's compilers. But that compiler may not support most current c++ standards that you may be studying.
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
This thread may interest you. But no, you can not use those libraries with any Microsoft compiler.
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
The return 0; is implicit and the std:: qualifier on cout means that you don't need the using namespace std; line.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
> this doesnt work.......there is no return....no mention of std???
Did you try it, before bumping this dead thread?
If so, which ancient compiler did you use (probably some turboc fossil no doubt).
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953