26-CS106X-Practice-Midterm

Shown on the previous page there are five unique

This preview shows 2 out of 5 pages.

shown on the previous page, there are five unique acronyms, of which two have multiple expansions, so the returned percentage would be 40% (expressed as a double that's 0.40 ). double PercentConfusing(Map<Vector<string> >& map) { Problem 2: HTML Entitles HTML is a language that helps decorate plain text with tags that serve as instructions on how to style the text within a web browser. Tags take the form of strings that begin with '<' and end with '>' . Some of the more common tags are <b> (for styling text as boldface), <u> (for underlining text), and <i> (for italicizing text). 2
Image of page 2

Subscribe to view the full document.

Because '<' and '>' are so prevalent in HTML, it’s difficult to include actual < and > characters in plain text because the browser might confuse them as markup. As a result, the following plain text: < and > are the most popular relational operators in C++. might give the impression that there’s a leading HTML and tag. You could argue that browsers should just know that and isn’t a genuine tag, but as it turns out, HTML documents can define their own tags, and in principle <and> might be a legitimate tag type within a particular document. The solution is to replace the plain text < ’s and the >’s with HTML entities —strings used to represent characters in a document that otherwise have special meaning. In standard HTML, < is represented by "&lt;" (without the double quotes), and > is represented by "&gt;" . And because & has special meaning now, there’s also an HTML entity for it: "&amp;" . In fact, there are a whole slew of HTML entities beyond these three. Here are just a few examples: < &lt; > &gt; & &amp; " &quot; ' &apos; ¢ &cent; Every single HTML entity begins with & and ends with ; , and is associated with some single character in (what we’re simplifying it to be) the ASCII character set. To be clear: John said, &quot;Hi!&quot; is really John said, "Hi!" Cold Stone&apos;s sundaes: 49&cent;! is really Cold Stone's sundaes: 49¢! A&amp;P Supermarket is really A&P Supermarket x &lt; 7 &amp;&amp; y &gt;= 10 is really x < 7 && y >= 10 You’re to write a function called RestorePlainText , which takes a string and a map of HTML entity strings to characters, and returns a copy of the incoming string, save that all of its HTML entities have been replaced with the characters they represent. The Map<char> is keyed on the HTML entity (without the leading & and trailing ; so that strings like "lt" and "amp" are keys, not "&lt;" and "&amp;" ) and each maps to the character it represents (i.e. '<' or '&' ). If the string contains what appears to be an HTML entity not in the Map<char> , then that entity is left in the string as is. You can assume the string is otherwise well formed, in that every opening & is eventually balanced by a closing ; , and that there aren’t any unpaired ampersands or semicolons. 3
Image of page 3
2 . 1 . 3 . 4 . 5 . 6 . Place your implementation of the following this and the following page.
Image of page 4

Subscribe to view the full document.

Image of page 5
You've reached the end of this preview.
  • Winter '08
  • Cain,G

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern