Hi, i have a project using basic inheritance to output shapes, but i would like to make it draw the shapes aswell.
Does anyone know where i can find tutorials on how to draw shapes in dos using C++?

thanks

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

i need a basic way to draw shapes, is there an easier way? i was hoping it would run in a dos window.
thansk

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

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.

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.

how do i find out about it?
dont think the help is working on my comp...
is the file in the visual c++ libries?
thanks

This thread may interest you. But no, you can not use those libraries with any Microsoft compiler.

do you know any method in which to draw hearts all over the screen in C++?..please help me..I want to make my bf a gift:P..thanks:D:)

do you know any method in which to draw hearts all over the screen in C++?

I sure do:

#include <iostream>

int main()
{
    for (int x = 0; x < 1000; ++x) std::cout << "<3";
}

:D

thanks..>:D<

I sure do:

#include <iostream>

int main()
{
    for (int x = 0; x < 1000; ++x) std::cout << "<3";
}

:D

this doesnt work.......there is no return....no mention of std???

The return 0; is implicit and the std:: qualifier on cout means that you don't need the using namespace std; line.

> 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).

do you know any method in which to draw hearts all over the screen in C++?..please help me..I want to make my bf a gift:P..thanks:D:)

#include <stdio.h>
int main()
{
   	while(1) printf("%c",3);
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    cout<<"\aE\an\at\ae\ar\n \at\ah\ae \t\t\av\aa\al\au\ae\as \t\t\ao\af \n\ax\a,\ay\a,\az \t\t\aa\an\ad \t\t\ao\au\at\ap\au\at \n\af\ao\aa\am \tt\ah\ai\as \t\t\a(\ax\a*\ax\a)\a+\ay\a+\az \n\aa\an\ad \t\t\aa\al\as\ao \t\t\ao\au\at\ap\au\at \n\ao\af \t\t\aa\a,\ab\a,\ac \t\t\ai\an \n\t\t\as\ai\an\a,\ac\ao\as \a& \at\aa\an\a:"<<endl;
    int x,y,z;
    cin>>x;
    cin>>y;
    cin>>z;
    float b=30;
    float result1=sin(b);
    float c=60;
    float result2=sin(c);
    float d=60;
    float result3=sin(d);
    int result=(x*x)+y+z;
    cout<<result<<'\t'<<result1<<'\t'<<result2<<'\t'<<result3<<endl;
    return 0;
}

why not with

#include<iostream>
using namespace std;

int main(int argc, char* argv[])
{
 char ch=3; 
 for(;;)
 {
  cout<<ch;
 }
 return 0;
}

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.