In: Computer Science
I. Given the following code segment below what is the best description of line 5 and line 6? Identify the public and private members.
1. #include <iostream.h>
2. class SimpleCat
3. {
4. public:
5. SimpleCat (int age, int weight);
6. ~SimpleCat(){}
7. int GetAge() {return itsAge;}
8. int GetWeight() {return itsWeight;}
9. private:
10. int itsAge;
11. int itsWeight;
12. };
II. Multiple Choice questions
1. A function that is called automatically each time an object is created or
instantiated is
a. constructor b. Destructor c. Copy constructor
2. A constructor may be _____________.
a. provided by you b. overloaded c. both a and b
3. A class named Gymnast must have this destructor.
a. Gymnast b. Destructor c. ~Gymnast d. *destructor
4. The return type for all constructors is this.
a. void b. int c. float d. double e. no type is allowed
5. A class named Building has a method getfloors(
). If School is a child class of Building and
AMA is an object of type School
then which of the following are valid?
a)Building.getfloors(); b)School.getfloors( ) c)AMA.getfloors();
III. What is the output ?
class A
{
int a,b,c;
public:
A( )
{
cout<<"A"<<endl;
}
~A( )
{
cout<<"B"<<endl;
}
void add( )
{
a=2, b=3;
c=a+b;
cout<<c<<endl;
}
};
void main()
{
A ab;
ab.add( );
}
1.)
2.)
3.)
4.)
5.)
6.)
7.)
A
5
B