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

hi C++ folks, could you guys help me with these multiple choice question. There

ID: 660941 • Letter: H

Question

hi C++ folks, could you guys help me with these multiple choice question.

There is 25 of them. Please do your best, and indicate the one you're not sure of. THANKS EVERYONE.

What is the purpose of a constructor?

Select one:

Constructors can be very useful for defining and initializing private member variables.

Constructors can be very useful for setting initial values for certain member variables.

Constructors can be very useful for controlling access to private member variables by non-member functions.

Constructors can be very useful for handling all of the c++ code required in a program.

Consider the following main function. What can you guess about the Line class?

#include "line.h"

int main()
{
Line line(10.0);

}

Select one:

It has a member variable with the same name as the class that can store the value 10.0

It has a constructor that has a parameter

It has a constructor that has one or more required parameters

It uses the C++ default constructor

You have a main method with the following statements. Each statement creates an object of the Platypus class, but one sends an argument in parentheses and the other does not. In which circumstances would this be allowed?

Platypus p1("digger");

Platypus p1;

Select one:

When the Platypus class has a single constructor that has a String parameter. When an object is created with a String argument, this constructor is called. When an object is created without a constructor argument, the c++ default constructor is called.

When the Platypus class has an overloaded constructor. One constructor of this class would have no parameters. When an object is created without an argument, this constructor is called. The class also has another constructor that has a string parameter. When an object is created with a String argument, this constructor is called.

This will always produce an error. Only one constructor is allowed. Either a constructor with arguments or without arguments, but not both for the same class.

This is only allowed when no constructor is defined.

You have the following struct defined in the private area of your class:

struct database {
int id_number;
int age;
float salary;
};

database employee;

How would you assign a value to each of the data members in a function belonging to the same class?

Select one:

employee->age = 22;
employee->id_number = 1;
employee->salary = 12000.21;

c. age = 22;
id_number = 1;
salary = 12000.21;

employee.age = 22;
employee.id_number = 1;
employee.salary = 12000.21;

employee::age = 22;
employee::id_number = 1;
employee::salary = 12000.21;

Which of the following classes handles reading from a file?

Select one:

iostream

ifstream

ofstream

inputstream

You have an array of structs that is defined as follows.

struct pairT {
std::string key;
int val;
};

Which of the following could be used to add a new struct to the array called entries in position 0?

Select one:

pairT p;
p.key = "Bob" && p.val = 12345;
entries.0 =p;

pairT p("Bob", 12345);

pairT p;
p = "Bob";
p = 12345;
entries[0] =p;

pairT p;
p.key = "Bob";
p.val = 12345;
entries[0] =p;

What does the following program do?

#include <iostream>

#include <fstream>

using namespace std;

int main () {

ofstream myfile ("example.txt");

if (myfile.is_open())

{

    myfile << "This is a line. ";

    myfile << "This is another line. ";

    myfile.close();

}

else cout << "Unable to open file";

return 0;

}

Select one:

Counts lines in a file

Reads lines from a file.

Gets lines from the keyboard

Writes lines to a file

What will happen if the example.txt file is found?

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main () {

string line;

ifstream myfile ("example.txt");

if (myfile.is_open())

{

    while ( getline (myfile,line) )

    {

      cout << line << ' ';

    }

    myfile.close();

}

else cout << "Unable to open file";

return 0;

}

Select one:

a. Each line of a file is written to another file

b. Each line of the file is counted

c. Each line entered at the keyboard is written to a new file

d. Each line of the file is displayed

Unlike an array, you should consider passing a vector by reference with the & symbol in the parameter list.

Select one:

True

False

You need to modify this function so that it only erases the string called sub if it is found. Note that this file has a #include <string>

void Iclear(string sub, string &s)
{
int found;

found = s.find(sub);
s.erase(found, sub.length());
}

Which if clause should you add to this function?

Select one:

a. void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(found == string::npos)
s.erase(found, sub.length());

}

b. void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(found != -1)
s.erase(found, sub.length());

}

c. void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(sub != string::npos)
s.erase(found, sub.length());

}

