Question

C++ HTML files use tags enclosed in angle brackets to denote formatting instructions. For ex- ample,...

C++

HTML files use tags enclosed in angle brackets to denote formatting instructions. For ex- ample, indicates bold, indicates italics, etc. If a web browser is displaying an HTML document that contains ‘<’ or ‘>’ then 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 ” may result in the browser interpreting as a tag. To avoid this problem, HTML uses special symbols to denote ‘<’ and ‘>’. The < symbol is created with the string “<” while the ‘>’ symbol is created with the string “>” . Write a program that reads in a C++ source file and converts all ‘<’ symbols to “<” and all ‘>’ symbols to “>” . Also add the tag

 to the beginning of the file and 

to the end of the file. This tag preserves whitespace and formatting in the HTML document. Your program should create a new file with the converted output. To implement this, you should write a function ‘convert’ that takes the input and output streams as parameters. As an example, given the following input file: #include 1 int main() { int x=4; if (x < 3) x++; cout << x << endl; } The program should produce a textfile with the following contents:

        #include 
        int main() {
              int x=4;
              if (x < 3) x++;
              cout << x << endl;
} 

You can test your program with any .cpp file you have as input (Make sure to make a copy of the input file as you may loose it with incorrect File I/O). You should test your output file by opening it with a web browser. The contents should appear identical to the original source code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdlib>
using namespace std;

function void convert(ifstream inStream, ofstream outStream){
   // Input file to convert
string dataFile;
// Output file with .html on the end
string outputFileName;
char eachChar;
int i;

cout << "Enter file name: " << endl;
cin >> dataFile;

// Opening the file given by user
inStream.open(dataFile.c_str());
if (inStream.fail()) {
cout << "error in opening file." << endl;
exit(1);
}

   // preparing the output result file
   outputFileName = dataFile + ".html";
   outStream.open(outputFileName.c_str());

   // outputting <pre> tag
   outStream << "<PRE>" << endl;

   // reading file line by line
   while (!inStream.eof()) {
           inStream.get(eachChar); // reading each character
           // replacing '>' and '<' symbol
       if (eachChar == '<') {
           outStream << "<";
       }
       else if (eachChar=='>') {
           outStream << ">";
       }
       else outStream << eachChar;
   }
   // finally outputting</pre> tag
   outStream << "</PRE>" << endl;
   inStream.close();
   outStream.close();
   cout << "Processing done... Check output file " << outputFileName << endl;
}
// mail
int main() {
ifstream inStream;
ofstream outStream;
   convert(inStream, outStream);
}

Add a comment
Know the answer?
Add Answer to:
C++ HTML files use tags enclosed in angle brackets to denote formatting instructions. For ex- ample,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a...

    [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average monthly rainfall...

  • I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program...

    I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program reads two input files whose lines are //ordered by a key data field. This program should merge //these two files, writing an output file that contains //all lines from both files ordered by the same key field. // //********************************************************* #include <iostream> #include<string> #include<fstream> //prototype void mergeTwoFiles (ifstream&,ifstream&, ofstream&); using namespace std; int main() {string inFile1,inFile2,outFile; // input and output files ifstream in1; ifstream in2;...

  • 13.13 Final - Problem 2 (Chapter 8) Google Docs (20 points) Given the Document class below,...

    13.13 Final - Problem 2 (Chapter 8) Google Docs (20 points) Given the Document class below, you will write a basic version of Google Drive. Your program will store two lists of documents, one for documents the user has created and one for created documents the user has shared with a friend. The user will have a few options which you will need to implement (note: the menu will only be displayed once at the beginning of the program): Add...

  • C++ requirements The store number must be of type unsigned int. The sales value must be...

    C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...

  • It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #inclu...

    It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #include "File.h" // Constructor of File that takes File name and type as arguments File::File(string type, string name) {    this->type = type;    this->name = name; } //returns the type. string File::getType() {    return type; } //returns the name of file. string File::getName() {    return name; } File.h #ifndef __FILE_H__ #define...

  • Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in...

    Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...

  • Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be...

    Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book tit le, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an...

  • Don't attempt if you can't attempt fully, i will dislike and negative comments would be given...

    Don't attempt if you can't attempt fully, i will dislike and negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book titnle, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an HTML web...

  • Follow the instructions for starting C++ and viewing the Intermediate23.cpp file, which is contained in either...

    Follow the instructions for starting C++ and viewing the Intermediate23.cpp file, which is contained in either the Cpp8IChap11\Intermediate23 Project folder or the Cpp8\Chap11 folder. (Depending on your C++ development tool, you may need to open the project/solution file first.) The program uses an array to store the amount of money a game show contestant won in each of five days. The program should display the total amount won and the average daily amount won. It should also display the day...

  • How do I complete this problem? * CENGAGE MINDIAP > Terminal Opening Files and Performing FileInput...

    How do I complete this problem? * CENGAGE MINDIAP > Terminal Opening Files and Performing FileInput in C++ 0 Opening Files and Performing File Input Flowers.cpp flowers.dat 1 // Flowers.cpp - This program reads names of flowers and whether they are grown in shade or sun from an input 2 // file and prints the information to the user's screen. 3.// Tnput: flowers.dat. 4 // Output: Names of flowers and the words sun or shade. Summary In this lab, you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT