In this assignment, the output of your program will be HTML
code that displays computational results in a nice table.
Your program will use cout to write results to
the screen, which you can then copy and paste into a text
editor (like Notepad), save as a file, and finally open in a
web-browser to view the results.
Hello World in HTML
<html> and ends
with </html>. In between, anything that's
supposed to show up in the browser window comes between a
<body> and a </body>.
(Note: Anything sandwiched between < >'s is
called a tag.) Then in the body, any text
you write is displayed in the browser. So, here's "Hello
World", first in Notepad you see the HTML file, and then in
Internet Explorer you see the file viewed in the browser:
Now, there's no reason that a C++ program couldn't produce its output in HTML code. For example, if I wanted to write a "Hello World" C++ program that produced its output in HTML, here's how I'd do it:
#include <iostream>
using namespace std;
int main()
{
// Print html and body starting tags
cout << "<html>" << endl << "<body>" << endl;
// Print the Hello World message
cout << "Hello World!" << endl;
// Print html and body closing tags
cout << "</body>" << endl << "</html>" << endl;
return 0;
}
|
If you were to run this program, paste the output into a
notepad document and save as a file named, for example,
HelloWorld.html, you could open the file
HelloWorld.html in your browser and the results
would be just what you see above. To view a local file in
your browser, go to your browser's File menu and
choose Open, and in the resulting menu choose either
Browse or Choose (depending on whether you run
Explorer or Netscape). This should allow you to navigate
your file system and click on the file to be opened.
NOTE: To save yourself some headaches, make sure that
your file's name ends in ".html".
<table> and ends with the tag
<table>. Within that, each row begins with
the tag <tr>, and each cell within a row
begins with the tag <td>. The contents of
a cell in a table can be text, which is all we'll want here,
or more HTML tags. For example, here's a simple table:
Now, to bring out the fact that it's a table and make things
easier to read, we probably would like to have a border
around our cells. To instruct your browser to do this, the
beginning tag for the table,
i.e. <table>,
needs to be changed to something like
<table border=2>
Believe it or not, that's all the HTML you'll need for this project!