SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Streams And File Io
Exercise:
Programming Projects
Question:19 | ISBN:9780132846813 | Edition: 5

Question

HTML files use tags enclosed in angle brackets to denote formatting instructions. For example, <B> indicates bold and <I> indicates italics. If a web browser is displaying an HTML document that contains < or > , it may mistake these symbols for tags. This is a common problem with C++ files, which contain many < ’s and > ’s. For example, the line "#include <iostream>" may result in the browser interpreting <iostream> as a tag.

To avoid this problem, HTML uses special symbols to denote < and > . The < symbol is created with the string &lt; while the > symbol is created with the string &gt; .

Write a program that reads in a C++ source file and converts all < symbols to & It; and all > symbols to & gt;. Also add the tag <PRE> to the beginning of the file and </PRE> to the end of the file. This tag preserves whitespace and formatting in the HTML document. Your program should output the HTML file to disk.

As an example, given the following input file,

#include <iostream>

int main()

{

int x=4;

if (x < 3) x++;

cout << x << endl;

}

the program should produce a text file with the following contents:

<PRE>

#include &lt;iostream&gt;

int main()

{

int x=4;

if (x &lt; 3) x++;

cout &lt;&lt; x &lt;&lt; endl;

}

</PRE>

You can test your output file by opening it with a web browser. The contents should appear identical to the original source code.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.