Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Students can Download Computer Science Chapter 11 Functions Questions and Answers, Notes Pdf, Samacheer Kalvi 11th Computer Science Book Solutions Guide Pdf helps you to revise the complete Tamilnadu State Board New Syllabus and score more marks in your examinations.

Tamilnadu Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Samacheer Kalvi 11th Computer Science Functions Text Book Back Questions and Answers

PART – 1
I. Choose The Correct Answer

Question 1.
Which of the following header file defines the standard I/O predefined functions?
(a) stdio.h
(b) math.h
(c) string.h
(d) ctype.h
Answer:
(a) stdio.h

Question 2.
Which function is used to check whether a character is alphanumeric or not?
(a) isalpha()
(b) isdigit()
(c) isalnum()
(d) islower()
Answer:
(c) isalnum()

Question 3.
Which function begins the program execution?
(a) isalpha()
(b) isdigit()
(c) main()
(d) islower()
Answer:
(c) main()

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 4.
Which of the following function is with a return value and without any argument?
(a) x = display(int, int)
(b) x = display()
(c) y = display(float)
(d) display(int)
Answer:
(b) x = display()

Question 5.
Which is return data type of the function prototype of add(int, int);?
(a) int
(b) float
(c) char
(d) double
Answer:
(a) int

Question 6.
Which of the following is the scope operator?
(a) >
(b) &
(c) %
(d) ::
Answer:
(d) ::

PART – 2
II. Answer to all the questions

Question 1.
Define Functions.
Answer:
A large program can typically be split into smaller sized blocks called as functions.
Functions can be classified into Pre-defined or Built-in or Library Functions and User-defined Functions.

Question 2.
Write about strlen() function.
Answer:
The strlen() takes a null-terminated byte string source as its argument and returns its length. The length does not include the null(\0) character.

Question 3.
What are the importance of void data type?
Answer:
void type has two important purposes:

  1. To indicate the function does not return a value
  2. To declare a generic pointer.

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 4.
What are Parameter and list its types?
Answer:
Arguments or parameters are the means to pass values from the calling function to the called function. The variables used in the function definition as parameters are known as formal parameters. The constants, variables, or expressions used in the function call are known as actual parameters.
Types: Default arguments and Constant Arguments.

Question 5.
Write a note on Local Scope.
Answer:

  1. A local variable is defined within a block.A block of code begins and ends with curly braces { }.
  2. The scope of a local variable is the block in which it is defined.
  3. A local variable cannot be accessed from outside the block of its declaration.
  4. A local variable is created upon entry into its block and destroyed upon exit.

PART – 3
III. Answer to all the questions

Question 1.
What is Built-in functions?
Answer:
C++ provides a rich collection of functions ready to be used for various tasks. The tasks to be performed by each of these are already written, debugged and compiled, their definitions alone are grouped and stored in files called header files. Such ready – to – use subprograms are called predefined functions or built-in functions.

Question 2.
What is the difference between isupper() and toupper() functions?
Answer:
isupper( )
This function is used to check the given character is uppercase. This function will return 1 if true otherwise 0. For the following examples value 1 will be assigned to n and 0 for m.
int n=isupper(‘A’);
int m=isupper(‘a’);

toupper( )
This function is used to convert the given character into its uppercase. This function will return the upper case equivalent of the given character. If the given character itself is in upper case, the output will be the same.
The following statement will assign the character constant ‘K’ to the variable c.

char c = toupper(‘k’);
But, the output of the statement given below will be ‘B’ itself.
cout <<toupper(‘B’);

Question 3.
Write about strcmp() function.
Answer:
The strcmp() function takes two arguments: string1 and string2. It compares the contents of string1 and string2 lexicographically.
The strcmp() function returns a:

  1. Positive value if the first differing character in string1 is greater than the corresponding character in string2. (ASCII values are compared)
  2. Negative value if the first differing character in string1 is less than the corresponding character in string2.
  3. 0 if string1 and string2 are equal.

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 4.
Write short note on pow() function in C++.
Answer:
The pow() function returns base raised to the power of the exponent. If any argument passed to pow() is long double, the return type is promoted to long double. If not, the return type is double. The pow() function takes two arguments:

  1. base – the base value
  2. exponent – exponent of the base

Example:
cout << pow(5, 2);

Output:
25

Question 5.
What are the information the prototype provides to the compiler?
Answer:
The function prototype provides details about the return data type, name of the function and a list of formal parameters or arguments.

Consider the following function prototype:
long fact (int, double);

The prototype above provides the following information to the compiler:

  • The return value of the function is of type long.
  • fact is the name of the function.
  • The function is called with two arguments:
  • The first argument is of int data type.
  • The second argument is of double data type.

Question 6.
What is default arguments? Give example.
Answer:
In C++, one can assign default values to the formal parameters of a function prototype. The Default arguments allow omitting some arguments when calling the function.
1. For any missing arguments, compiler uses the values in default arguments for the called function.

2. The default value is given in the form of variable initialization.
Example : void defaultvalue(int n1 = 10, n2 = 100);

3. The default arguments facilitate the function call statement with partial or no arguments.
Example :

  1. defaultvalue (x, y);
  2. defaultvalue (200, 150);
  3. defaultvalue (150);
  4. defaultvalue (x, 150);

4. The default values can be included in the function prototype from right to left, i.e., we cannot have a default value for an argument in between the argument list.
Example:

  1. void defaultvalue (int n1=10, n2);//invalid prototype.
  2. void defaultvalue (int n1, n2 = 10);//valid prototype.

PART – 4
IV. Answers to all the questions

Question 1.
Explain Call by value method with suitable example.
Answer:
This method copies the value of an actual parameter into the formal parameter of the function. In this case, changes made to formal parameter within the function will have no effect on the actual parameter.
Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions
Output:
Example : Function call by value
Enter the Value for A : 5
The Value inside display function (a * a) : 25
The Value inside main function 5

Question 2.
What is Recursion? Write a program to find GCD using recursion.
Answer:
A function that calls itself is known as recursive function. And, this technique is known as recursion.
Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions
Output:
Enter two numbers: 81 153
gcd : 9

Question 3.
What are the different forms of function return? Explain with example.
Answer:
The return statement:
Returning from the function is done by using the return statement. The return statement stops execution and returns to the calling function. When a return statement is executed, the function is terminated immediately at that point. The return statement is used to return from a function. It is categorized as a jump statement because it terminates the execution of the function and transfer the control to the called statement.
Syntax:
return expression/variable;

Example : retum(a + b); retum(a);
return; // to terminate the function

The Returning values:
The functions that return no value is declared as void. The data type of a function is treated as int, if no data type is explicitly mentioned. For example,
For Example:
int add (int, int);
add (int, int);
In both prototypes, the return value is int, because by default the return value of a function in C++ is of type int.

Returning Non – integer values:
A string can also be returned to a calling statement.
Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions
Output:
Example: Function with Non-Integer Return Chennai

The Returning by reference:
#include
using namespace std;
int main( )
{

int n 1 = 150;
int &n 1 ref = n1;
cout << “\nThe Value of N1 = “<< n1 << “and n 1 Reference =”<< n 1 ref;
n 1 ref++;
cout << “\n After nl increased the Value of N1 =”<< n1;
cout << “and n 1 Reference = ”<< n 1 ref;
retum(0);

}
Output:
The Value of N1 = 150 and nl Reference =150
After n1 increased the Value of N1 = 151 and n1 Reference =151

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 4.
Explain scope of variable with example.
Answer:
A scope is a region or life of the variable. Scope refers to the accessibility of a variable. There are four types of scopes in C++. They are Local scope, Function scope, File scope and Class scope.

Local Scope:
A local variable is defined within a block. A block of code begins and ends with curly braces { }.
The scope of a local variable is the block in which it is defined.
A local variable cannot be accessed from outside the block of its declaration.
A local variable is created upon entry into its block and destroyed upon exit.

Example:
if (a > b)
{
int temp; //local to this if block//
temp = a;
a = b;
b = temp;
}

Function Scope:
The scope of variables declared within a function is extended to the function block, and all sub-blocks therein.
The life time of a function scope variable, is the life time of the function block. The scope of formal parameters is function scope.

Example:
void add(int x, int y)
{
int m=x+y; //’m’ declared within function add()// cout<<“\nThe Sum = “<<m;
}

File Scope:
A variable declared above all blocks and functions (including main ()) has the scope of a file. The life time of a file scope variable is the lifetime of a program.
The file scope variable is also called a global variable.

Example:
int file_var=20; //Declared within File// void add(int x, int y)
{
int m=x+y+file_var;
cout<<“\n The Sum = “<<m;
}

Question 5.
Write a program to accept any integer number and reverse it.
Answer:
Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions
Output:
Enter number : 1 2 3
Reverse number: 3 2 1

Samacheer Kalvi 11th Computer Science Functions Additional Questions and Answers

PART – 1
I. Choose the correct answer

Question 1.
A large program can be split into small sub-programs called……………
a) Arrays
b) Functions
c) Structures
d) Unions
Answer:
b) Functions

Question 2.
………………. is used to check whether the given character is an alphabet or not.
(a) isalnum()
(b) isalpha()
(c) isalph()
(d) isal()
Answer:
(b) isalpha()

Question 3.
The functions which are available by default known as …………….. functions.
a) Built-in
b) User-defined
c) Either A or B
d) None of these
Answer:
a) Built-in

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 4.
………………. takes a null-terminated byte string source as its argument and returns its length.
(a) strcpy()
(b) strlen()
(c) strcmp()
(d) strcat()
Answer:
(b) strlen()

Question 5.
Functions created by users is called ………………. functions.
a) Built-in
b) User-defined
c) Either A or B
d) None of these
Answer:
b) User-defined

Question 6.
………………. is the name of the function.
(a) fact
(b) task
(c) arguments
(d) None of these
Answer:
(d) none of these

Question 7.
Complicated programs can be divided into manageable subprograms called functions using ………………
a) Divide and conquer
b) Reusability of code
c) Both A and B
d) All the above
Answer:
a) Divide and conquer

Question 8.
Arguments are also called……………….
(a) variable
(b) constant
(c) function
(d) parameters
Answer:
(d) parameters

Question 9.
……………… provide function prototype and definitions for library functions.
a) Header files
b) Pre-processor directive
c) Structures
d) None of these
Answer:
a) Header files

Question 10.
Inline functions execute faster but require more ……………….
(a) variables
(b) pointers
(c) memory
(d) functions
Answer:
(c) memory

Question 11.
………….. function will return 1 if the given character is an alphabet, and 0 otherwise 0.
a) isalnum( )
b) isalpha( )
c) isdigit( )
d) None of these
Answer:
b) isalpha( )

Question 12.
………… function is used to check whether a given character is a digit or not.
a) isalnum( )
b) isalpha( )
c) isdigit( )
d) None of these
Answer:
c) isdigit( )

Question 13.
……………. function will return 1 if the given character is a digit, and 0 otherwise.
a) isalnum( )
b) isalpha( )
c) isdigit( )
d) None of these
Answer:
c) isdigit( )

Question 14.
………………. function is used to check whether a character is in lower case (small letter) or not.
a) islower( )
b) tolower( )
c) Both A and B
d) None of these
Answer:
a) islower( )

Question 15.
……………. functions will return a non-zero value if the given character is a lower case alphabet, and 0 otherwise.
a) islower( )
b) tolower( )
c) toupper( )
d) isupper( )
Answer:
a) islower( )

Question 16.
……………. function is used to check the given character is uppercase.
a) islower( )
b) tolower( )
c) toupper( )
d) isupper( )
Answer:
d) isupper( )

Question 17.
……………. function will return 1 if the given character is an uppercase alphabet otherwise 0.
a) islower( )
b) tolower( )
c) toupper( )
d) isupper( )
Answer:
d) isupper( )

Question 18.
………….. functions can be used to reduce the overheads like STACKS for small function definition.
a) Inline
b) Built-in
c) User-defined
d) None of these
Answer:
a) Inline

Question 19.
……………. reduces the speed of program execution.
a) Array
b) Stacks
c) Structures
d) Unions
Answer:
b) Stacks

Question 20.
What is the return type of the following function prototype? double add (int, int);
a) float
b) void
c) double
d) int
Answer:
c) double

Question 21.
What is the return type of the following function prototype?
char *display();
a) float
b) string
c) double
d) char
Answer:
b) string

Question 22.
A function that calls itself is known as ………….. function.
a) recursive
b) nested
c) invariant
d) variant
Answer:
a) recursive

Question 23.
A function that calls itself using …………. technique.
a) recursive
b) variant
c) invariant
d) recursion
Answer:
d) recursion

Question 24.
………………. is mandatory when a function is defined after the main() function.
a) Function prototype
b) Function parameters
c) Return statement
d) None of these
Answer:
a) Function prototype

Question 25.
Scope refers to the accessibility of a ……………..
a) Function
b) Class
c) Variable
d) Constant
Answer:
c) Variable

PART – 2
II. Very Short Answers

Question 1.
What is a user-defined function and built-in function?
Answer:

  • Built-in functions – Functions which are available in the C++ language standard library.
  • User-defined functions – Functions created by users.

Question 2.
What are user-defined functions?
Answer:
C++ also provides the facility to create new functions for a specific task as per user requirements. The name of the task and data required (arguments) are decided by the user and hence they are known as User-defined functions.

Question 3.
Write a note on divide and conquer.
Answer:
Divide and Conquer:

  • Complicated programs can be divided into manageable subprograms called functions.
  • A programmer can focus on developing, debugging, and testing individual functions.
  • Many programmers can work on different functions simultaneously.

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 4.
What are the advantages of inline functions?
Answer:
Advantages of inline functions:

  1. Inline functions execute faster but require more memory space.
  2. Reduce the complexity of using STACKS.

Question 5.
What is the classification of a function?
Answer:
Functions can be classified into two types,

  • Pre-defined or Built-in or Library Functions
  • User-defined Function.

Question 6.
What is the purpose of strupr( ) and strlwr( ) functions?
Answer:

  • The strupr( ) function is used to convert the given string into Uppercase letters.
  • The strlwr( ) function is used to convert the given string into Lowercase letters.

PART – 3
III. Short Answers

Question 1.
WrIte about lsalnum( ) function with suitable example .
Answer:
Isalnum( )
This function ¡s used to check whether a character is alphanumeric or not.
Syntax:
int isainum (char c)
This function returns a non-zero value if c is a digit or a letter, else it returns 0.

Example:
int r = isalnum’5′);
cout << isalnum’A’) <<‘\t'<<r;
The statements given below assign 0 to the variable n, since the given character is neither an alphabet nor a digit,
char c =‘$‘;
int n = isalnum(c);
cout<<c;
Output
0
PROGRAM
#include <iostream>
#include <stdio.h>
#include <ctype.h>
using namespace std;
int main()
{
char ch;
int r;
cout<<“\n Type a Character :”;
ch = getcharQ;
r = isalnum(ch);
cout<<“\nThe Return Value of isalnum(ch) is :”<<r,
}
Output-1:
Type a Character :A
The Return Value of isa1num(ch) is
Output – 2:
Type a Character 😕
The Return Value of isa1num(ch) is :0

Question 2.
Define library functions.
Answer:
C++ provides a rich collection of functions ready to be used for various tasks. The tasks to be performed by each of these are already written, debugged, and compiled, their definitions alone are grouped and stored in files called header files. Such ready-to-use subprograms are called predefined functions or built-in functions or Library Functions.

Question 3.
Write about tolower( ) function.
Answer:
tolower( )
This function is used to convert the given character into its lowercase. This function will return the lower case equivalent of the given character. If the given character itself is in lower case, the output will be the same.

Syntax:
char tolower(char c);

The following statement will assign the character constant ‘k’ to the variable c.
char c = tolower(‘K’);
The output of the statement given below will be ‘b’ itself.
cout <<tolower(‘b’);

Question 4.
Write a program using pow() and sin() function.
Answer:
The pow() function returns base raised to the power of the exponent. The sin() function takes a single argument in radians.
#include
#include using namespace std;
int main ()
{

double base, exponent, result;
base = 5;
exponent = 4;
result = pow(base, exponent);
cout << “pow(“ << base << “A” << exponent <<”) =” << result;
double x = 25;
result = sin(x);
cout << “\nsin(“<< x <<”)=”<<result;
return 0;

}
Output:
pow (5^4) = 625
sin (25) = – 0.132352

Question 5.
How will you append (concatenate) strings?
Answer:
strcat( ) function appends a copy of the character string pointed by the source to the end of the string pointed by the target. The strcat( ) function takes two arguments: target and source.
Example:
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
char target[50] = “Learning C++ is fun”;
char source[50] = ” , easy and Very useful”;
strcat(target, source);
cout << target;
return 0;
}
Output
Learning C++ is fun, easy, and Very useful.

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 6.
What is scope resolution operation?
Answer:

  1. The scope operator reveals the hidden scope of a variable. The scope resolution operator (::) is used for the following purposes.
  2. To access a Global variable when there is a Local variable with the same name. An example using Scope Resolution Operator.

PART – 4
IV. Explain in Detail

Question 1.
Explain user-defined function with an example.
Answer:
User-defined functions are created by the user. A function can optionally define input parameters that enable callers to pass arguments into the function. A function can also optionally return a value as output. Functions are useful for encapsulating common operations in a single reusable block, ideally with a name that clearly describes what the function does.

Function Definition:
In C++, a function must be defined before it is used anywhere in the program. The general syntax of a function definition is:
Return_Data_Type Function_name (parameter list)
{
Body of the function
}

  • The Return_Data_Type is any valid data type of C++.
  • The Function_name is a user-defined identifier.
  • The parameter list, which is optional, is a list of parameters, i.e. a list of variables preceded by data types and separated by commas.
  • The body of the function comprises C++ statements that are required to perform the intended task of this function.

Question 2.
Explain about Inline functions with a suitable program.
Answer:
An inline function looks like a normal function in the source file but inserts the function’s code directly into the calling program. To make a function inline, one has to insert the keyword inline in the function header.
Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions
Output:
Enter the Principle Amount Rs. :60000
Enter the Number of Years: 10
Enter the Rate of Interest: 5
The Simple Interest = Rs. 30000

Question 3.
Write about the function prototype.
Answer:
C++ program can contain any number of functions. But, it must always have only one main() function to begin the program execution. We can write the definitions of functions in any order as we wish. We can define the main() function first and all other functions after that or we can define all the needed functions prior to main(). Like a variable declaration, a function must be declared before it is used in the program. The declaration statement may be given outside the main() function
Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions
The prototype above provides the following information to the compiler:

  1. The return value of the function is of type long.
  2. Fact is the name of the function.
  3. The function is called with two arguments:
    • The first argument is of the int data type.
    • The second argument is of double data type, int display(int, int)//function prototype//

The above function prototype provides details about the return data type, the name of the function, and a list of formal parameters or arguments.

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 4.
Explain call by reference with an example.
Answer:
Call by reference or address method:
This method copies the address of the actual argument into the formal parameter. Since the address of the argument is passed, any change made in the formal parameter will be reflected back in the actual parameter.

PROGRAM:
#include <iostream>
using namespace std;
void display(int &x) //passing address of a//
{
x=x*x;
cout<<“\n\nThe Value inside display function (n1 x n1) :”< }
int main( )
{
intn1;
cout<<“\nEnter the Value for N1 cin>>n1;
cout<<“\nThe Value of N1 is inside main function Before passing : “<< n1; display(n1);
cout<<“\nThe Value of N1 is inside main function After passing (n1 x n1) : “<< n1; return(O);
}
Output:
Enter the Value for N1:45
The Value of N1 is inside main function Before passing: 45
The Value inside display function (n1 x n1) :2025
The Value of N1 is inside main function After passing (n1 x n1): 2025

The & symbol in the declaration of the parameter x means that the argument is a reference variable and hence the function will be called by passing reference. Hence when the argument num1 is passed to the display( ) function, the variable x gets the address of num1 so that the location will be shared.

In other words, the variables x and num1 refer to the same memory location. We use the name num1 in the main() function, and the name x in the display() function to refer to the same storage location. So, when we change the value of x, we are actually changing the value of num1.

Samacheer Kalvi 11th Computer Science Solutions Chapter 11 Functions

Question 5.
Given data: Principal amount Rs. 50000

Number of years 5
Rate of interest 7

To find the simple interest of the above-mentioned given data. Write a C++ program using inline functions.
Answer:
#include
using namespace std;
inline float simple interest(float p1, float n 1, float r 1)
{

float sil=(pl*nl*rl)/100;
retum(sil);

}
int main ()
{

float si,p,n,r;
cout << “\n Enter the Principle Amount Rs. :”; cin >> p;
cout << “\n Enter the Number of Years :”; cin >> n;
cout << “\n Enter the Rate of Interest :”; cin >> r;
si = simple interest(p, n, r);
cout << “\n The Simple Interest = Rs.” << si;
return 0;

}

Output:
Enter the Principle Amount Rs. 50000
Enter the Number of Years: 5
Enter the Rate of Interest: 7
The Simple Interest = Rs. 17500