C++ to HTML file

Disclosure: This is a HW assignment.

I am working on a calendar homework assignment where we are to create a calender for a specific month. This calender needs to be output to an HTML file.

So far I have been able to create the C++ calender without any issue. It prints the correct number of days with the correct starting day.

Where I am looking for assistance is how do I send this to an HTML file? So I understand I need ofstream to send data to the output file but I how do I create the file with an HTML structure? I have an HTML calendar template created and I have the code that created the calender, I just need to put the two together.

Any documentation or input would be appreciated.

Just output as text file adding the html tags as you wish
You need to learn how HTML files are organized. Here's a good tutorial:
http://www.w3schools.com/htmL/default.asp

Essentially, every web page should have certain tags, or text formatting, to make it work.
In your case, a simple calendar page might look like this:
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  <title>Duoas's calendar</title>
</head>

<body>
  <center><h1>April 2010</h1></center>

  <table width="100%" border="1" bgcolor="#FFFFDD">
    <tr bgcolor="#FFFFEE">
      <td width="14.28%" align="center">Sunday</td>
      <td width="14.28%" align="center">Monday</td>
      <td width="14.28%" align="center">Tuesday</td>
      <td width="14.28%" align="center">Wednesday</td>
      <td width="14.28%" align="center">Thursday</td>
      <td width="14.28%" align="center">Friday</td>
      <td width="14.28%" align="center">Saturday</td>
    </tr>
    <tr valign="top">
      <td bgcolor="#FFFFEE">&nbsp;<br><br><br><br><br></td>
      <td bgcolor="#FFFFEE">&nbsp;</td>
      <td bgcolor="#FFFFEE">&nbsp;</td>
      <td bgcolor="#FFFFEE">&nbsp;</td>
      <td>1</td>
      <td>2</td>
      <td>3</td>
    </tr>
    <tr valign="top">
      <td>4<br><br><br><br><br></td>
      <td>5</td>
      <td>6</td>
      <td>7</td>
      <td>8</td>
      <td>9</td>
      <td>10</td>
    </tr>
    <tr valign="top">
      <td>11<br><br><br><br><br></td>
      <td>12</td>
      <td>13</td>
      <td>14</td>
      <td>15</td>
      <td>16</td>
      <td>17</td>
    </tr>
    <tr valign="top">
      <td>18<br><br><br><br><br></td>
      <td>19</td>
      <td>20</td>
      <td>21</td>
      <td>22</td>
      <td>23</td>
      <td>24</td>
    </tr>
    <tr valign="top">
      <td>25<br><br><br><br><br></td>
      <td>26</td>
      <td>27</td>
      <td><b>28</b><br>&nbsp; Happy Birthday Duoas!</td>
      <td>29</td>
      <td>30</td>
      <td bgcolor="#FFFFEE">&nbsp;</td>
    </tr>
  </table>
</body>
</html> 

Before you read any further, go ahead and cut and paste the above example into a file on your computer named "duoas.html", and load it up in your browser to see how it looks.

You can use that template if you like. Your C++ code should write a file that looks like that example. The only things you'll need to change each time your code writes the file are for the dates:
 - The month and year on line 8
 - The colors for days not in the month (notice how I used a lighter shade of yellow for non-days)
 - Possibly the color for the day of week titlebar (I used the same lighter shade of yellow, but you don't have to do that)
 - The actual number of the day. If it is not a day, write the non-breaking space &nbsp; instead. You can see how it was done above.
 - Don't forget those linebreaks <br> after the number in the first cell of each row, otherwise the table will look funny. You can instead use a "height" attribute (like <td height="100">), but that assumes something more about your user's browser than just a few linebreaks.
 - You can even add additional information to the calendar day, as I did on 28 April (line 60).

Of course you'll also want to change the <title> of your web page (line 4) to something more appropriate.

This is very old, very simple HTML. It should work anywhere, even on your professor's browser. Just so you know, there are better ways of doing it, using CSS and the like, but it probably isn't worth your time and grief right now to get into that stuff.

Writing C++ code to produce such a file should not be too hard.

Hope this helps.
Topic archived. No new replies allowed.