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

1. template < class T1, class T2 > T1 f1( T1 value1, T2 value2 ) { if ( value1 <

ID: 667025 • Letter: 1

Question

1. template < class T1, class T2 > T1 f1( T1 value1, T2 value2 ) { if ( value1 < value2 ) return value1; else return value1*2; } What would be returned by the following function call? f 1 (10, 20.7).

2. Suppose the unary operator ! is an overloaded member function of the class LinkedList. What’s the function that is equivalent to !o where o is an object of LinkedList?

3. If the line ‘friend class A;’ appears in class B, and the line ‘friend class B;’ appears in class C, then: a. Class A can access private variables of class B. b. Class A is a friend of class C. c. Class C can call class A’s private member functions. d. Class B can access class A’s private variables.

4. Consider the following statement of operator overloading, true or false? a. An operator function must be implemented as a member function b. The leftmost operand must be an object of the operator’s class c. Assuming that the operator + is overloaded, it makes the operator += overloaded d. An overloaded operator can have more than one operator functions implemented

5. The following statements about an abstract class, true or false? a. It cannot have abstract derived classes. b. It contains at most one pure virtual function. c. It can have objects instantiated from them if the proper permissions are set. d. It is defined, but cannot instantiate any objects from it. 6. What will be the proper output, line1 and line2 code? int main(){ ofstream myfile; myfile.open ("config.dat"); myfile << "int 12 1 9 1 8 6 3 4 3 9 7 0 " << "float 2 56.12 63.66 " << "char 5 H e l l o "; myfile.close(); ifstream inClientFile; inClientFile.open( "config.dat"); int numbOfLines = 0; string line; while (getline(inClientFile, line)){ ++numbOfLines; } cout << "number of lines " << numbOfLines << endl; //(line1) ---------------; //(line2) ---------------; // other functions follow to parse each line in the file // the code is not shown /

Explanation / Answer

1) here the function call to f1(10,20.7) returns 10.because the arguments which are passed to the function are satisfying the condition (value1 < value2). Hence it returns value1 value which is 10.

2) Not is an Bitwise operator which used as not.for example the value of !(true) is false.Hence the operator is overloaded.the result !o(where o is the object of LinkedList) is based on the value in the LinkedList.If the value are integers or floats it creates a runtime error.

3) the answer is a.class A can access private values of class B.

friend class has ability to access the private and protected members of the another class by declarint it as a friend of that class.friend is a keyword in C++. It is used to create friend classes and functions.

4) Operator overloading is used to assign additional capabilities to the basic operators.hence they can work with the class objects instead of datavalues.

a. An operator function must be implemented as a member function: The answer is TRUE.

b. The leftmost operand must be an object of the operator’s class:The answer is TRUE

c. Assuming that the operator + is overloaded, it makes the operator += overloaded:The answer is FALSE

d. An overloaded operator can have more than one operator functions implemented : the answer is FALSE

5) Abstract class is a class which has virtual functions and constant values in it. It must be extracted by another class to use its members.

a. It cannot have abstract derived classes.(FALSE)

b. It contains at most one pure virtual function. (TRUE)

c. It can have objects instantiated from them if the proper permissions are set. (TRUE)

d. It is defined, but cannot instantiate any objects from it.(TRUE)

6) The question is not clear.there is no line1 and line2 code to answer.