Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
March 7th, 2003, 05:11 AM
 willo
Junior Member

Join Date: Feb 2003
Location: Liverpool
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
Graphs In C

How do you create a basic graph in C. I am using the borland compiler and i need the program to ask the user for the step size and the starting point of x.

Thanks

#2
March 7th, 2003, 06:37 AM
 Jason Doucette
jasondoucette.com

Join Date: Feb 2003
Posts: 378
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
I think we need more information to answer your question. Such as: are you writing a console app, or do you have graphics unit, are you using DirectX/OpenGL, etc. What is your compiler (i.e. DOS, win32, etc)? And what type of graphs do you wish to draw? It would help us understand what you mean by 'starting point of x' and 'step size'.

#3
March 7th, 2003, 04:45 PM
 willo
Junior Member

Join Date: Feb 2003
Location: Liverpool
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
Basicly i wish to create an .exe file that will run in windows. The compiler is win32 (Youll have to bear with me im new to all ths)

|
|
|
|
|
|
_|_______________
|

Above is how i wish my graph to look. The step size is the amount of units on the x axis between the current number and future number. i.e. 2, 4, 6 The setp size is 2 because there are two spaces in between each number.

The starting point of the X axis is the number it starts on. So if the starting point was 5, and the step number is 5 the graph would start: 5, 10, 15, 20

Thanks

#4
March 7th, 2003, 07:23 PM
 Jason Doucette
jasondoucette.com

Join Date: Feb 2003
Posts: 378
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
So, you are looking to plot an equation, like y = 2*x^2 - 3*x + 2 or y = cos(x) for example (i.e. where y is a function of x)?

#5
March 8th, 2003, 04:54 AM
 willo
Junior Member

Join Date: Feb 2003
Location: Liverpool
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
yes my formula is

Y=2X+5

#6
March 8th, 2003, 12:20 PM
 Jason Doucette
jasondoucette.com

Join Date: Feb 2003
Posts: 378
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
Are you looking to create the graph in a high resolution bitmap mode (if so, what graphics API are you using?), or just a simple one in text mode?

#7
March 8th, 2003, 04:10 PM
 willo
Junior Member

Join Date: Feb 2003
Location: Liverpool
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
simple one in text

#8
March 8th, 2003, 04:53 PM
 Jason Doucette
jasondoucette.com

Join Date: Feb 2003
Posts: 378
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
An easy way to do this is to use a 2D array of char (an array of strings, essentially). You can initialize the array to spaces at first, then draw the x and y-axis with - and | characters. Then 'draw' the graph to the array.

You will need to know what x value each column of the graph represents. Use variables like xmin, xmax to store the x values for the extreme left and right columns, and xstep to mean the difference in x value from one column to another (if you ask the user for xstep, then you can compute xmax from this value if you know what xmin is).

Go through every column of the graph, and compute its y value. If it is within range (after rounding off to fit in a particular row), change that character in the graph to * or some other character. Obviously, you need ymin and ymax values set, as well. These will all need to be known when you draw the x-axis and y-axis to the array.

Now print it to the output one row at a time (one string at a time). Take care to print a \n character at the end of each row.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Graphs In C

## Developer Shed Advertisers and Affiliates

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |