C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 7th, 2003, 05:11 AM
willo willo is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Liverpool
Posts: 6 willo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation 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

Reply With Quote
  #2  
Old March 7th, 2003, 06:37 AM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
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'.

Reply With Quote
  #3  
Old March 7th, 2003, 04:45 PM
willo willo is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Liverpool
Posts: 6 willo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old March 7th, 2003, 07:23 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
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)?

Reply With Quote
  #5  
Old March 8th, 2003, 04:54 AM
willo willo is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Liverpool
Posts: 6 willo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yes my formula is

Y=2X+5


Reply With Quote
  #6  
Old March 8th, 2003, 12:20 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
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?

Reply With Quote
  #7  
Old March 8th, 2003, 04:10 PM
willo willo is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Liverpool
Posts: 6 willo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
simple one in text

Reply With Quote
  #8  
Old March 8th, 2003, 04:53 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Graphs In C


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT