Forum Moderators: open
What I want to know: Is there a way to embede the c++ code into the html? Some may say that i should write the equation in Javascript and embede it in html. The problem is that the equations are very complex (gauss curves) and javascript cant handle it. I must use the prepared codes.
Is there a way?
You can't embed C++ into a page.
Any reason not to put the calculation part server-side (CGI for example)?
I'm pretty sure that java-script can use 32bit real numbers though (could be wrong). It sounds like your code is just going to be raw maths. Are you sure that the code cannot be ported?
TJ
Can you point me to a specific page with a code already written in cgi to study and learn how to do it? I want to create a form (thats easy), take the data from the form, input them in the c++ code, in this code all the mathematical work will be done, then take the results from the c++ code and renter them in a specific point in the html where they will be shown (difficult part).
I have the form, the pages, the c++ codes. How am I ever going to "marry" them?
The most common languages for scripting are PERL, PHP, JAVA, and ASP. There are a a few more but these are the most common.
If you understand what C++ is, then you might understand that the code needs to be compiled. When it comes to scripting languages, this is not the case. The 'compiler' ... well ... the best way to put it is that it compiles 'on the fly'. You can open any page in your favorite text editor and actually view and edit that code simply by editing and hitting "save". No need to compile.
These pages work then by taking input from say "index.html" and sending information to say "index.cgi", at which time it's proccessed ON THE SERVER, and finally outputted to html. Thus making the site dynamic.
As an example, if I were to have a page called "index.php", and opened it in a text editor, it would look something like this:
<?
echo "<html>";
echo "<body>";
echo "<H1>Hello World!</H1>;"
echo "</body></html>;"
?>
This would output after proccessing:
<html>
<body>
<H1>Hello World!</H1>
</body></html>
Of course there is no dynamic content in a hello world script, but your proccesses would simply go anywhere between the <? and?> of the PHP page. to reasearch the actual programming, you can google any of the above langauges and hit literally thousands of tutorial sites. I don't know what your setup is, thus my inablility to suggest a language to you for further research. You might try hitting the ASP, PHP, and PERL forums in this site though, they are a wealth of knowledge!
-- Zak
There is one tool I have seen called html++, but from the way I understood it, the only part that is keepable is the algorithm he's already got. Now he says he's not a programmer, so which do you think is easiest (consider he'll have to learn html either way):
1) He learn C++, (ask anyone how easy this language is, and they'll tell you to start with something simpler. I've used it off-and-on for 6 years and it still gives me fits sometimes) and learn to include the classes needed, and which ones. And to input his the variables somehow, proccess and format it into a readable html page, and finally direct the browser TO that page output.
2) He learn a scripting language, not have to include any classes unless it's REALLY complicated like shooting off emails & such. He already knows the algorithm so all he has to do is learn the syntax. Create the html doc formatted into a readable page.
Beleive me, if he's not a programmer, it'll be faster to start over for a simple project like this one. I might be able to understand if it were a 15,000 line proccess, but we're talking about 3 questions with four answers a peice. This gives us just 3 numbers we have to deal with (probably just coming up with the mean, or the median?) Hardly Rocket-Science. It'll save a ton of time to just do it in a scripting language, If that's all there is to it...
Considering it's as simple as I understand it, this should be sufficient:
HERE'S THE HTML CALLED 'questions.html'
<html>
<body>
<form method=post action="math.php">
Question 2:<br>
A: <input type="radio" name="input1" value="1">
B: <input type="radio" name="input1" value="2">
C: <input type="radio" name="input1" value="3">
D: <input type="radio" name="input1" value="4">
<br><br>
Question 2:<br>
A: <input type="radio" name="input2" value="1">
B: <input type="radio" name="input2" value="2">
C: <input type="radio" name="input2" value="3">
D: <input type="radio" name="input2" value="4">
<br><br>
Question 3:<br>
A: <input type="radio" name="input3" value="1">
B: <input type="radio" name="input3" value="2">
C: <input type="radio" name="input3" value="3">
D: <input type="radio" name="input3" value="4">
<input type="submit" value="calculate">
</form>
</body></html>
THIS WOULD BE THE PHP FOR THE ABOVE INPUT CALLED 'math.php':
<?
$total = $input1 + $input2 + $input3;
$total = $total / 3;echo "your total is $total";
?>
P.S. I did not test this, but it looks right, so I think just cutting and pasting to test it should work.
[edited by: lZakl at 1:36 pm (utc) on Dec. 14, 2004]
I suspect the easiest way to do this (although I've never tried it) is going to be using a Perl (or PHP, or whatever) script to pass the form inputs into the program, retrieve the outputs, and format them into HTML data. I just think rewriting the existing C++ code into PHP is more trouble that it's worth.
How am I ever going to "marry" them?
You could execute the app on the server in realtime, depending on how the app. outputs the result, but it's going to be real messy doing it - and you'll need some PERL "glue" to hold it all together.
I agree that porting to PERL is the obvious solution, but I'm not sure if PERL does C++, or straight C only?
TJ
cpan.uwinnipeg.ca/htdocs/perl/Math/Trig.html
If you understand how to get the Standard Deviation, it shouldn't be too difficult...
Getting output from an executable to a script, that'll be a little tougher. I suppose you could do a 2 stepper. HTML form takes you to first PERL page. PERL writes to text file, calls and starts executable. Executable proccesses aformentioned text file, outputs to ANOTHER text file, button on current PERL page says "go to next page and get your results" next page calls to executable-written txt file. Could be done though... But he'll STILL have to learn a scripting program. Might as well go all the way.. lol
In essence, it would be:
HTML form ---> CGI input ---> file1.txt outputted and math.exe executed ---> Math.exe reads file1.txt and proccesses and then writes file2.txt ---> Current CGI page takes you to NEXT CGI page ---> CGI page 2 reads file2.txt and gives user results...
[codeproject.com...]
Oh yeah, and buying an IDE for a single language tends to cost around $120 CAN, as opposed to the entire Visual Studio package, which was over $1000 last I checked.
I think that you can create webservices with this. Although not completely sure. I use visual studio.