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

10. (TCO 4) How many elements does the following array contain? double data [100

ID: 3543035 • Letter: 1

Question

10. (TCO 4) How many elements does the following array contain?
double data [100] [500]; (Points : 7)                                        500
                                        100
                                        600
                                        50,000
              
11. (TCO 4) The function call below is designed to return, in variable result, the product of x and y. All the variables are of type int. What is the correct prototype for such a function?
myFunction(&result, &x, &y); (Points : 7)                                       void myFunction(int, int, int) ;
                                        void myFunction(int *, int *, int *) ;
                                        void myFunction(const int *, const int *, const int *) ;
                                        void myFunction(int *, const int *, const int *) ;
              
12. (TCO 4) What is the output of the following code?
void func(int x)
{
x = x * 2;
}
int main( )
{
int x = 10;
func(x);
cout << x << endl;
} (Points : 7)                                       20
                                        30
                                        10
                                        5
              
13. (TCO 4) When a variable is passed by reference (Points : 7)                                       the variable can be changed by the calling and the called function.
                                        the parameter name is an alias of the variable passed.
                                        the called function can change the value of the variable in the calling program.
                                        All of the above
              
14. (TCO 4) What is the output of the following code?
void func(int x[ ])
{
x[0] = x[0] * 3;
x[1[ = x[1] * 3;
x[2] = x[2] * 3;
}
void main ()
{
int x[ ] = {1, 2, 3};
func(x);
cout << x[0] << << x[1] << << x[2] << endl;
} (Points : 7)                                       1 2 3
                                        3 4 5
                                        3 6 9
                                        3 3 3
              
15. (TCO 4) When organizing a program into three files (main, class implementation, and class header), which is not a .cpp file? (Points : 7)                                       Main
                                        None are .cpp
                                        Class header
                                        Class implementation
              
16. (TCO 4) Given the following class definition and lines of code, what, if anything, is wrong with Line 6 in main?
class Distance
{
private:
int feet;
double inches;
public:
Distance( );
Distance(int initFt, double initIn);
void setFeet(int feetIn);
void setInches(double inchesIn);
int getFeet() const;
double getInches( ) const;
};
int main( )
{
  Distance d1; //Line 1
const int  MAX = 100; //Line 2
Distance list [MAX]; //Line 3
Distance d2(1, 2.3); //Line 4
Distance * pDist; //Line 5
d1.feet = 5; //Line 6
// etc. assume the remaining code is correct
} (Points : 7)                                       It will not compile: feet is private and cannot be directly accessed.
                                        Distance d1; should be changed to int d1;.
                                        The ::d1.feet = 5; should be changed to d1(feet) = 5;.
                                        It will compile, but causes a run-time error because d1.feet has not been declared.
              
17. (TCO 4) A Distance class has two private members, feet, of type int, and inches, of type double. Which prototype correctly declares a 2-argument constructor for such class? (Points : 7)                                       Distance(int, double);
                                        void Distance(int, double);
                                        int Distance(int, double);
                                        Distance(feet, inches);
              
18. (TCO 4) Assume you have a class, called Simple, that has two data members, a and b, both of type int. What can be said about the function prototype given below? (Choose the best answer.)
Simple(int=0, int=0); (Points : 7)                                       It is the prototype for the default constructor.
                                        It is the prototype for the 2-argument constructor.
                                        It is both the 0-argument, and the 2-argument, constructor.
                                        It is incorrect. 11. (TCO 4) The function call below is designed to return, in variable result, the product of x and y. All the variables are of type int. What is the correct prototype for such a function?
myFunction(&result, &x, &y); (Points : 7)                                       void myFunction(int, int, int) ;
                                        void myFunction(int *, int *, int *) ;
                                        void myFunction(const int *, const int *, const int *) ;
                                        void myFunction(int *, const int *, const int *) ;

Explanation / Answer

10.

double data [100] [500]; is a two dimensional array containing 100 columns and 500 rows. It will contain 100X500=50000 elements.

Hence, the correct answer is 50000.

11.

The correct prototype isvoid myFunction(int *, const int *, const int *) ;

According to the given function call, the product of x and y should be stored in result and cannot be declared as const. The values of x and y should not be changed in the function. So they should be declared as const in function prototype.

Hence, the correct answer is isvoid myFunction(int *, const int *, const int *) ;

12.

The output of the given code is 10.

Initially the value of x is 10. Within the function the value of x is multiplied by 2. As the function is called by using call by value mechanism, any changes made to variable x in the function will be local to the function and will not affect the variable x in the main function. So, when the statement cout << x << endl;, is executed, the value 10 will printed.

Hence, the correct answer is 10.

13.

When a variable is passed by reference, any changes made to variable in the function will have direct effect on the variable. The called function as well as the calling function can change the value of the variable.

Hence, the correct answer is All the above.

14.

The output of the given code is 3 6 9.

When an array is passed, by default the reference of the array is passed. So any changes made to the array in the function will have direct effect on the array. In the function, the values of the array variables are multiplied by 3. So cout statement will print 3 6 9.

Hence, the correct answer is 3 6 9.

15.

When organizing a program into three files (main, class implementation, and class header), main and class implementation will be .cpp files.

The class header file will be .h or .hpp file.

Hence, the correct answer is Class header.

16.

Private data members can be accessed only through member functions of the class. They cannot be accessed directly by the object of the class.

The variable feet is a private data member of the class Distance. So they cannot be accessed directly using the object d1 of class Distance.

Hence, the correct answer is It will not compile: feet is private and cannot be directly accessed.

17.

A constructor should have the same name as the class. As the class name is Distance and data type of two private members is int and double, the correct prototype of constructor for the class Distance is Distance(int, double);

Hence, the correct answer is Distance(int, double); .

18.

The class name is Simple with data members a and b of type int. The function prototype

Simple(int=0, int=0); is a prototype for the 2-argument constructor.

Hence, the correct answer is “It is the prototype for the 2-argument constructor”.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote