1

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

11
Contributors
15
Replies
31
Views
9 Years
Discussion Span
Last Post by Fuseteam
0

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

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

0

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.

0

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

0

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

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

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

0

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

0

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

0

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);
}

Edited by ankurgecr: n/a

-2
#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;
}

Edited by Nick Evan: Fixed formatting

0

why not with

#include<iostream>
using namespace std;

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

:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.