how can i make graphs with C?

This is a discussion on how can i make graphs with C? within the C Programming forums, part of the General Programming Boards category; i have an exercise here to be passed in school about creating graphs such as line and arcs... how can ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    9

    how can i make graphs with C?

    i have an exercise here to be passed in school about creating graphs such as line and arcs... how can i start making one? i really dont know how to make one.

    here are some details..

    1. i need to choose what graph should i make. wheter a line or an arc.

    1.1 if i choose line, i need to input 2 coordinates. (eg. (70,4), (10,15)

    2. the range of x axis is 80, the range of y axis is 20...

    3. the upper left corner is the origin (0,0). the positive x axis is to the right, the positive y axis is to downwards.

    4. if i choose arc, the following formula is to be followed : y^2 = 4ax

    if you want to help me out you can email me at: <<snipped>>

    thx in advance to those who can help. btw, the submission is on the 19th of january. i barely have 20 days to make the program. thx again.
    Last edited by Salem; 12-29-2007 at 07:57 AM. Reason: Snipped email address. You posted here, you read it here.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    You didn't say what platform. If it's Windows, check out Charles Petzold's book "Programming Windows Fifth Edition". It will tell you EXACTLY how to do what you need to do.

    Todd

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    Well which graphics library you choose depends a great deal on which Operating system and compiler you use.
    So can you tell us a bit of background to help narrow the suggestions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    Quote Originally Posted by Salem View Post
    Well which graphics library you choose depends a great deal on which Operating system and compiler you use.
    So can you tell us a bit of background to help narrow the suggestions.
    i use windows vista, im using the turbo c because some fcns can't be used in c++... i always get error when compiling in my devc++...

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,184
    Turbo C is horribly old and poor.
    If you can't use something in Dev-C++, it's probably because you're doing it wrong.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Using Turbo C on Windows Vista is one way to horribly screw up your perception of C programming.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is just a Christmas card type of thing, from DOS days. The screen ratio is all screwy with Windows and the newer/bigger monitors, but anyway.

    It shows in the sine-wave portion of it, one way to draw with Turbo C, on the screen, using nothing from Windows (because Windows was still a twinkle in Xerox's Parc Research Center's eye, at that time.

    Can you show an example of what you want the final output to look like, and what have you got so far?

    Code:
    #include <graphics.h>
    #include <conio.h>
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <dos.h>
    
    const int pi=3.1415927;  	/*part of the initial sinewave drawing */
    
    void main()
      {
      void drawstar();
      int graphdriver, graphmode, errorcode, i;
      double swing, width, crest, ypos;
    
      graphdriver = DETECT;
      initgraph(&graphdriver, &graphmode, "C:\\TC\\BGI");
      errorcode = graphresult();
      if (errorcode != grOk)
        {
        printf("Graphics System Error: %s\n",grapherrormsg (errorcode));
        exit(1);
        }
      ypos = getmaxy() /2;
      crest = getmaxy() /4;
      width = getmaxx();
      for (i=0; i<width; i++)
        {
        swing=crest*sin(10*pi*i/width);
        putpixel(i, ypos+swing, RED);
        putpixel(i, ypos-swing, BLUE);
        }
      sleep(2);
      drawstar();
      closegraph();
      }
    void drawstar()
      {
      cleardevice();   //NOT clrscr();
      setcolor(BLACK);
      int x,y;
      int half1[] = {120,20, 106,40, 80,40, 93,60, 80,80, 106,80, 120,100, 134,80, 160,80, 147,60, 160,40, 134,40, 120,20};
      fillpoly(13, half1);
      setcolor(BLUE);
      settextstyle(TRIPLEX_FONT, HORIZ_DIR, 2);
      outtextxy(190,20, "... and a bright star shone in the East");
      setcolor(RED);
      settextstyle(GOTHIC_FONT, HORIZ_DIR, 8);
      outtextxy(33,30, "Merry Christmas");  
      settextstyle(GOTHIC_FONT, HORIZ_DIR, 6);
      outtextxy(95,120, "and Happy Holidays");
    /*  outtextxy(190,90, "to Everyone at"); */
    /*  settextstyle(GOTHIC_FONT, HORIZ_DIR, 8); */
    /*  outtextxy(30,120, "  This  Home"); */
      getch();
      }

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > i use windows vista, im using the turbo c because some fcns can't be used in c++
    So you're another person who's bought a Ferrari, and replaced the engine with an elastic band.

    If I told you that no matter how many processors your machine has, and how many GB of memory you have, and how long your filenames can be, that you're restricting yourself to
    - 1 processor
    - 640K (Yes, K, not M or G) bytes of memory
    - 8.3 filenames.

    Plus, any graphics you might get will be limited to probably at most 800x600 and 256 colours.

    Are you going to reconsider your use of that stone-age compiler.


    > ... i always get error when compiling in my devc++...
    Perhaps if you posted code and error messages, we could tell you what to do about it.
    For starters, there is no graphics.h, and the BGI graphical API is dead.

    If you get dev-c++, the first thing you do is download the libsdl "devpak", and then get yourself over to www.libsdl.org and read some tutorials.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    If I told you that no matter how many processors your machine has, and how many GB of memory you have, and how long your filenames can be, that you're restricting yourself to
    - 1 processor
    - 640K (Yes, K, not M or G) bytes of memory
    - 8.3 filenames.
    Lol, that really is awful.

    Definitely have a go at getting DevCpp to work. SDL is quite simple for doing 2d graphics with, and the newer versions of DevCpp have a package manager that can do all the setup for you.

    [edit]Actually now I remember: I couldent get devcpp to work on vista either so I just started using MSVC++ instead until I switched to Ubuntu. I really don't like vista. XP is just so much better. [/edit]
    Last edited by mike_g; 01-01-2008 at 12:33 PM.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    thanks for all your replies... sorry that im not so used in c language. i just started about a month ago and i dont learn anything at all from my professors. they just keep giving us work not backing us with important information on how to do it.. sorry to bother all of you who are masters in this... hope you understand my situation... all what i was trying to do was to gain some information on how to make my work done but it seems i didnt get any help coz u all just gave your comments and not helping with my problem... you all have the mind but it is all you've got..

    >dont reply anymore with useless comments.... they wont help me either..

  11. #11
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    Quote Originally Posted by Elysia View Post
    Turbo C is horribly old and poor.
    If you can't use something in Dev-C++, it's probably because you're doing it wrong.
    i know im not doing it wrong.. it does not compile because some functions can't be read by cpp... get it master elysia?

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    all what i was trying to do was to gain some information on how to make my work done but it seems i didnt get any help coz u all just gave your comments and not helping with my problem.
    The comments are intended to help you with your problem. Namely, they suggest that:

    1. You use a newer compiler and IDE.
    2. You download an IDE package with the library you need.
    3. You search for the information on getting started yourself at the library's website.

    i know im not doing it wrong.. it does not compile because some functions can't be read by cpp.
    Which functions might they be? If you really are such a beginner, how do you know that what you think you know is correct?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    Quote Originally Posted by Salem View Post
    Are you going to reconsider your use of that stone-age compiler.
    I fired up Turbo C a few months ago just for giggles. A bunch of good old memories came flooding right back. It's sad to see good products become obsolete, although that's the way of things.

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > i know im not doing it wrong.. it does not compile because some functions can't be read by cpp.
    Until you post some of YOUR code, there isn't much anyone else can do, irrespective of whichever compiler you're using.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,184
    Quote Originally Posted by anchee123 View Post
    i know im not doing it wrong.. it does not compile because some functions can't be read by cpp... get it master elysia?
    Post your code and we'll see if we can get it work in Dev-C++ or Visual Studio or whatever and we'll see who's "right."
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 08:51 PM
  2. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  3. make all rule
    By duffy in forum C Programming
    Replies: 9
    Last Post: 09-11-2003, 01:05 PM
  4. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 11:50 AM
  5. Replies: 6
    Last Post: 04-20-2002, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21