Computer Science
2610
Spring 2000
Quiz 3
Answer all of the questions. For the multiple choice questions, circle the letter of the best answer. You have 25 minutes.
(a) A class is a plan for constructing objects.
(b) An object is a plan for constructing classes.
(c) Classes and objects are unrelated.
(d) Classes should not be used in large programs, but objects should.
(a) Every class must have at least one constructor written inside it.
(b) The name of a constructor must not be the same as the name of the class that it is inside.
(c) A constructor is usually used to initialize the variables of an object.
(d) A constructor is not allowed to use the private variables of the object to which it belongs.
(a) ifstream “mydata.txt”;
(b) ofstream “mydata.txt”;
(c) ifstream fil(“mydata.txt”);
(d) ofstream fil(“mydata.txt”);
(a) char jam[31];
(b) char jam[30];
(c) char jam(31);
(d) char jam(30);
void mystery(int A[], int n)
{
int k;
for(k = 0; k < n; k++) A[k] = k;
for(k = 0; k < n-1; k++) A[k+1] =
A[k];
}
(a) It is impossible to say from the information given.
(b) A[0] = 0, A[1] = 0, A[2] = 0, A[3] = 0
(c) A[0] = 0, A[1] = 0, A[2] = 1, A[3] = 2
(d) A[0] = 0, A[1] = 1, A[2] = 2, A[3] = 3
class
Circle
{
public:
Circle(Point Center, double radius);
double perimeter();
private:
Point myCenter;
double myRadius;
};
Write a definition of function perimeter. Expression c.perimeter() should return the perimeter of circle c. Write it as it would occur if written outside of the class.