Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5. Explain what this code does: int jimmy [3][5]; A. declares a single dimensional array with 3 rows and 5 columns B. declares a multi-dimensional

5. Explain what this code does:

int jimmy [3][5];

A. declares a single dimensional array with 3 rows and 5 columns

B. declares a multi-dimensional array with the value 3 in the first index and the value 5 in the second index.

C. declares a single dimensional array with a size of 35.

D. declares a multi-dimensional array with 3 rows and 5 columns

6. Consider the following function prototypes:

void passbyValue(int valnum);

void passbyRef(int &refnum);

Which has a reference parameter?

A. void passbyRef(int &refnum);

B. void passbyValue(int valnum);

7. Explain two things that are wrong with this code and how to fix them:

#include

int sum(x, y)

{

std::string result;

result = x + y;

return result;

}

A. You cannot use the + operator with a char data type.

B. data types are required for x and y

C. return value must be int data type, not string

D. The prototype should be: void sum(x, y);

8. Consider the following code. What is the output?

foo.h:

1

2

3

4

5

int DoSomething(int nX, int nY)

{

return nX + nY;

}

goo.h:

1

2

3

4

5

int DoSomething(int nX, int nY)

{

return nX - nY;

}

main.cpp:

1

2

3

4

5

6

7

8

9

10 #include "foo.h"

#include "goo.h"

#include //include iostream

using namespace std;

int main()

{

cout << DoSomething(4, 3);

return 0;

}

A. 7

B. 1

C. Error occurs due to naming collision

D. Error occurs due to missing class definition

9. By default, all variables and functions are defined in the global namespace.

A. True

B. False

10. Although the using keyword can be used outside of a function to help resolve every identifier in the file, this is not recommended. Why?

A. it decreases the chance of identifiers from multiple namespaces conflicting

B. it increase the chance of identifiers from multiple namespaces conflicting

C. it makes it extremely difficult to use identifiers from other namespaces, such as the Standard namespace.

D. it is considered bad style because it makes your code sloppier and more difficult to read.

11. What is the purpose of a constructor?

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

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

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

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

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

#include "line.h"

int main( )

{

Line line(10.0);

}

A. It has a constructor that has one or more parameters

B. It has a constructor that has a parameter

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

13. 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;

A. 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 default constructor is called.

B. 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.

C. 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.

14. Assume that myList is a previously declared an initialized array. Assume that the variable length holds the total number of elements in the array. What does the following code block do?

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

cout << myList[i] << " ";

}

A. Displays the total number of elements in the array called myList followed by a space.

B. Displays the data stored before the first element of the array called myList up to the data element stored in the second to last element in the array, separated by a space.

C. Displays each data element stored in the array called myList, separated by a space.

D. Displays each index number of the array called myList, followed by a space, up to the last index number in the array's length.

15. Which of the following would be a correct way to call (invoke) this method?

void printArray(int array[]) {

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

cout << array[i] << " ";

}

}

A.

int result[]={3, 1, 2, 6, 4, 2};

printArray({3, 1, 2, 6, 4, 2});

B.

int result[];

printArray(int result[]);

C.

int result[]={3, 1, 2, 6, 4, 2};

printArray(result);

D.

int[]{3, 1, 2, 6, 4, 2};

printArray(int[]);

16. Which search algorithm can be described as follows:

Given a collection you try every element in the collection until you have found the element or until you reach the end of the collection.

A. No answer text provided.

B. Recursive Binary Search

C. Sequential Search

D. Iterative Binary Search

17. 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?

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.

employee.age = 22;

employee.id_number = 1;

employee.salary = 12000.21;

D.

age = 22;

id_number = 1;

salary = 12000.21;

18. Consider the following function named mystery:

void mystery()

{

myclass foo;

int original_num = 1;

std::cout << original_num << std::endl;

foo.passbyValue(original_num);

std::cout << original_num << std::endl;

foo.passbyRef(original_num);

std::cout << original_num << std::endl;

}

How would you call (activate) this function?

A. mystery();

B. This function cannot be called; it is run automatically when the program is started.

C. mystery(4, 3);

D. foo.mystery();

19. What is the value of s4 as a result of the following statements:

string s = "yellow";

s4 = s.substr(1);

A. yellow

B. yello

C. ellow

D. llow

20. Consider the following incomplete main function.

int main () {

ofstream myfile ("example.txt");

if (myfile.is_open())

{

//TODO: complete this block of code

}

else cout << "Unable to open file";

return 0;

}

Which statements might be used to complete the if block?

A.

while ( myfile.good() )

{

getline (myfile,line);

cout << line << endl;

myfile.close();

}

B.

myfile << "This is a line. ";

myfile << "This is another line. ";

myfile.close();

C.

while ( myfile.good() )

{

getline (myfile,line);

cout << line << endl;

}

myfile.close();

D.

myfile >> "This is a line. ";

myfile >> "This is another line. ";

myfile.close();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

Students also viewed these Databases questions

Question

Compare the different types of employee separation actions.

Answered: 1 week ago

Question

Assess alternative dispute resolution methods.

Answered: 1 week ago

Question

Distinguish between intrinsic and extrinsic rewards.

Answered: 1 week ago