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

I have the answers to 10 of them. Whoever gets the most or first to get all 10 g

ID: 3558541 • Letter: I

Question

I have the answers to 10 of them. Whoever gets the most or first to get all 10 gets "best answer"! If no best answer is chosen, that means nobody has gotten it, as I will check every 5 minutes until someone does!

-----------------------------------------------------------

1) The >> operator can be used to write a line to a file. True / False

-----------------------------------------------------------------------------------

2) An array is a collection of data elements of one or more data types. True / False

---------------------------------------------------------------------------------

3) The __________ function will return true if the file you wish to use is ready for input/output operations.

A.

good()

B.

open()

C.

ready()

D.

is_good()

----------------------------------------------------------------------------------

4) Explain what this code does:

int jimmy [3][5];

A.

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

B.

declares a single dimensional array with a size of 35.

C.

declares a single dimensional array with 3 rows and 5 columns

D.

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

----------------------------------------------------------------------------------------

5) Explain two things that are wrong with this code and how to fix them: (pick 2)

#include

int sum(x, y)

{

std::string result;

     result = x + y;

     return result;

}

A.

return value must be int data type, not string

B.

data types are required for x and y

C.

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

D.

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

-------------------------------------------------------------------------------------

6) 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.

1

B.

Error occurs due to missing class definition

C.

7

D.

Error occurs due to naming collision

-------------------------------------------------------------------------------

7) By default, all variables and functions are defined in the global namespace. True / False

-----------------------------------------------------------------------------------------

8) 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 makes it extremely difficult to use identifiers from other namespaces, such as the Standard namespace.

B.

it decreases the chance of identifiers from multiple namespaces conflicting

C.

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

D.

it increase the chance of identifiers from multiple namespaces conflicting

---------------------------------------------------------------------------------------

9) 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 a parameter

B.

It has a constructor that has one or more parameters

C.

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

D.

None of the above

-------------------------------------------------------------------------------

10) 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 Java default constructor is called.

B.

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.

C.

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.

-------------------------------------------------------------------------------------

11) 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 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.

B.

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

C.

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

D.

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

----------------------------------------------------------------------------

12) 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[]{3, 1, 2, 6, 4, 2};

printArray(int[]);

B.

int result[];

printArray(int result[]);

C.

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

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

D.

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

printArray(result)

--------------------------------------------

13) Consider the following function implementation:

void myvariables::getvalues()
{
        //local variables
        int count;
        std::string first, last;
}

The myvariables class contains a private data member called count that is set to the value 100 before this function is called. If this function included the following line as the last line of this function, what would the result be?
std::cout << count;

A. A Syntax Error

B. 100

C. Unpredictable

D. 0

----------------------------------------

14) Which part(s) of a class is accessible to a nonmember function and which is not?

A. Only the main function has access to public and only member functions have access to private.

B. public and private are both accessible to a nonmember function.

C. public is accessible to a nonmember function, private is not.

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

----------------------------------------------

15) Consider the following function implementation.

#include <iostream>

void print_me( )
{
    std::cout << "Hello World ";
}

Which of the following statements could be used in the main function to call the above function?

A.   print_me();

B.   print.me( );

C.   print_me.print_me(

A.

good()

B.

open()

C.

ready()

D.

is_good()

Explanation / Answer

1)true
2) false
3) B
4) D
5) A,D
6) D
7) true
8) D
9) A
10) C
11) D
12) D
13) B
14) C
15) A

16) B