home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / talk / bizarre / 23228 < prev    next >
Encoding:
Internet Message Format  |  1992-07-24  |  3.9 KB

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!netnews.upenn.edu!netnews!mjd
  2. From: mjd@saul.cis.upenn.edu ("[*] The One Who Makes the Clocks Run Down")
  3. Newsgroups: talk.bizarre
  4. Subject: The Exam
  5. Message-ID: <MJD.92Jul24112855@saul.cis.upenn.edu>
  6. Date: 24 Jul 92 15:28:55 GMT
  7. References: <MJD.92Jul21174614@saul.cis.upenn.edu> <1992Jul22.180505.28634@kakwa.ucs.ualberta.ca>
  8. Sender: news@netnews.upenn.edu
  9. Followup-To: comp.lang.c.d
  10. Organization: Eaters of Wisdom
  11. Lines: 107
  12. Nntp-Posting-Host: saul.cis.upenn.edu
  13.  
  14.  
  15. aaron@space.ualberta.ca (Aaron Humphrey) writes:
  16.  
  17. >Are you taking a typing class by any chance, mjd?
  18.  
  19. No.
  20.  
  21. I am teaching a C programming class.
  22.  
  23. 3.2       5  points
  24.  
  25. Dafydd Painter, a world-famous nostrilologist, is writing C programs to
  26. help him with his work. In one of them he has the directive
  27.  
  28.     #define  NUMBER_OF_NOSTRILS  2
  29.  
  30.      He explains: "This constant represents the number of nostrils
  31. possessed by the typical human being. It appears many places in my
  32. program. I represented the number of nostrils with a manifest constant
  33. so that if the value ever changes, it'll be easy to change the code."
  34.  
  35.      Of course that's silly, because we don't expect the typical number
  36. of nostrils to change. Nevertheless, there is a good reason for
  37. #define'ing NUMBER_OF_NOSTRILS.  What is it?
  38.  
  39. [One student said, ``In case the number of nostrils people have changes,
  40. it will be easy to change the code because we'll only have to change the
  41. 2 in one place.''  Oy gevalt.]
  42.  
  43.  
  44. 3.3       5  points
  45.  
  46. Farina Granville, noted quinquagintaseptologist, tried to write a
  47. function that would set the value of a variable to 57:
  48.  
  49.   void  set_to_57(int  var)
  50.   {
  51.      var  =  57;
  52.   }
  53.  
  54.      Of course, it didn't work. You explained to her that in order for
  55. the function to change the value of a variable, it must know where that
  56. variable is, and so Farina will have to pass the address of the variable
  57. she wants to change into the function set_to_57.
  58.  
  59.     Farina is obstinate: "I don't want to pass in a pointer," she says.
  60. "People shouldn't have to know about pointers to use this simple
  61. function. I'll have the function itself get the address once it's
  62. called." Then she writes this:
  63.  
  64.   void  set_to_57(int  var)
  65.   {
  66.      int  *p;          /*  Address  of  argument  */
  67.  
  68.       p  =  &var;
  69.      *p  =  57;
  70.   }
  71.  
  72.      Does this work? If so, how?  If not, why not?
  73.  
  74. [I was dismayed by how many students said that this would work.]
  75.  
  76. 3.4       5  points
  77.  
  78. Kelvin R. Reaumur, a noted temperaturologist, wants to write a function
  79. which accepts a Celsius temperature as an argument and which returns the
  80. equivalent Fahrenheit temperature. The formula for converting from
  81. degrees Celsius to degrees Fahrenheit is:
  82.  
  83.                                 9
  84.         deg F = deg C * -  +  32
  85.                                 5
  86.  
  87. Here is what Dr. Reaumur tried:
  88.  
  89.   double  celsius_to_fahrenheit(double  c)
  90.  
  91.   {
  92.      double  f;
  93.  
  94.  
  95.      f  =  c  *  (9/5)  +  32;
  96.      return  f;
  97.   }
  98.  
  99.      First, Dr. Reaumur tested the function by passing in 0, the Celsius
  100. freezing point of water, and it correctly returned 32, the Fahrenheit
  101. freezing point of water. Heartened, he then tried it on 37, which is
  102. normal human body temperature, but the return value was 69, instead of
  103. 98.6 as it ought to have been.
  104.  
  105.      What is wrong with this function? Fix it.
  106.  
  107. [This next one didn't make it onto the exam]
  108.  
  109.     Hieronymus Bonghit was never quite himself after he was struck on
  110. the head by a falling wah-wah pedal at last year's Saint Patrick's Day
  111. Parade.  His irrational hatred of the Irish rock band `U2' has increased
  112. ever since last March.  This week he wants to erase all the files on his
  113. system which mention U2.  The first step is to identify these files.
  114. Write a program which reads its input and reports whether or not the
  115. sequence of characters `U2' appeared anywhere within it.
  116.  
  117. --
  118.  
  119.                 And for to see, and eke for to be seye
  120. Mark-Jason Dominus                       mjd@central.cis.upenn.edu 
  121.