-
February 12th, 2011, 01:59 AM
#1
make graphing function
so I want to program a way to graph a function. i made the function below to make a graph. but how do i get it to accept string condition in the if statement (i don't want to worry about the case if it isn't a valid if statement for now)
for example if i take the // replace with an expression and put x==y, it puts a straight line.
but if i want to consule input "x == y" to make it print out that, how would i do it?
Code:
void makeGraph(){
cout << "Enter n where this creates an nxn graph" << endl;
int n;
cin >> n;/*
cout << "Enter your plot condition" << endl;
string condition;
cin>> condition;
for (int x = -n; x <= n; x ++){
for (int y = n; y >= -n; y --){
if( // replace with an expression){
cout << "X";
}
else if (x == 0 && y == 0){
cout << '0';
}
else if (x == 0){
cout << '-';
}
else if (y == 0){
cout<< "|";
}
else{
cout<< " ";
}
}
cout <<endl;
}
cin.ignore();
cin.get();
}
Last edited by Marc G; February 12th, 2011 at 09:29 AM.
Reason: Added code tags
-
February 12th, 2011, 07:01 AM
#2
Re: make graphing function
you need to be able to parse the string into something you can evaluate as a function of x and y.
expression parsing isnt a simple one-liner.
e.g. http://www.speqmath.com/tutorials/ex...cpp/index.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|