c++ Hi everyone, please help me to answear these Multiple choice Question. There is 16 of them, so h

c++ Hi everyone, please help me to answear these Multiple choice Question. There is 16 of them, so hard so easy. If you are not sure of the one you’re answearing please indicate that in your answear. THANKS A LOT IN advance What is the purpose of a constructor?

Select one:

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

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

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

d. Constructors can be very useful for controlling access to private member variables by non-member functions Which of the following would be a correct way to call (invoke) this function?

void printArray(int array[])
{

for (int i = 0; i < length; i++)
{

    cout << array[i] << ” “;

}

}

Select one:

a. int result[];
printArray(int result[]);

b. int result[]={3, 1, 2, 6, 4, 2};
printArray(result);

c. int result[]={3, 1, 2, 6, 4, 2};
printArray({3, 1, 2, 6, 4, 2});

d. int[]{3, 1, 2, 6, 4, 2};
printArray(int[]); 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:

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

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

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

d. employee.age = 22;
employee.id_number = 1;
employee.salary = 12000.21; Which of the following classes handles reading from a file?

Select one:

a. ofstream

b. inputstream

c. ifstream

d. iostream Consider the following prototype:

void duplicate (int& a, int& b, int& c)

What do the ampersands (&) signify?

Select one:

a. The ampersands signify that their corresponding arguments are to be passed by reference instead of by value.

b. The ampersands signify that their corresponding arguments are to be passed by value instead of by reference.

c. The ampersands signify that their corresponding arguments are to be passed as a constant (read-only) value.

d. None of these. Ampersands are not allowed in a function prototype 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;
p = “Bob”;
p = 12345;
entries[0] =p;

pairT p;
entries[0] = {key = “Bob”; val = 12345};

pairT p;
p.key = “Bob”;
p.val = 12345;
entries[0] =p; What does the following program do?

#include

#include

using namespace std;

int main () {

ofstream myfile (“example.txt”);

if (myfile.is_open())

{

    myfile << “This is a line.n”;

    myfile << “This is another line.n”;

    myfile.close();

}

else cout << “Unable to open file”;

return 0;

}

Select one:

a. Reads lines from a file

b. Counts lines in a file

c. Writes lines to a file

d. Gets lines from the keyboard What will happen if the example.txt file is found?

#include

#include

#include

using namespace std;

int main () {

string line;

ifstream myfile (“example.txt”);

if (myfile.is_open())

{

    while ( getline (myfile,line) )

    {

      cout << line << ‘n’;

    }

    myfile.close();

}

else cout << “Unable to open file”;

return 0;

}

Select one:

a. Each line of the file is displayed

b. The first line of the file is displayed

c. Each line of the file is counted

d. Each line entered at the keyboard is written to a new file The __________ function will return true if the file you wish to use is ready for input/output operations.

Select one:

is_good()

good()

is_ready()

open() Consider the following class definition:

class Line

{

   public:

      void setLength( double len );

      double getLength( void );

      Line();

   private:

      double length;

};

Which is the constructor?

Select one:

void setLength( double len );

double getLength( void );

Line();

double length; Consider the following class definition:

//username.h

#include

#include

class username

{

   public:

      void getName();           

      void display_usernames();

   private:

      std::string first;

      std::string last;

     

};  

Which functions can carry out an assignment first = A????1JoeA????1; to the private member variable first?

Select one:

a. getName, display_usernames and main can carry out the assignment.

b. Neither getName nor display_usernames nor main can carry out the assignment.

c. Only main can carry out the assignment.

d. getName and main can carry out the assignment, but not display_usernames.

e. getName and display_usernames can carry out the assignment, but not main. Consider the following code. Note: Line numbers are provided on the left side of the code, but are not part of the file.

1 #include <iostream>

2

3 class scores

4 {

5 public:

6    void loadScores();

7    void displayScores();

8 private:

9    int stats[10];

10

11 }

Which line contains a syntax error?

Select one:

a. 3

b. 8

c. 9

d. 11 creating an object is similar to creating a variable, except that you must use the __________ as the data type.

Select one:

a. class name

b. function name

c. Any data type that is native to C++

d. object name

Consider the following class definition:

#include <string>
class world

{

private:

    std::string word;

}; Which statement(s) would you use to add a member void function named greetings that has an empty parameter list and must be called by the main function?

Select one:

public:
       void greetings();

void greetings;

private:
       void greetings();

public void greetings;

Consider the following code from a client main function:
int main()
{
Time target;
target.setHour(5);
target.setMinute(20);
target.getTime();
target.countDown(10);
} Which is a class name?

Select one:

a. Time

b. target

c. setMinute

d. setHour

16. Which part(s) of a class is accessible to the main function and which is not?

Select one:

a. Only nonmember functions have access to public and private.

b. Only class member functions have access to any part of a class.

c. Public and private are both accessible to the main function.

d. Public is accessible to the main function, private is not

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer