Chris Pollett>Old Classes>PIC 10a, Spring 2000>Practice Midterm

Spring 2000 PIC 10a Practice Midterm

The midterm covers up through 4.1. Remember to bring your photo ID to the midterm. One problem off this practice midterm will be on the actual midterm.

  1. Define the following terms and give an example of them:
    1. local variable
    2. call-by-reference
    3. type casting
    4. infinite loop
    5. polymorphism
  2. Consider the following two code fragments:
    Fragment 1:
    if( x==1)
    {
    	cout << "hi there";
    }
    else if(y ==1)
    {
    	cout <<"ho there";
    }
    
    Fragment 2:
    if( x==1)
    {
    	cout << "hi there";
    }
    if(y ==1)
    {
    	cout <<"ho there";
    }
    
    Do these pieces of code produce the same output? Explain why or why not.
  3. When a divide by zero occurs in running program assume Floating exception is printed to the screen somehow. What does the following code output?
    int main()
    {
            int x=0;
            if(false && (7/x>0 || true))
                    cout<<"hi there";
    	return 0;
    }
    
  4. Write a function with prototype:
        double power(int x, int y);
    
    that calculates xy for all integers (positive and negative). For any inputs involving an x value of zero it returns 0.
  5. Write a program that uses a const variable which does the following. It asks the user to enter a price as a double then computes the sales tax and prints Your tax is: and outputs it to two digits precision. The tax rate is 8.25 percent.
  6. Write a program that prints out the following exactly:
    This is a quote " and this is a slash \
    
  7. Explain function overloading by writing two functions: one that takes two ints and returns the smaller int and the other takes three ints and returns the smallest int.
  8. What does the following code print out?
    #include< iostream.h>
    
    int function1(int i);
    
    int a=0;
    
    int main()
    {
       int b;
    
       {
         a++;
       }
    
       cout << a << endl;
    
       {
         int a = 2;
    
         cout << a << endl;
       }
    
       {
         cout << a << endl;
       }
    
       b= function1(a);
    
       cout<< "a:" << a << "b: " << b << endl;
    
       return 0;
    }
    
    int function1 (int i)
    {
        int a =3;
        i++;
        return i;
    }
    
  9. Which of the following pairs of expressions are equivalent?
    1. a + b - c
      a + (b - c)
    2. 2*7%5
      14%5
    3. ( x < z) && ( z < y)
      !((x>=z) || (z >=y))
  10. Give an example of how to use a do while loop.