2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

Students can Download 2nd PUC Computer Science Chapter 8 Function Overloading Questions and Answers, Notes Pdf, 2nd PUC Computer Science Question Bank with Answers helps you to revise the complete Karnataka State Board Syllabus and to clear all their doubts, score well in final exams.

Karnataka 2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

2nd PUC Computer Science Function Overloading One Mark Questions and Answers

Question 1.
What is meant by function overloading?
Answer:
Function overloading is the process of defining the function with same name to carray out similar types of activities with various data items.

2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

Question 2.
When is function overloading needed?
Answer:
Two or more function have same name, but differ in number of arguments or data type of arguments.

Question 3.
Write an advantage of function overloading.
Answer:
It is easier to understand the flow of information & debug.

Question 4.
Name one condition for overloading of functions.
Answer:
Each functions is the set of overloading functions must have different argument list.

Question 5.
What is an inline functions?
Answer:
A short function consists of function call along with function code.

Question 6.
Write one advantage of inline function.
Answer:
The speed of execution of a program increases.

Question 7.
The inline ifunction is always converted to a code block. True / False.
Answer:
True.

Question 8.
What is a friend function?
Answer:
A friend function is a non – member function that is a friend of a class.

2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

Question 9.
Write an example for friend function declaration.
Answer:
Friend int sum (number n1, number n2);

Question 10.
Write one condition for using a friend function.
Answer:
It cannot access the member variable directly & has to use an object.

Question 11.
Can the keyword friend be used while declaring a friend function?
Answer:
Yes.

Question 12.
Overloading a function means using different names to perform the same operations True / False.
Answer:
False.

2nd PUC Computer Science Function Overloading Two Marks Questions and Answers

Question 1.
What is meant by overloading implements polymorphism?
Answer:
Ploymorphism refers to “one name having many forms, different behavior of an instance of an object depending on situations”. C++ implements polymorphism through function overloading & operator overloading. The function overloading allows the user to create new abstract data types.

2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

Question 2.
Write example for definition & declaration of function overloading.
Answer:
int product (int p, int q, int r);
float product (float x, float y, float z);
int product (int p, int q, int r)
{
cout << “product = ” << p* q* r << endl;
}
float product (float x, float y, float z)
{
cout << ” product = ” << x* y* z << endl;
}

Question 3.
What are the restrictions on overloading functions?
Answer:

  1. Each function in a set of overloaded fucntions must have different argument lists.
  2. If typed is used for naming functions, then the function is not considered as different type.

Question 4.
What are the inline functions? Give an example.
Answer:
A short function consists of function call along with function code.
ex:
inline int square (int a)
{
return (a*a);
}

Question 5.
Write the advantages of inline functions.
Answer:

  1. The inline member functions are compact function calls
  2. Therefore the size of the object code is considerably reduced.
  3. The speed of the execution of a program increases.
  4. Very efficient code can be generated.
  5. The readability of the program increases.

2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

Question 6.
Create an inline function to check if a number is prime or not.
Answer:

# include < iostream.h>
# include < conio.h >
inline void isprime (int a)
{
for (int i = 2; i < a-1; i ++)
{
if (a % i == 0)
{
cout < < "\n The number is not prime " ;
break';
}
}
If (i == a)
cout < < "\n The number is prime";
}
void main ()
{
int num;
clrscr () ;
cout < < "Enter the no to check prime or not ";
is prime (num);
get ch (); ;
}

Question 7.
When are the friend functions are used? write the syntax of declaration of friend functions.
Answer:
Friend functions are used to access the private abd protected members of the class.
ex:
class class – name
public :
friend void function 1 (void);
};

Question 8.
Write any two characteristics of friend functions.
Answer:

  1. A friend function although not a member function, has the full access right to the private & protect members of the classes.
  2. A friend function cannot be called using the object of the class. It can be involved like any normal function
  3. A friend function is declaration by the class that is granting access. The friend declared can be placed anywhere in the class declaration. It is not affected by the access control keywords.

2nd PUC Computer Science Function Overloading Three Marks Questions and Answers