d. void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(found != string::npos)
s.erase(found, sub.length());

}

Consider the following non-member function:

int addition (int a, int b)

{ int r;

r = a + b;

return r;

}

Which of the following could replace the above function with a member function of the class named myclass and properly call the member function?

Select one:

int myclass::addition (int a, int b)

{ int r;

r = a + b;

return r;

}

int main()

{

int num1 = 1;

int num2 = 2;

int total = 0;

myclass test1;

total = test1.addition(num1, num2);

}

int myclass:addition (int a, int b)

{ int r;

r = a + b;

return r;

}

int main()

{

int num1 = 1;

int num2 = 2;

int total = 0;

myclass test1;

total = myclass.addition(num1, num2);

}

int myclass.addition (int a, int b)

{ int r;

r = a + b;

return r;

}

int main()

{

int num1 = 1;

int num2 = 2;

int total = 0;

myclass test1;

total = test1::addition(num1, num2);

}

int addition::myclass (int a, int b)

{ int r;

r = a + b;

return r;

}

int main()

{

int num1 = 1;

int num2 = 2;

int total = 0;

myclass test1;

total = myclass.addition(num1, num2);

}

Which statement initializes (allocates) a pointer to point to a memory address in the heap?

Select one:

int* p;

int *p = new int;

int p = new int;

int& p = new int;

Here is a function declaration:

    void goo(int* x)

    {

        *x = 1;

    }

Suppose that a is an int* variable pointing to some integer, and *a is equal to zero. What is printed if you cout << a; after the function call goo(a)?

Select one:

The address of x

1

0

The address of a

What is printed by these statements?

   int *p1 = new int;

   int *p2 = p1;

   *p1 = 3;

   *p2 = *p1;

   cout << p1 << endl;

Select one:

4

The address of p1

3

Unpredictable

What is wrong with this block of code?

    int *p1 = new int; //line 1

    int *p2;        //line 2

    *p2 = 4;        //line 3

    p1 = p2;        //line 4

    cout << p1 << p2 << endl; //line 5

Select one:

a. A pointer assignment to set the address of a pointer cannot be done with an integer value on line 3.

b. The p1 pointer is incorrectly instantiated with the wrong operator before accessing its memory location on line 1.

c. The p2 pointer is not instantiated with the new operator before accessing its memory location on line 3.

d. Parentheses are missing from this statement.

What is the delete keyword used for?

Select one:

To delete both the pointer and to deallocate the space in the heap that is pointed to.

To deallocate the space in the heap pointed to by a pointer.

To delete the value stored in the heap pointed to by a pointer

To remove a pointer address from the stack

Which of the following declarations is legal (will not generate an error)?

Select one:

int *q;

int q = new *int;

int q* = new int;

int q = new int;

What is printed by these statements?

   int p1 = 3;

   int &p2 = p1;

   p2 = p1;

   cout << p1 << endl;

Select one:

The address in the stack of both p1 and p2

3

The address in the stack of p1

An error occurs

Consider the following class:

class hourlyEmp: public employee {

         public:

             hourlyEmp();

             hourlyEmp(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveRaise(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

How could you create an object of this class (Select all that apply)?

Select one or more:

hourlyEmp arnold("Arnold Jones","23456664",13,20);

hourlyEmp arnold();

employee::hourlyEmp arnold("Arnold Jones");

employee arnold("Arnold Jones","23456664",13,20);

Which of the following is a pure abstract function?

Select one:

virtual double area() = 0;

pure virtual double area() = {};

virtual double area() {area= 0};

abstract double area();

A programming language is required to provide which things in order for it to be considered an object oriented programming language?

Select one or more:

Pointers

Inheritance

Encapsulation

Polymorphism

Consider the following:

class base {

        public:

            void vfunc() {

                cout << "This is base's vfunc()." << endl;

            }

    };

    class derived1 : public base {

        public:

            void vfunc() {

                cout << "This is derived1's vfunc()." << endl;  

            }

    };

int main()

    {

        base *p, b;

        derived1 d1;

        p = &b;

        p -> vfunc();

        // remember, this is equivalent to (*p).vfunc();

        p = &d1;

        p -> vfunc();

    }

What is the output of this program?

Select one:

This is base's vfunc().
This is base's vfunc().

Error. Ambiguous reference.

This is base's vfunc().
This is derived1's vfunc().

This is derived1's vfunc().
This is derived1's vfunc()

Consider the following:

class base {

        public:

            virtual void vfunc() {

                cout << "This is base's vfunc()." << endl;

            }

    };

    class derived1 : public base {

        public:

            void vfunc() {

                cout << "This is derived1's vfunc()." << endl;  

            }

    };

int main()

    {

        base *p, b;

        derived1 d1;

        p = &b;

        p -> vfunc();

        // remember, this is equivalent to (*p).vfunc();

        p = &d1;

        p -> vfunc();

    }

What is the output of this program?

Select one:

a. This is base's vfunc().
This is derived1's vfunc().

b. This is derived1's vfunc().
This is base's vfunc().

c. This is derived1's vfunc().
This is derived1's vfunc().

d. This is base's vfunc().
This is base's vfunc()

Consider the following code.

string str1(3, 'a');

cout << str1 << endl;

string str2(str1);

cout << str2 << endl;

string str3("hello", 2);

cout << str3 << endl;

string str5 = "How are you?";
string str6(str5, 4, 3);

cout << str6 << endl;

Assuming that this code has the using namespace std directive and the appropriate #include statements, what would you expect the output to be?

Select one:

aaa
aaa
he
are

aaa
aa
he
are

he
aaa
aaa
aaa

aaa
aa
he
are

25.Consider the following class definition:

// this is the file "employee.h"

       

     #ifndef EMPLOYEE_H

     #define EMPLOYEE_H

     #include <string>

     using namespace std;

     class employee {

         public:

             employee();

             employee(const string& newName, const string& newSsn);   

             string getName() const;

             string getSsn() const;

             void changeName(const string& newName);

             void changeSsn(const string& newSsn);

         protected:

             string name;

             string ssn;

             double netPay;

     };

    

     #endif

Which of the following is a child class of the employee class shown above?

Select one:

// this is the file "contractor.h"

       

     #ifndef CONTRACTOR_H

     #define CONTRACTOR_H

     #include "employee.h"

     #include

     using namespace std;

     class contractor: public employee {

         public:

             contractor();

             contractor(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveBonus(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

    

     #endif

// this is the file "contractor.h"

       

     #ifndef CONTRACTOR_H

     #define CONTRACTOR_H

     #include "employee.h"

     #include

     using namespace std;

     class contractor:: public employee {

         public:

             contractor();

             contractor(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveBonus(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

    

     #endif

// this is the file "contractor.h"

       

     #ifndef CONTRACTOR_H

     #define CONTRACTOR_H

     #include "employee.h"

     #include

     using namespace std;

     class contractor: inherit employee {

         public:

             contractor();

             contractor(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveBonus(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

    

     #endif

// this is the file "contractor.h"

       

     #ifndef CONTRACTOR_H

     #define CONTRACTOR_H

     #include "employee.h"

     #include

     using namespace std;

     class employee: public contractor {

         public:

             contractor();

             contractor(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveBonus(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

    

     #endif

What is the purpose of a constructor?

Select one:

Constructors can be very useful for defining and initializing private member variables.

Constructors can be very useful for setting initial values for certain member variables.

Constructors can be very useful for controlling access to private member variables by non-member functions.

Constructors can be very useful for handling all of the c++ code required in a program.

Consider the following main function. What can you guess about the Line class?

#include "line.h"

int main()
{
Line line(10.0);

}

Select one:

It has a member variable with the same name as the class that can store the value 10.0

It has a constructor that has a parameter

It has a constructor that has one or more required parameters

It uses the C++ default constructor

You have a main method with the following statements. Each statement creates an object of the Platypus class, but one sends an argument in parentheses and the other does not. In which circumstances would this be allowed?

Platypus p1("digger");

Platypus p1;

Select one:

When the Platypus class has a single constructor that has a String parameter. When an object is created with a String argument, this constructor is called. When an object is created without a constructor argument, the c++ default constructor is called.

When the Platypus class has an overloaded constructor. One constructor of this class would have no parameters. When an object is created without an argument, this constructor is called. The class also has another constructor that has a string parameter. When an object is created with a String argument, this constructor is called.

This will always produce an error. Only one constructor is allowed. Either a constructor with arguments or without arguments, but not both for the same class.

This is only allowed when no constructor is defined.

You have the following struct defined in the private area of your class:

struct database {
int id_number;
int age;
float salary;
};

database employee;

How would you assign a value to each of the data members in a function belonging to the same class?

Select one:

employee->age = 22;
employee->id_number = 1;
employee->salary = 12000.21;

c. age = 22;
id_number = 1;
salary = 12000.21;

employee.age = 22;
employee.id_number = 1;
employee.salary = 12000.21;

employee::age = 22;
employee::id_number = 1;
employee::salary = 12000.21;

Which of the following classes handles reading from a file?

Select one:

iostream

ifstream

ofstream

inputstream

You have an array of structs that is defined as follows.

struct pairT {
std::string key;
int val;
};

Which of the following could be used to add a new struct to the array called entries in position 0?

Select one:

pairT p;
p.key = "Bob" && p.val = 12345;
entries.0 =p;

pairT p("Bob", 12345);

pairT p;
p = "Bob";
p = 12345;
entries[0] =p;

pairT p;
p.key = "Bob";
p.val = 12345;
entries[0] =p;

What does the following program do?

#include <iostream>

#include <fstream>

using namespace std;

int main () {

ofstream myfile ("example.txt");

if (myfile.is_open())

{

    myfile << "This is a line. ";

    myfile << "This is another line. ";

    myfile.close();

}

else cout << "Unable to open file";

return 0;

}

Select one:

Counts lines in a file

Reads lines from a file.

Gets lines from the keyboard

Writes lines to a file

What will happen if the example.txt file is found?

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main () {

string line;

ifstream myfile ("example.txt");

if (myfile.is_open())

{

    while ( getline (myfile,line) )

    {

      cout << line << ' ';

    }

    myfile.close();

}

else cout << "Unable to open file";

return 0;

}

Select one:

a. Each line of a file is written to another file

b. Each line of the file is counted

c. Each line entered at the keyboard is written to a new file

d. Each line of the file is displayed

Unlike an array, you should consider passing a vector by reference with the & symbol in the parameter list.

Select one:

True

False

You need to modify this function so that it only erases the string called sub if it is found. Note that this file has a #include <string>

void Iclear(string sub, string &s)
{
int found;

found = s.find(sub);
s.erase(found, sub.length());
}

Which if clause should you add to this function?

Select one:

a. void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(found == string::npos)
s.erase(found, sub.length());

}

b. void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(found != -1)
s.erase(found, sub.length());

}

c. void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(sub != string::npos)
s.erase(found, sub.length());

}

d. void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(found != string::npos)
s.erase(found, sub.length());

}

Consider the following non-member function:

int addition (int a, int b)

{ int r;

r = a + b;

return r;

}

Which of the following could replace the above function with a member function of the class named myclass and properly call the member function?

Select one:

int myclass::addition (int a, int b)

{ int r;

r = a + b;

return r;

}

int main()

{

int num1 = 1;

int num2 = 2;

int total = 0;

myclass test1;

total = test1.addition(num1, num2);

}

int myclass:addition (int a, int b)

{ int r;

r = a + b;

return r;

}

int main()

{

int num1 = 1;

int num2 = 2;

int total = 0;

myclass test1;

total = myclass.addition(num1, num2);

}

int myclass.addition (int a, int b)

{ int r;

r = a + b;

return r;

}

int main()

{

int num1 = 1;

int num2 = 2;

int total = 0;

myclass test1;

total = test1::addition(num1, num2);

}

int addition::myclass (int a, int b)

{ int r;

r = a + b;

return r;

}

int main()

{

int num1 = 1;

int num2 = 2;

int total = 0;

myclass test1;

total = myclass.addition(num1, num2);

}

Which statement initializes (allocates) a pointer to point to a memory address in the heap?

Select one:

int* p;

int *p = new int;

int p = new int;

int& p = new int;

Here is a function declaration:

    void goo(int* x)

    {

        *x = 1;

    }

Suppose that a is an int* variable pointing to some integer, and *a is equal to zero. What is printed if you cout << a; after the function call goo(a)?

Select one:

The address of x

1

0

The address of a

What is printed by these statements?

   int *p1 = new int;

   int *p2 = p1;

   *p1 = 3;

   *p2 = *p1;

   cout << p1 << endl;

Select one:

4

The address of p1

3

Unpredictable

What is wrong with this block of code?

    int *p1 = new int; //line 1

    int *p2;        //line 2

    *p2 = 4;        //line 3

    p1 = p2;        //line 4

    cout << p1 << p2 << endl; //line 5

Select one:

a. A pointer assignment to set the address of a pointer cannot be done with an integer value on line 3.

b. The p1 pointer is incorrectly instantiated with the wrong operator before accessing its memory location on line 1.

c. The p2 pointer is not instantiated with the new operator before accessing its memory location on line 3.

d. Parentheses are missing from this statement.

What is the delete keyword used for?

Select one:

To delete both the pointer and to deallocate the space in the heap that is pointed to.

To deallocate the space in the heap pointed to by a pointer.

To delete the value stored in the heap pointed to by a pointer

To remove a pointer address from the stack

Which of the following declarations is legal (will not generate an error)?

Select one:

int *q;

int q = new *int;

int q* = new int;

int q = new int;

What is printed by these statements?

   int p1 = 3;

   int &p2 = p1;

   p2 = p1;

   cout << p1 << endl;

Select one:

The address in the stack of both p1 and p2

3

The address in the stack of p1

An error occurs

Consider the following class:

class hourlyEmp: public employee {

         public:

             hourlyEmp();

             hourlyEmp(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveRaise(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

How could you create an object of this class (Select all that apply)?

Select one or more:

hourlyEmp arnold("Arnold Jones","23456664",13,20);

hourlyEmp arnold();

employee::hourlyEmp arnold("Arnold Jones");

employee arnold("Arnold Jones","23456664",13,20);

Which of the following is a pure abstract function?

Select one:

virtual double area() = 0;

pure virtual double area() = {};

virtual double area() {area= 0};

abstract double area();

A programming language is required to provide which things in order for it to be considered an object oriented programming language?

Select one or more:

Pointers

Inheritance

Encapsulation

Polymorphism

Consider the following:

class base {

        public:

            void vfunc() {

                cout << "This is base's vfunc()." << endl;

            }

    };

    class derived1 : public base {

        public:

            void vfunc() {

                cout << "This is derived1's vfunc()." << endl;  

            }

    };

int main()

    {

        base *p, b;

        derived1 d1;

        p = &b;

        p -> vfunc();

        // remember, this is equivalent to (*p).vfunc();

        p = &d1;

        p -> vfunc();

    }

What is the output of this program?

Select one:

This is base's vfunc().
This is base's vfunc().

Error. Ambiguous reference.

This is base's vfunc().
This is derived1's vfunc().

This is derived1's vfunc().
This is derived1's vfunc()

Consider the following:

class base {

        public:

            virtual void vfunc() {

                cout << "This is base's vfunc()." << endl;

            }

    };

    class derived1 : public base {

        public:

            void vfunc() {

                cout << "This is derived1's vfunc()." << endl;  

            }

    };

int main()

    {

        base *p, b;

        derived1 d1;

        p = &b;

        p -> vfunc();

        // remember, this is equivalent to (*p).vfunc();

        p = &d1;

        p -> vfunc();

    }

What is the output of this program?

Select one:

a. This is base's vfunc().
This is derived1's vfunc().

b. This is derived1's vfunc().
This is base's vfunc().

c. This is derived1's vfunc().
This is derived1's vfunc().

d. This is base's vfunc().
This is base's vfunc()

Consider the following code.

string str1(3, 'a');

cout << str1 << endl;

string str2(str1);

cout << str2 << endl;

string str3("hello", 2);

cout << str3 << endl;

string str5 = "How are you?";
string str6(str5, 4, 3);

cout << str6 << endl;

Assuming that this code has the using namespace std directive and the appropriate #include statements, what would you expect the output to be?

Select one:

aaa
aaa
he
are

aaa
aa
he
are

he
aaa
aaa
aaa

aaa
aa
he
are

25.Consider the following class definition:

// this is the file "employee.h"

       

     #ifndef EMPLOYEE_H

     #define EMPLOYEE_H

     #include <string>

     using namespace std;

     class employee {

         public:

             employee();

             employee(const string& newName, const string& newSsn);   

             string getName() const;

             string getSsn() const;

             void changeName(const string& newName);

             void changeSsn(const string& newSsn);

         protected:

             string name;

             string ssn;

             double netPay;

     };

    

     #endif

Which of the following is a child class of the employee class shown above?

Select one:

// this is the file "contractor.h"

       

     #ifndef CONTRACTOR_H

     #define CONTRACTOR_H

     #include "employee.h"

     #include

     using namespace std;

     class contractor: public employee {

         public:

             contractor();

             contractor(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveBonus(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

    

     #endif

// this is the file "contractor.h"

       

     #ifndef CONTRACTOR_H

     #define CONTRACTOR_H

     #include "employee.h"

     #include

     using namespace std;

     class contractor:: public employee {

         public:

             contractor();

             contractor(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveBonus(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

    

     #endif

// this is the file "contractor.h"

       

     #ifndef CONTRACTOR_H

     #define CONTRACTOR_H

     #include "employee.h"

     #include

     using namespace std;

     class contractor: inherit employee {

         public:

             contractor();

             contractor(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveBonus(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

    

     #endif

// this is the file "contractor.h"

       

     #ifndef CONTRACTOR_H

     #define CONTRACTOR_H

     #include "employee.h"

     #include

     using namespace std;

     class employee: public contractor {

         public:

             contractor();

             contractor(const string& newName, const string& newSsn,

                            double newPayRate, double newHours);

             double getHours() const;

             void setHours(double newHours);

             void giveBonus(double amount);

             void printCheck() const;

         private:

             double hours;

             double payRate;

     };

    

     #endif

Explanation / Answer

1.

The main purpose of a constructor function is to initialize the member variables.

Thus, the correct option is “Constructors can be very useful for setting initial values for certain member variables.”

2.

If a class has a constructor with parameters, then only it is allowed to pass parameters. In the given example one parameter is passed to constructor.

Thus, the correct option is “It has a constructor that has a parameter.”

3.

When a constructor with parameters is defined in a class, it is necessary to define a default constructor with no parameters. Then only, it allows executing the statements given in the question; otherwise, it arise error.

Thus, the correct option is “When the Platypus class has an overloaded constructor. One constructor of this class would have no parameters. When an object is created without an argument, this constructor is called. The class also has another constructor that has a string parameter. When an object is created with a String argument, this constructor is called.”

4.

The struct variable employee and struct data members belong to same class and they are assigning in the member function of same class. Therefore, the operator :: is not necessary.

Thus, the correct option is “

employee.age = 22;
employee.id_number = 1;
employee.salary = 12000.21;”

5.

obviously, ifstream is used to read data from files.

Thus, the correct option is “ifstream”.

6.

We can’t directly assign a struct variable to array. But, a struct variable can be assigned to one array element of same type.

Thus, the correct option is,

pairT p;
p.key = "Bob";
p.val = 12345;
entries[0] =p;

7.

correct option is “Writes lines to a file.”

8.

correct option is,” d. Each line of the file is displayed.”

9.

A vecotor can be passed by value or by reference , as an array is passed.

Thus, correct option is “False.”

10.

When a sub string is searched using find() method, it returns the first character position of string in the main string; otherwise, it returns string::npos(not found).

So, it is required to check whether a sub string is found or not

Thus correct option is,

d.

void Iclear(string sub, string &s)
{
int found;
found = s.find(sub);
if(found != string::npos)
s.erase(found, sub.length());

}