Question & Answer: If the line: friend class A: appears in class B, and the line: friend class B: appears in class C. then: A) Cl…..

35. If the line friend class A; appears in class B, and the line: friend class B; appears in class C. then: A) B) C) D) class A is a friend of class c Class A can access private variable Class c can call class As private member functions. Class s of class B, B can access class As private variables 36. The correct function name for overloading the addition (+) operator 1s: A) operator+ B) operator(+) C) operator:+ D) operator+ 37. Suppose you have a programmer-defined data type Data and want to overload the operator to output your data type to the screen in the form cout <s datatoPrintr cascaded function cal1s. The first 1ine of the function definition would be: and allow A) ostream &operatore<( ostream koutput, const Data &dataToPrint) B) ostream operator<c( ostream koutput, const Data &dataToPrint) C) ostream operator<<( const Data &dataToPrint, ostream koutput ) D) ostream operator<<( const Data &dataToPrint, ostream &output ) 38. Which statement about class unique ptr (ot the new C++ standard) and dynamie memory allocation is false? obect of class unique_ptr maintaine a pointer to dynamically allocated A) An B) unique ptr cannot be used to dynamically allocate memory to an array of object. memorY c) class template uni D) When a unique_ptr goes out of scope, ite destructor automatically returna the 39. Which of the following is most likely a base class of the other three? unique ptr object can be used just as a regular pointer variable is managed memory to the free store A) automobile B) convertible. C) miniVan D) sedan 40. When should base class members be declared protected? A) When all clients should be able to access these members. B) When c) When these members should be available only to derived classes (and friends), these members are used only by member functions of this base class. but not to other clients The protected access specified should never be used. D) Programming section. 41. Convert binary 10011l1 to hexadecimal and decimal. Show your work. Page S

If the line: friend class A: appears in class B, and the line: friend class B: appears in class C. then: A) Class A is a friend of class C. B) Class A can access private variable Class B. C) Class C can call class A’s private member functions. D) Class B can access class A’s private variables. The correct function name for overloading the addition (+) operator is: A) operator+ B) operator(+) C) operator: + D) operator_+ Suppose you have a programmer-defined data type Data and want to overload the

Expert Answer

 

Following are the answers for mcq’s

35) – B) Class A can access private variables of class B

36) – A) operator+

37) – A) ostream &operator<<(ostream &output, const Data &dataToPrint)

39) – A) automobile

40) – C) When these members should be available only to derived classes (and friends), not to other clients

41)Programming Section:

The procedure and the calculations to convert the given binary number to decimal and hexadecimal is shown in the image. Code has been explained using comments

CODE:

#include<bits/stdc++.h>

using namespace std;

int main(){

int binary_number,remainder,decimal=0,base=1;

cout<<“Enter binary number”<<endl;

cin >> binary_number;

//Binary to decimal conversion

while(binary_number>0){

remainder = binary_number%10; // Get last digit

decimal=decimal+remainder*base; //multiply last digit with base and add to decimal variable

base = base * 2; // base is initially 1 and is multiplied with 2 in each iteration

binary_number = binary_number/10; //last digit is removed

}//while ends

cout<<“Decimal= “<<decimal<<endl;

//Decimal to hexadecimal conversion

char hexadecimal[100]; //char array to store hex value

int i=0,j;

while(decimal>0){

remainder=decimal%16; //get remainder by dividing decimal by 16

// to convert integer into character

if(remainder<10){

remainder=remainder+48;

}

else{

remainder=remainder+55;

}

hexadecimal[i]=remainder; //store character equivalent

i++;

decimal=decimal/16;

}

cout<<“Hexadecimal =”;

for(j=i;j>=0; j–){

cout<<hexadecimal[j];

}

return 0;

}//main method ends

Output:

Question & Answer: If the line: friend class A: appears in class B, and the line: friend class B: appears in class C. then: A) Cl..... 1

Calculations:

Question & Answer: If the line: friend class A: appears in class B, and the line: friend class B: appears in class C. then: A) Cl..... 2

Still stressed from student homework?
Get quality assistance from academic writers!