Assignment (7)

CS 1440 - Due Nov. 1

 

Write a C++ code to convert an input file into a simple Hyper Text Markup Language (HTML) file.  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 the input file character by character.

 

1) Every time you run this program, the first thing is to write the following 4 lines at the beginning of the output file.  This is the header of the html file.

<Html>

<Title>

This is my C++ html converter

</Title>

<Body>

 

2) From this point on, you will write the contents of the input file exactly the way it is.  However, you need to write something for the new line.  Every time you get a new line (\n), write <br> in the output file.  Note that the entire <br> must be written.  This, in html, is called break line which is the same as \n in C or C++.

Example:  Input file

I have a black cat.

I have a white dog.

 

In the above example, you have a new line (\n) at the end of the first line.  So once I see that, I will write <br> in the output file.  Thus, my 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 it completely into the output file, you need to add the following two lines at the end of the output file.

 

</Body>

</Html>

 

This file is an html file and if you have done everything correctly, you can open it using a web browser like Netscape or Internet Explorer.

 

 

 

Example :

Input file:

 

Hi my name is David.

This is my web page.

 

 

 

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 includes the following information at the top in the same format.

 

Last Name:

First Name :

Classifications:

Hubbies:

E-mail:

 

Write five lines about yourself. Anything you wish to include but make sure it is written on 5 lines.

 

Your program should include the following functions:

Instruction()

Get_files           It assign the myfile and myfile.html names to two arrays and will return

the arrays to the main program.

Test_files          Test the input and output files and create the streams after they are validated successfully.

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

Footer()           This function will write the last two lines onto the output file.

Copy_text        This file copy the contents of the input file, myfile, onto the output file line by line, and consider the given instruction for the new line as it write each line.