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.
- Define the following terms and give an example of them:
- local variable
- call-by-reference
- type casting
- infinite loop
- polymorphism
-
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.
- 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;
}
-
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.
-
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.
- Write a program that prints out the following exactly:
This is a quote " and this is a slash \
-
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.
-
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;
}
-
Which of the following pairs of expressions are equivalent?
- a + b - c
a + (b - c)
-
2*7%5
14%5
-
( x < z) && ( z < y)
!((x>=z) || (z >=y))
-
Give an example of how to use a do while loop.