Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write the prototype for a function Triple that receives a number of type doub

ID: 669490 • Letter: 1

Question

1. Write the prototype for a function Triple that receives a number of type double and returns the number multiplied by 3.

2. Implement a function Swap that interchanges the values of two int arguments.

3. Given the classes:

class ClassA

{

public:

void SetX(int x);

void Print() const;

private:

int a_;

};

class ClassB : public ClassA

{

public:

void SetXY(int x, int y);

void Print() const;

private:

int b_;

};

4. Which statement best describes the class variables for ClassB?

5. Which of the following is a correct initialization of class variables by a constructor for class Date?

a. Date::Date (int d, int m, int y) :: d(day_), m(month_), y(year_)

{

//optional code here

}

b. Date::Date (int d, int m, int y) : d(day_), m(month_), y(year_)

{

//optional code here

}

c. Date::Date (int d, int m, int y) : day_(d), month_(m), year_(y)

{

//optional code here

}

d. Date::Date (int d, int m, int y) :: day_(d), month_(m), year_(y)

{

//optional code here

}

5. Operator new T

d. Calls a constructor for the class T

a. ClassB objects have two private variables a_ and b_ . b. ClassB objects have one public variable a_ and one private variable b_ . c. ClassB objects have one private variable a_ . d. ClassB objects have one private variable b_ .

5. Which of the following is a correct initialization of class variables by a constructor for class Date?

a. Date::Date (int d, int m, int y) :: d(day_), m(month_), y(year_)

{

//optional code here

}

b. Date::Date (int d, int m, int y) : d(day_), m(month_), y(year_)

{

//optional code here

}

c. Date::Date (int d, int m, int y) : day_(d), month_(m), year_(y)

{

//optional code here

}

d. Date::Date (int d, int m, int y) :: day_(d), month_(m), year_(y)

{

//optional code here

}

Explanation / Answer

1. Write the prototype for a function Triple that receives a number of type double and returns the number multiplied by 3.

Ans: double Triple(double);

2. Implement a function Swap that interchanges the values of two int arguments.

Ans:

void swap(int a, int b)

{

int t;

t=a;

a=b;

b=t;

}

3. Given the classes:

class ClassA

{

public:

void SetX(int x);

void Print() const;

private:

int a_;

};

class ClassB : public ClassA

{

public:

void SetXY(int x, int y);

void Print() const;

private:

int b_;

};

Which statement best describes the class variables for ClassB?

Ans: b) ClassB objects have one public variable a_ and one private variable b_ .

4. Which of the following is a correct initialization of class variables by a constructor for class Date?

a. Date::Date (int d, int m, int y) :: d(day_), m(month_), y(year_)

{

//optional code here

}

b. Date::Date (int d, int m, int y) : d(day_), m(month_), y(year_)

{

//optional code here

}

c. Date::Date (int d, int m, int y) : day_(d), month_(m), year_(y)

{

//optional code here

}

d. Date::Date (int d, int m, int y) :: day_(d), month_(m), year_(y)

{

//optional code here

}

Ans:

b. Date::Date (int d, int m, int y) : d(day_), m(month_), y(year_)

{

//optional code here

}

5. Operator new T

a. Requires the size of the object as an argument

b. Automatically destroys the object when it goes out of scope

c. Returns a pointer to type T

d. Calls a constructor for the class T

Ans: a. Requires the size of the object as an argument