3i Infotech Placement: Sample Questions 797 - 798 of 1245

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 797

Question

MCQ▾

I went to Lucky Duck Casino and in the first game I lost one-third of my money, in the second game I lost half of the rest. If I still have ₹ 1,000. How much money did I have when I arrived at the Casino?

Choices

Choice (4)

a.

₹ 1,000

b.

₹ 3,000

c.

₹ 6,000

d.

₹ 2,000

Answer

b.

Explanation

In the first game I lost one third of total money.

In the second game I lost half of the rest.

After second game I am having 1000 ₹

Let the total money I was having in the beginning be ₹ x.

So,

So, I was having ₹ 3000 in the beginning when I arrived at the casino.

Question 798

Edit

Describe in Detail

Essay▾

Find the output of the following program

  1. #include<iostream>classfig2d
  2. {
  3.     intdim1;
  4.     intdim2;
  5.     public:fig2d()
  6.     {
  7.         dim1=5;
  8.         dim2=6;
  9.     }
  10.     virtualvoidoperator≪(ostream & rhs);
  11. };
  12. voidfig2d::operator≪(ostream &rhs)
  13. {
  14.     rhs ≪dim1" "dim2" ";
  15. }
  16. voidmain()
  17. {
  18.     fig2dobj1; obj1 ≪ cout;
  19. }

Explanation

  • In the program
Table Showing the Program
  1. classfig2d
  2. {
  3.     intdim1;
  4.     intdim2;
  5.     public:fig2d()
  6.     {
  7.         dim1=5;
  8.         dim2=6;
  9.     }
  10.     virtualvoidoperator ≪ (ostream & rhs);
  11. };
  • Define the class fig2d
  • Define the integer variable dim1 and dim2.
fig2d () function assigns the value of dim1 = 5 and dim2 = 6The << operator is overloaded with ostream as arguments.
  1. voidfig2d::operator ≪ (ostream &rhs)
  2. {
  3.     rhs ≪ dim1 ≪ ” “ ≪ dim2 ≪ ” “;
  4. }
print the value of dim1 and dim2
  1. voidfig2d::operator ≪ (ostream &rhs)
  2. {
  3.     rhs ≪ dim1 ≪ ” “ ≪ dim2 ≪ ” “;
  4. }
  • This enables the ‘cout’ to be present at the right-hand-side.
  • Normally, ‘cout’ is implemented as global function, but it doesn՚t mean that ‘cout’ cannot be overloaded as member function.
  • Overloading ≪ as virtual member function is handy when the class in which it is overloaded is inherited, and this becomes available to be overriden.
  • This is as opposed to global friend functions, where friends are not inherited.

Developed by: