Kerala Plus One Computer Science Chapter Wise Previous Questions Chapter 9 String Handling and I/O Functions
Question 1.
……….. function is used to copy a string to another variable. (Say – 2016)
Answer:
b) strcpy( );
Question 2.
a) Write the declaration statement for a variable ‘name’ in C++ to store a string of maximum length 30. (Say – 2016)
b) Differentiate between the statement cin»name and gets (name) for reading data to the variable ‘name’.
Answer:
a) char name[31];(One for null(\0) character).
OR
cin>> does not allows space. It will take characters up to the space and characters after space will be truncated . Here space is the delimiter.
Considerthe following code snippet that will take the input upto the space.
#include<iostream> using namespace std; int main() { char name[20]; cout<<“Enter your name:”; cin»name; cout<<“Hello “<<name; }
If you input a name “Alvis Emerin” then the output will be Hello Alvis. The string after space is truncated.
b) gets( ) function is used to get a string from the key board including spaces.
Considerthe following code snippet that will take the input including the space.
#include<iostream> #include<cstdio> using namespace std; int main() { char name[20]; cout<<“Enter your name:”; gets(name); cout<<“Hello “<<name; }
If you input a name “Alvis Emerin” then the output will be Hello Alvis Emerin.
Question 3.
My_name is a variable contains a string. Write two different C++ statements to display the string. (Say – 2016)
Answer:
1) cout<<my_name;
2) puts(my_name);
Question 4.
Suggest most suitable built-in function in C++ to perform the following tasks : (March – 2016)
a) To find the answer for 53
b) To find the number of characters in the string “KERALA”“HAPPY NEW YEAR”
c) To get back the number 10 if the argument is 100
Answer:
a) pow (5,3);
b) strlen (“KERALA”)
c) tolower(‘M’)
d) sqrt (100);