Question 1.
Write any three reasons for function overloading.
Answer:

  1. When different functions are created for different operations, than user has to call respective function depending on the situation.
  2. Code Executed is fast.
  3. It is easier to understand the flow of information and debug.
  4. Code maintenance is easy.
  5. Easier interface between programs & Real world objects.

2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

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

  1. Inline functions are small in size + compact.
  2. Inline function are executed faster than other functions.
  3. Efficient code can be generated.
  4. Readability of the program is increased.

Question 3.
What are the disadvantage of inline functions?
Answer:

  1. The Inline function definition is too long or too complicated.
  2. The Inline function is recursive.
  3. The Inline function has looping constructs.
  4. The Inline function has a switch or goto.

Question 4.
When is it possible that an inline function may not work?
Answer:

  1. The Inline function definition is too long or too complicated.
  2. The Inline function is recursive.
  3. The Inlinr function has looping constructs.
  4. The Inlinr function has a switch or goto.

Question 5.
Write any three characteristics of friend function.
Answer:

  1. A friend function is a non- member function that is a friend of a class.
  2. The friend function is declared within a class with the perfix friend. But it should be defined outside the class like a normal function without the prefix friend.
  3. It an access public members like non – member functions.

2nd PUC Computer Science Function Overloading Five Marks Questions and Answers

Question 1.
Explain the need for function overloading.
Answer:
Function overloading means two or more functions have same namfe, but differ in the number of arguments or data type of arguments. Therefore it is said that (function name) is overloaded. Function overloading therefore a process of defining. Same function neme to carry out similar types of activities with various data items. The advantages of the function overloading are:
1. When different functions are created for different operations (hen user has to call respective functions depending on the situations. Instead for different situations if the same functions are called with different arguments using function overloading, then the compiler automatically decides about the appropriate functions by comparing the arguments types used in the call to the funciton & call to the required function. Thus the code is executed faster.

2. It is easy to understand the flow of information & debug.

3. Code maintanance is easy.

4. Easier interface between programs & real world objects.

2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

Question 2.
Discuss the overloaded functions with syntax & examples.
Answer:
Function overloading is the process of defining the functions with same name to carry out similar types of activities with various data items. Two or more functions have same name, but differ in number of arguments or data type of arguments. It is easier to understand the flow of information & debug. Each functions in the set of overload functions must have different arguments list.
int product (int p, int q, int r);
float product (float x, float y, float z);
int product (int p, int q, int r)
{
cout << ” product = “<< p* q* r << end 1;
}
float product (float x, float y, float z)
{
cout << ” product = “<< x* y* z << end 1 ;
}

Question 3.
Explain the inline functions with syntax & example.
Answer:
A short function consists of function call along with function code & the process is known as expansion.

  1. Inline function definition starts with the keyword, inline.
  2. The inline functions should be defined before all that calls it.
  3. The compiler replaces the function call statement with the function code itself (expansion) then compiles the entire code.
  4. They run little faster then the normal function calling overheads are saved.

Example:

# include < iostream, h>
inline int square (int a)
{
return (a*a) ;
}
int main ()
{
int x, y;
x = square (5);
Cout << " square of 5 = "<< x << end1;
y = square (10);
Cout << " square of 10 = " << y << end1;
return 0 ;
}

2nd PUC Computer Science Question Bank Chapter 8 Function Overloading

Question 4.
Explain the friend functions & their characteristics.
Answer:
A function is a non – member function that is a friend of a class, The friend function is declared inside the class with the prefix friend.

  1. A friend function although not a member function, has the full access right to the private & protect members of the classes.
  2. A friend functions cannot be called using the object of the class. It can be invoked like any normal function.
  3. A friend function is declared by the class that is granting access. The friend declared can be placed anywhere in the class declaration. It is not affected by the access control keywords (public, private based protected)
  4. They are normal external functions that are given special access privileges.
  5. It cannot access the number variable directly & has to use an object- name member – name [Here is membership operator],
  6. The function is declaration with the keyword friend But while defining friend function it does not use either keyword friend or “::” operator.