954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Drawing shapes in c++

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

kgz
Newbie Poster
12 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

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
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

kgz
Newbie Poster
12 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

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
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

kgz
Newbie Poster
12 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

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

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

vyo_bog
Newbie Poster
2 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 
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

Tom Gunn
Master Poster
733 posts since Jun 2009
Reputation Points: 1,446
Solved Threads: 135
 

thanks..>:D

vyo_bog
Newbie Poster
2 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

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???

ishaangt
Newbie Poster
3 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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
Team Colleague
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
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
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);
}
ankurgecr
Newbie Poster
5 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

#include
#include
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:"<>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<

sheryar.niazi
Newbie Poster
1 post since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

why not with

#include<iostream>
using namespace std;

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


:)

Fuseteam
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You