Name: ________________________________

Honor Code Acknowledgment: _____________________________


CPS 6, Summer 1999                 Random Quiz 5

Due: Friday, June 4, 1999                 7 points


Problem 1: Output (3 pts)

Consider the following code segment.

int DoSomething(int a, int & b)
{
   a += 1;
   b += 3;
   return a+b;
}

int DoAgain(int & a, int & b)
{
   a += 1;
   b += 3;
   return a+b;
}


int main()
{
   int a = 3, b = 4;

   cout << DoSomething(a,b) << endl;
   cout << "a= " << a << " b= " << b << endl;

   a = 3, b = 4;
   cout << DoSomething(b,a) << endl;
   cout << "a= " << a << " b= " << b << endl;

   a = 3, b = 4;
   cout << DoAgain(a,a) << endl;
   cout << "a= " << a << " b= " << b << endl;
}

What is the output?









Problem 2: Making Change (4 pts)

Write the function MakeChange to convert a dollar amount into all coins: quarters, nickels and pennies. Put as much as possible into quarters, then nickels, and then pennies.

For example, MakeChange(4.97, quar, nick, pen) modifies quar to be 19, nick to be 4 and pen to be 2.

Complete the function MakeChange below.

void MakeChange(double amount, int & quarters, int & nickels, int & pennies)
// precondition: amount >= 0 and has at most two decimal places
// postcondition: returns the number of quarters, nickels and pennies
//                equal to amount, with preference for quarters first,
//                then nickels, and then pennies.
{