⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http:^^www.cs.wisc.edu^~milo^cs302^quiz2-sol.html

📁 This data set contains WWW-pages collected from computer science departments of various universities
💻 HTML
字号:
Date: Mon, 11 Nov 1996 17:12:27 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Fri, 04 Oct 1996 07:25:42 GMTContent-length: 2631<HTML><HEAD><TITLE>Quiz 2 Solutions - CS 302 Fall 1996 - Section 4</TITLE></HEAD><BODY><H4 ALIGN=CENTER>  <!WA0><!WA0><!WA0><!WA0><!WA0><!WA0><A HREF="http://www.cs.wisc.edu/~cs302">CS 302</A>  Fall 1996 - <!WA1><!WA1><!WA1><!WA1><!WA1><!WA1><A HREF="http://www.cs.wisc.edu/~milo/cs302.html">Section 4</A></H4> <H4 ALIGN=CENTER>Quiz 2 Solutions</H4><hr><br>This quiz is 20 total points.  Please write legibly.  If I can't readit, I can't grade it.  You have until 5 minutes after the class periodends to finish.Good luck.<OL>  <LI> (2 points) What does the ``magic'' type ``<TT>const char *</TT>''allow us to do?<br> <br> It allows us to pass a constant character string to a function.<br> <br>  <LI> (2 points)State one difference between a local variable and a <EM>call-by-value</EM>parameter?        <br> <br> <EM>call-by-value</EM> parameters have an initial value obtained froman actual parameter from the call to the funciton.  Local variablesstart with an unspecified initial value and thus they need to beassigned or explicity initialized before used.  <br> <br>  <LI> (2 points) What does a <tt>void</tt> keyword at the beginning of afunction header or prototype mean?<br><br>That function returns no value.<br><br>  <LI> (2 points) Based on what was said in class, when are ``global''variables acceptible to use?<br><br>I accepted two answers:  Never or only when they are global <B>constants</B>.<br><br>  <LI> (2 points) Give one reason to use a <EM>call-by-reference</EM>(&) parameter. <br><br>A function needs to give back more information than a single variable.<br><br>  <LI> (5 points) What is the output of the following program?<PRE>#include&ltiostream.h&gtvoid height(int total_inches, int& inches, int& feet);int main() {  int my_height = 78;  int height_inches, height_feet;  height(my_height, height_inches, height_feet);  cout << "I am " << height_feet << " feet, ";  cout << height_inches << " inches tall." << endl;}void height(int total_inches, int& inches, int& feet){  inches = total_inches % 12;  feet = total_inches / 12;}</PRE><br>I am 6 feet, 6 inches tall.<br> <br>  <LI> (5 points) Exercise 7, page 184: Write a <tt>void</tt> functiondefinition for a function called <tt>add_tax</tt>.  The function<TT>add_tax</tt> has two formal parameters: <tt>tax_rate</TT> which is theamount of sales tax expressed as a percentage and <tt>cost</tt> which isthe cost of an item before tax.  The function changes the value of<tt>cost</tt> so that it includes sales tax.<pre>void add_tax(int tax_rate, int& cost){  cost = (1.0 + tax_rate) * cost;}</pre></OL></BODY></HTML>

⌨️ 快捷键说明

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