http:^^www.cs.wisc.edu^~mbirk^cs302^assignments^prog6.html

来自「This data set contains WWW-pages collect」· HTML 代码 · 共 134 行

HTML
134
字号
Date: Mon, 11 Nov 1996 17:00:35 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Fri, 08 Nov 1996 21:04:59 GMTContent-length: 3563<html><head><title> Program 6 </title><center> <h2> Program 6 </h2> </center></head><body><ul><li> CS302 Section 12<li> TA: Michael Birk<li> <strong>Assigned:</strong> Tue 11/5/96<li> <strong>Due:</strong> Tue 11/12/96</ul>For this assignment, you will write a program that can create"Mad Libs."  A "Mad Lib" is a humorous story generated by takingotherwise normal paragraphs and substituting arbitrary words andphrases.<p>Mad Libs are probably best illustrated with an example.  Here isa sample run of the Mad Libs program:<p><pre>Enter a Mad Libs file: test.madEnter a number: 1127Enter an adjective: slimyEnter a person's name: Joe BlowEnter an adjective: drunkEnter a verb: incinerateEnter an adjective: tranquilComputer Science 1127 is a very slimy class.  Thereason is that our teacher, Joe Blow, is reallydrunk.  One time, he even stopped right in the middleof class to incinerate a student!  It wus truly a tranquilexperience.</pre><p>The actual stories that will be processed by the Mad Libs programare stored in a separate text file.  These Mad Libs files containthe prompts for each word or phrase to be substituted.  For example,the Mad Libs file, <tt>test.mad</tt>, used in the above examplelooks like this:<p><pre>Computer Science [a number] is a very [an adjective] class.  Thereason is that our teacher, [a person's name], is really[an adjective].  One time, he even stopped right in the middleof class to [a verb] a student!  It was truly a [an adjective]experience!</pre><p>Notice how the prompts are surrounded with square brackets.  Yourprogram should read the file (you can use the <tt>read_file</tt>function from Program 5), prompt the user for each of the wordsor phrases to substitute into the story, and then print out thestory with the user's responses in place of the square-bracketedprompts.<h2> Hints and Notes </h2>Probably the simplest way to do this is to scan the Mad Libs file in twopasses.  The first time through, just extract each prompt, ask the user fortheir response, and store the response in an array.  Then go through thetext of the Mad Libs file a second time, this time printing out the story,substituting the user's responses for the square-bracketed prompts.<p>Recall that you can use the <tt>substring</tt> member functionof the string class to extract portions of a string (e.g., toextract the prompts inside the square brackets.)  For example,<p><pre>   string x = "abcde";   cout &lt;&lt; x.substring (1,2); // prints "bc" - the string of 2 characters                              // starting at position 1</pre><p><b>Note:</b> You do not have to worry about somehow "reformatting"the paragraph so all the lines have the same length.  Just print thestory as it is given in the file, substituting the user promptswith the user responses.<a name="tests"><h2> What to Hand In </h2></a>As usual, you will hand in the source code, along with the outputgenerated for some test cases.  These test cases are now available.(Note: They are also available "directly" in the lab, as<tt>r:\public\mbirk\madlib1.txt</tt> and<tt>r:\public\mbirk\madlib2.txt</tt>.)<p><ul>  <li> <a href="prog6/madlib1.txt">Test 1</a>  <li> <a href="prog6/madlib2.txt">Test 2</a></ul><p>Feel free to hand in any of the creative madlibs that you came upwith on your own!  (But this is not required - only test cases 1 and 2must be handed in.)<hr><i> <a href="mailto:mbirk@cs.wisc.edu">mbirk@cs.wisc.edu</a></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?