Assignment (5)

CS1440 - Due April 5, 2001

Write a C++ code that converts an input file, myfile, into a simple Hyper Text Markup Language (HTML) file, myfile.html. In order to do this, you will read an input file, myfile, from the beginning to the end and create an output file, myfile.html by following the instructions given below.You need to use the get function to read all the characters (everything) from the input file character-by-character and write everything to the output file, character-by-character using put function. 

1) Every time you run your code, the first thing you will do is to write the following lines at the beginning of the output file before you start reading the input file.

<Html>

<Title>

This is my C++ html converter <br>

</Title>

<Body>

2) From this point on, you will write the contents of the input file exactly the same way as you are reading it, onto the output file.However, when you reach the end of each line in your input file, you will need to do something different. Every time you get to the end of a line (\n) (note that \n is invisible) on the input file, you will write <br> onto the output file.  Please note that you need to have the < and > with br.  The <br> in html means the same thing as the \n in C++. The process continues until everything is written onto the output file. In html <br> stands for break line.

For example suppose your input file has the following two lines:

Line 1 on the input file:I have a black cat.

Line 2 on the input file:I have a white dog.

As you can see at the end of the first line there is a '\n'.So once we see that, we will write <br> onto the output file instead.Thus, these two lines on the output file will look like this:

I have a black cat. <br> 

I have a white dog.

3) After reading the input file and copying its entire contents onto the output file, you will write the following two lines at the end of the output file.

</Body>

</Html>

The output that you will generate after you run the code, is an html file.  If you have done everything correctly, you can open it using a web browser like Netscape or Internet Explorer.

Example Input:

Hi my name is David.

This is my C++ html converter.

Output:

<Html>

<Title>

This is my web page <br>

</Title>

<Body>

Hi my is David. <br>

This is my web page

</Body>

</Html>

How to create the input file myfile?Use pico and create a file that contains the following information in the same format.

Last Name: 

First Name :

Classifications (freshman, junior, ...):

Courses I am taking this semester:

E-mail:

Write five lines about yourself. Anything you wish to include on your web page. Make sure it is written on 5 lines.

Your program should include the following functions:

void Instruction()

void Get_test_files(ifstream& in_s, ofstream& out_s)

This function asks users to input the input and output file names, it tests the connection and if the connection is made to the input/output files, it creates the input/output streams for the input/output files and returns those streams to the main.

void Header(ofstream& out_s)

This function will write the first four lines that were shown in part (1) onto the output file.

void Footer(ofstream& out_s)

This function will write the two lines shown in part (3) at the end of the output file.

void Copy_text(ifstream& in_s, ofstream& out_s)

This file copies the entire contents of the input file, myfile, onto the output file line-by- line, by considering the given instructions for the new line.