Introduction: Graphic Calculator - C++ Program
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!