Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 211 - 213 of 354

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

Question 211

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is a USECASE? Why it is needed?

Explanation

  • Use cases provide sequence of actions of system that yield an observable result.
  • Used in system analysis to identify, clarify, and categorize system requirements.
  • Use case maps interactions between systems and users within an environment related to a particular goal.
  • Use case contain all significant system activities within a given system.
Given the Image is the Use Case

Question 212

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Explain one method to process and entire string as one unit?

Explanation

  • ‘gets’ allows entering the entire string

Following is the declaration for gets () function.

char ⚹ gets (char ⚹ str)

  • Str: The pointer to an array of chars where the C string is stored.
  • The function returns str on success, and NULL on error. NULL is also retuned on reaching “end of file” and no characters have been read.

Question 213

C & C Plus Plus
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: