/**********************************************
This program writes an html file called temp.html
that is rendered by your browser to show
the continued fraction a + 1/(a + 1/(a + ...
in a table layout. For example, if a = 3
and n, the number of terms, is 2, you should
print html code that renders something like:
1
3 + -----
1
3 + -
3
except use tables, and the "<hr>" tag, which
draws a horizontal line. Note: if you use
<td align="center"> instead of just <td>, the
contents of that cell will be centered.
**********************************************/
#include <iostream>
#include <fstream>
using namespace std;
void printtable(int a, int n, ostream& OUT);
int main()
{
// Get integer n, n >= 0
int n,a;
cout << "Enter non-negative integer: ";
cin >> n;
cout << "Enter value a: ";
cin >> a;
// Write html file for continued fraction
ofstream OUT("temp.html");
OUT << "<html><body>" << endl;
printtable(a,n,OUT);
OUT << "</body></html>" << endl;
return 0;
}
void printtable(int a, int n, ostream& OUT)
{
if (n == 0)
OUT << a << endl; // Base Case
else
{ /* This table is formatted roughly like this
---------------------
| | 1 |
---------------------
| a + | -------- |
---------------------
| | recurse |
---------------------
*/
OUT << "<table><tr><td><td align=\"center\">1<tr><td>"
<< a << " + " << "<td><hr><tr><td><td>";
OUT << "<table>" << endl;
printtable(a,n-1,OUT);
OUT << "</table></table>" << endl;
}
}