[Edit:]
And here is the online version of the calculator :)
http://vector-partition.jacobs-university.de/cgi-bin/calculator
A test of what it can do: enter (x_1+x_2+x_3+x_4)^10 in the entry and click "Go" :) and that is it! [Edit:] The first two entries where it says "A" and "1" - are for later use so please ignore them :)
Hi guys,
I wrote a (soon-to-be) online calculator - one in which you enter a string, say:
(n_1+n_2)^2
and the calculator returns you the resulting simplified expression:
n_1^2+2n_1n_2+n_2^2
The parser is based on helios' explanation:
http://www.cplusplus.com/forum/lounge/11845/ .
The online version of the calculator uses apache server+cgi interface. At the moment it is only set-up on my personal computer, but I want to "go live/online".
What is stopping me is that I have no calculation timeout code. My calculator has some rather powerful functions, however, I cannot judge how long those function take to execute.
I want that the calculator, if not done with the computation in some fixed time, say 10 seconds, display a message:
"Dear user, your calculation has taken more than 10 seconds, the maximum allowed running time for the online version. Please use the offline version of the calculator"
What would you do in my place? Also, I want a relatively secure solution, because it will be hosted on the web servers of my university, and I can get in trouble if the webmasters catch me using up a lot of CPU resources.
Just to be more specific, the calculator's code looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
#include <unistd.h> //to call system functions on a Linux machine
#include "polyhedra.h" //(my main functionality)
void getPath(char* path, std::string& output);
int main(int argc, char **argv)
{ std::string inputString, inputPath, tempS;
std::cin >> inputString;//there are two methods to get information from a CGI form
//through an apache server: either via std::cin, or via an environment variable
if (inputString=="")
{ inputString=getenv("QUERY_STRING"); //getenv is a system function declared in <unistd.h>
}
getPath(argv[0], inputPath);
//inputString contains now the user input, which is a cgi form
//....
//here I parse the string and carry out the computation
// ...
// and finally I return some meaningful information to the user:
std::cout << "Content-Type: text/html\n\n"; //to tell the Apache server you are returning html text
std::cout << "<html><head><title>Vector partition calculator</title>";
std::cout << "<script src=\"/easy/load.js\"></script> "; //to display beautiful formulas I use a free script called mathjs
//... here I prepare a nice output for the user
return 0; // Toavoid Apache errors.
}
|