C++代写:INFO1156 Text To Html

用C++代写一个文本转HTML的工具。

Project Description

Start with the following code:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <fstream>
using namespace std;

int main( int argc, char* argv[] ) {
ifstream infile( argv[1] );
char ch = 0;
while( infile.get( ch ) ) {
cout.put( ch );
}
}

Create a C++ application that converts an old-style text file into a format more appropriate for use in a computer, smart-phone, or e-book reader. Specially, this program converts an UTF-8 text file (for example, PlatoTest.txt) to an xhtml 1.0 file (for example, PlatoTest.html) containing the same textual content as the original UTF-8 text file.

Note: If the input file has three newlines in a row, the output file should have only two <br /> tags replacing the three newlines. Overall, the number of break tags is always one less than the number of consecutiveor singlenewlines.

The executable file must be named: txt2html.exe

The program will operate as a command-line utility (not a console input program).

An Example - Convert PlatoTest.txt to PlatoTest.html

Below is an UTF-8 text file named “PlatoTest.txt”. Note that represents an <Enter> in the text.

The Republic, by Plato
The Project Gutenberg EBook of The Republic, by Plato
This eBook is for the use of anyone anywhere at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org
Title: The Republic
Author: Plato

The UTF-8 text file should convert to the html file named “PlatoTest.html” with the following source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PlatoTest</title>
</head>
<body>
The Republic, by Plato
The Project Gutenberg EBook of The Republic, by Plato
<br />
This eBook is for the use of anyone anywhere at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org
<br />
<br />
Title: The Republic
<br />
Author: Plato
</body>
</html>

This example would be run from the command prompt by typing:

txt2html.exe PlatoTest.txt

or

txt2html.exe PlatoTest.txt PlatoTest.html

Switch

If the user provides an optional command line parameter “-r”, print the report (described in the next section) to the console:

txt2html.exe -r PlatoTest.txt

or

txt2html.exe PlatoTest.txt PlatoTest.html -r

or

txt2html.exe PlatoTest.txt -r PlatoTest.html

Report

Provided the “-r” switch your program will display to the console a report that displays:

  • The number of complete lines read from the input file.
  • The number of paragraphs (indicated by <br /> tags)

Additional Examples

txt2html.exe -r "War and Peace.txt"

or

txt2html.exe "War and Peace.txt" -r

or

txt2html.exe "War and Peace.txt" W&P.html -r

or

txt2html.exe War&Peace.txt -r War&Peace.html