Friday, May 20, 2016

Basic puzzle questions in C/C++ :: MUST KNOWN concepts to every programmers :: SET-3

Q1.
string str;
int ii; double dd;
cin>>ii;
cout<<ii+i<<endl;
cin>>dd;
cout<<dd+d<<endl;
getline(cin,str);
cout<<str<<endl;


Q2.
double d=4;
cout<<d<<endl;

Q3.
double d=4;
cout<<setprecision(1)<<fixed<<d<<endl;

Q4.
Which one is suitable syntax for function template?
a. template< class T> return_type Function_Name(parameters)
b. template< typename T> return_type Function_Name(parameters)
c. both and b
d. None of these

Q5.
In CPP, the size of the character array should be one larger than the number of characters in the string.
a. True
b. False

Q6.
A class can contain objects of other classes and this phenomenon is called__________
a. Relationship
b. Object Association
c. Containership
d. None of these

-----------------------------------------------------------------------------------------------------------------
Answers:::
1)
It will take input in str. We need to use cin.ignore();
cin.ignore();  ----cin.ignore() is used to ignore previous cin values. string takes \n(new line) as input.
Correct program:-
string str;
int ii; double dd;
cin>>ii;
cout<<ii+i<<endl;
cin>>dd;
cout<<dd+d<<endl;
cin.ignore();
getline(cin,str);
cout<<str<<endl;

2)
O/P-  4

3)
O/P-  4.0

4)
Answer:: c (both a and b)

5)
Answer:: a ::True
void main()
{ char name[5] = “INDIA”; //This is invalid and cause error
  char x_name[6]=”INDIA” // This is valid, one extra byte required for \0 character
}

6)
Answer:: Containership


No comments:

Post a Comment