So I was in Grade 12 (until last week) and I have always had a disliking towards Graph Paper! Not that I Hate maths or René Descartes. It was just too boring to mark those points and connect them. I had to do a C++ program for my Computer Science final practical examination and was searching for an idea. Thats when i came up with THE GRAPHIC CALCULATOR. Why not give it a go?

DISCLAIMER: No Mathematicians or Graph Paper were harmed in making of this Instructables!

Step 1: Materials Required

1> A Computer (in working condition)

2> C++ Compiler (can be DOSBox/Turbo C++) I used BORLAND C++ v4.5

3> Microsoft Excel / Open Office Calculator

4> Time & Patience

Step 2: Behind the Screen - the Logic

The Logic is simple.

1> Get the equation from the User.

2> Loop the equation with enough values to get corresponding equation values

3> Plot Y-X Graph [Equation vs Variable]

The equation can be framed easily like this, for a linear equation, the general form is: ax + b = y. You get the values of 'a' and 'b' (coefficients & constants) from the user, then vary the value of variable 'x' to get the corresponding values of 'y'.

QUADRATIC: y = ax^2 + bx + c

CUBIC: y = ax^3 + bx^2 + cx + d

Step 3: Behind the Screen - Plotting

Once we have the coordinates, we can plot the graph pretty easily. Now, there are several ways to do this including downloading a separate header file / creating user defined functions. The easiest way that i came up with is to use setw() function for Horizontal spacing and "\n" for vertical Spacing.

Example: for a point (13,26) i would have to use setw(13) and for(int i=0; i<26; i++) cout << "\n"

cout << "|" << setfill('-') << setw(y + 200) << "¤" << "(" << x << " , " << y << ")\n" ;

I added another 200 spaces for setw() so that the graph doesn't get crowded with the axis. setfill('-') fills the setw() space with the hyphen character. You could also use any other character.

Step 4: Behind the Screen - Exploring Options

I further extended the idea to Quadratic / Cubic equations as well.Added a DELETE option so that the previous graphs can be deleted.

This is pretty simple, just open the file in ios::open mode. But what i did was to close existing file, open in ios::trunc and close this and again open it in ios::app. This looks long but is worth doing it.

Also, I used Microsoft Excel to view my Output mainly because of three reasons. One, the output wouldn't be correct in the C++ output window (at least in my case) and secondly, Excel has much space available for plotting, it would I've me much freedom to plot graphs with larger numbers. And Finally, One can Zoom - IN/OUT to view the graph (curve) or the points(co-ordinates).

Step 5: Finishing Touches

I added a short LOADING animation in the beginning. I felt it was a bit time consuming to go through the animation every time, so i added a bypass to skip the animation. And a Main Menu to wrap things up i a better way.

Pretty Printing is a great way to make your work look neater.

I've attached the code in here. So feel free to Use it / Customise it.

The loading part is too lengthy because #include isn't supported in BORLAND. Else you could use Delay(t) function where 't' is the time delay given in milliseconds. (1000 ms = 1 s).

Thanks Taking your time to read! Please Vote in Data Visualisation Contest!

<p>For other useful C programs visit</p><p><a href="http://codeitoff.blogspot.in/" rel="nofollow">http://codeitoff.blogspot.in/</a></p>
<p>I have rewritten and commented on much of the program in order to make it more efficient, fit the ISO C++ standard, and correctly use flow control (removed to goto statements). It is fairly rough-cut at it current state and the user experience is only slightly different. Feel free to look at the code and ask if there are any questions.</p><p><a href="http://pastebin.com/bqTcRqDX" rel="nofollow">http://pastebin.com/bqTcRqDX</a></p><p><br></p>
<p>Anytime. Also, if possible I would recommend getting a more standard compiler. I was using GCC 4.8, but Microsoft's is also fairly good, and I have also heard some good things about LLVM.</p><p>Just note that Borland C++ is very outdated and is no longer under development. However, all of the previously listed compilers can be downloaded for free. MS Visual Studio Express 2010 is probably the easiest (and the biggest) to download and install. It comes with a complete IDE. GCC and LLVM are both command line tools, but most IDEs support them. Most notably Eclipse CDT and Code::Blocks.</p><p>If you are headed in the direction of GCC, I would check into MinGW.</p>
<p>Thank you for your corrections and tips. Always ready to learn! </p>

About This Instructable




Bio: I am doing my B.arch (1st sem) in India.
More by W I N G M A N:Add a Mic to any Headphone - Simple EDGE-LIT Mouse Pad cum CD Case Tie Origami 
Add instructable to: