You are on page 1of 4

# Problem Statement

Design a software tool for Equation Drawing. The input to the software tool is
a string containing the Equation (Composed of Polynomials) and the output is
the Drawing of the equation using the Graphics Library provided by the text
book author.

Design
The project is divided into five stages as shown in Figure 1:
1. String input
2. String parsing
3. Drawing the function
4. Get a point
5. Zoom in or Zoom out

Implementation details
1. String Parsing:
Its the process of converting the string from text (characters) into two arrays of doubles which
represent the values of the powers and the coefficients of the terms.
The main function used for parsing is strtod .This function converts the string into double until it finds
strange character (not in the range 0-9) and it takes two parameters:
1) A pointer which indicates the start of the string to be converted into a double value
2) A pointer where the address of the strange character is saved. For this program this strange
character is either +- or (.
At first the user enters a string in the form (y=a
0
x
n
+a
1
x
n-1
+.+a
n
) where a
0
, a
1
,, a
n
are constants and n
is less than or equal 10.
The pointer used in this function is called pEnd and its address is initially the address of the first
character of the string.Then a while loop is used to extract the coefficient and the power of each term
from the string .The while loop ends when the address of pEnd is larger than the address of the last
element of the string.
The function strtod is used to extract the coefficient of the first term and its return value is saved into
the first element of the coefficient array.
Then the compiler checks the value of the strange character that ended the function:
If this character is ( ,this means that this term is multiplied by a certain power of x.So pEnd points
to the first element of this power skipping (x^ using pEnd += 3.Then the function strtod is used again
saving its return value to the first element of the power array.The address of pEnd is then incremented
by one in order to point to the sign of the next term(if it exists).
For any character rather than (which may be + or , the value of the first element of the power
array equals 0.
At the end of each loop the value two following elements of power and coefficient arrays are ready to
be assigned with values.

By the end of the while loop, we have two double arrays of both coefficients and powers of the terms.
difficulties :
we have first tried to do string parsing manually using .find and .substring but this concluded with
some problems which were that the program couldn't read a coeff with no powers or a coeff with no
brackets so we came up with many conditions and at last this only helped us with reading only one coeff
with no brackets nothing more..
so then we searched for some functions which would make it easier .. so we came up with strtod
function ..which helped us in reading as many non power coeff as the user would enter ad also
minimizing the code of string parsing to less than 40 lines of code .. and made it much easier to
comprehend if compared to the first manual method .

2. Drawing the grid lines:
This stage includes drawing the grid lines ,the X-axis and the Y-axis.
First of all, We draw the grid lines. By using a for loop, Successive vertical lines are drawn from the
bottom of screen till its top and successive horizontal lines are drawn from the left of the screen till its
right. This stage also includes printing numbers showing the grading of both X and Y axes.
Secondly we draw the x-axis and y-axis making them thicker than the rest of the grid lines. A for
loop is used to draw vertical and horizontal lines, just like the one used for drawing the grid lines. The
increment at the end of each loop is small such that the drawn lines are too near and appear to be one
thick line.
drawing the X letter and the Y letter on their axis but making their drawing dependant on the axis
to help us in the zooming functions

3) Drawing the function :
identifying a variable x1 and initializing it to -coordinate (which in the normal zoom made is equal to 10)
then identifying another variable y1 and initializing it to zero and indenting a counter .i = 0 which will
run until 10 ...we then begin our 2 for loop ..nesting a small for loop within other big one
{
{ making y1 += coef[i] * pow(x1, por[i]) so that in each small loop .i will inc by 1 till 10 passing by all your
ten coeff and your ten powers( which the program has saved them from the string input function)and
getting the submission of all y1 so that at the end you get only one y1 for only one x1}
then x1 will inc by 0.001 getting another point of x then the previous small for loop repeats it self again
to get the new y1 for the new x1
}
this all happens until x1 becomes equal to the initial positive coordinate ..we made inc x1 very small in
order to get many points closer to each other so as if to make the user sees them as a continuous
function while in fact they are nothing but many separate points drawn within a specific function

Testing

Tool limitations
The input should written in a specified way starting with 'y=' and each power is written
between two brackets (x^n) without any spaces between the characters.
The number of terms entered by the user can't exceed 10 terms
There is a limit to the zoom-in feature (coordinates can't be negative).

Zoom --input 10 termszoom in coord>0--
Future Work
The program can be edited such that:
The user can enter two functions to be drawn showing their intersection.
The program has better interface.
The program can specify whether the function is even or odd.

Functions(sine &cosine)Max & Min Domain & range Even or odd functions Enter 2 equations and
find s.s --
References
Big c++ - cplusplus.com