Date: Mon, 11 Nov 1996 17:12:36 GMT
Server: NCSA/1.5
Content-type: text/html
Last-modified: Fri, 04 Oct 1996 07:14:26 GMT
Content-length: 2279
Quiz 2 - CS 302 Fall 1996 - Section 4
Name: _______________________________
Quiz 2
Wednesday, October 2, 1996
This quiz is 20 total points. Please write legibly. If I can't read
it, I can't grade it. You have until 5 minutes after the class period
ends to finish.
Good luck.
- (2 points) What does the ``magic'' type ``const char *''
allow us to do?
- (2 points)
State one difference between a local variable and a call-by-value
parameter?
- (2 points) What does a void keyword at the beginning of a
function header or prototype mean?
- (2 points) Based on what was said in class, when are ``global''
variables acceptible to use?
- (2 points) Give one reason to use a call-by-reference(&) parameter.
- Over -
- (5 points) What is the output of the following program?
#include<iostream.h>
void 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;
}
- (5 points) Exercise 7, page 184: Write a void function
definition for a function called add_tax. The function
add_tax has two formal parameters: tax_rate which is the
amount of sales tax expressed as a percentage and cost which is
the cost of an item before tax. The function changes the value of
cost so that it includes sales tax.