Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Classify the following functions as injection, surjection or bijection:f : R → R, defined by f(x) = sin2x + cos2x

Answer»

One – One Function: – A function f: A → B is said to be a one – one functions or an injection if different elements of A have different images in B.

So, f: A → B is One – One function

⇔ a≠b

⇒ f(a)≠f(b) for all a, b ∈ A

⇔ f(a) = f(b)

⇒ a = b for all a, b ∈ A

Onto Function: – A function f: A → B is said to be a onto function or surjection if every element of A i.e, if f(A) = B or range of f is the co – domain of f.

So, f: A → B is Surjection iff for each b ∈ B, there exists a ∈ B such that f(a) = b

Bijection Function: – A function f: A → B is said to be a bijection function if it is one – one as well as onto function.

Now, f : R → R, defined by f(x) = sin2x + cos2x

Check for Injectivity and Check for Surjectivity

Let x be element belongs to R i.e x ∈ R such that

So, from definition

⇒ f(x) = sin2x + cos2x

⇒ f(x) = sin2x + cos2x

⇒ f(x) = 1

⇒ f(x) = constant

We know that a constant function is neither One – One function nor onto function.

Thus, It is not Bijective function

52.

Let `f : R->R` be a function defined by `f(x)=(e^(|x|)-e^(-x))/(e^x+e^(-x))` then --(1) f is bijection (2) f is an injection only (3) f is a surjection (4) f is neither injection nor a surjectionA. f is a bijectionB. f is an injection onlyC. f is surjection on onlyD. f is niether an injection nor a surjection

Answer» Correct Answer - D
53.

If f: R → R be the function defined by f(x) = 4x3 + 7, show that f is a bijection.

Answer»

Given as f: R → R is a function defined by f(x) = 4x3 + 7

Injectivity:

Let x and y be any two elements in domain (R), such that f(x) = f(y)

⇒ 4x+ 7 = 4y+ 7

⇒ 4x= 4y3

⇒ x= y3

⇒ x = y

Therefore, f is one-one.

Surjectivity:

Let y be any element in co-domain (R), such that f(x) = y for some element x in R (domain)

f(x) = y

⇒ 4x+ 7 = y

⇒ 4x= y − 7

⇒ x3 = (y – 7)/4

⇒ x = 3√(y - 7)/4 in R

Therefore, for every element in the co-domain, there exists some pre-image in the domain. f is onto.

Since, f is both one-to-one and onto, it is a bijection.

54.

If a funciton `f:[2,oo] to B` defined by `f(x)=x^(2)-4x+5` is a bijection, then B=A. RB. `[1,oo]`C. `[4,oo]`D. `[5,oo]`

Answer» Correct Answer - B
55.

If `f(x) = x^2` then the value of `(f(1.1) - f(1))/(1.1-1)`

Answer» Correct Answer - 2.1
`({(1.1)-f(1)})/((1.1-1))=({(1.1)^(2)-1^(2)})/((1.1-1))=(1.1+1)=2.1`.
56.

If `f(x)=x^(3)`, find the value of `({f(5)-f(1)})/((5-1))`

Answer» Correct Answer - 31
`({f(5)-f(1)})/((5-1))=({(5)^(2)-1^(3)})/(4)=((125-1))/(4)=(124)/(4)=31`.
57.

Let `f={(0,-5),(1-2),(2,1),(3,4),(4,7)}` be a linear function from Z into Z. Write an expression for f.

Answer» Correct Answer - `f(x)=3x-5`
Let `f(x)=ax+b`.
`f(0)=-5impliesaxx0+b=-5impliesb=-5`.
`f(1)=-2impliesaxx1+b=-2impliesa-5=-2impliesa=3`.
58.

Let f = {(0, -5), (1, -2), (3, 4), (4, 7)} be a linear function from Z into Z. Write an expression for f.

Answer»

Given that: f = {(0, -5), (1, -2), (3, 4), (4, 7)} be a function from Z to Z defined by linear function. 

We know that, linear functions are of the form y = mx + b 

Let f(x) = ax + b, for some integers a, b 

Here, (0, -5) ∈ f 

⇒ f(0) = -5 

⇒ a(0) + b = -5 

⇒ b = -5 …(i) 

Similarly, (1, -2) ∈ f 

⇒ f(1) = -2 

⇒ a(1) + b = -2 

⇒ a + b = -2 

⇒ a + (-5) = -2 [from (i)] 

⇒ a = -2 + 5

⇒ a = 3 

∴ f(x) = ax + b 

= 3x + (-5) 

f(x) = 3x – 5

59.

If f (x) = x2 , find the value of \(\frac{(f)(5)-f(1)}{(5-1)}\)

Answer»

Find: \(\frac{f(5)-f(1)}{(5-1)}\)......(i)

Firstly, we find the f(5) 

Putting the value of x = 5 in the given eq., we get 

f(5) = (5)2 

⇒ f(5) = 25 

Similarly, 

f(1) = (1)2 

⇒ f(1) = 1 

Putting the value of f(5) and f(1) in eq. (i), we get

\(\frac{f(5)-f(1)}{(5-1)}\) = \(\frac{25-1}{5-1}\) = \(\frac{24}4\) = 6

Hence, the value of \(\frac{f(5)-f(1)}{(5-1)}\) = 6

60.

If f(x) = x2 , find the value of \(\frac{(f)(1.1)-f(1)}{(1.1)-1}\)

Answer»

Given: f(x) = x2 

Firstly, we find the f(1.1) 

Putting the value of x = 1.1 in the given eq., we get 

f(1.1) = (1.1)

⇒ f(1.1) = 1.21

 Similarly, 

f(1) = (1)2 

⇒ f(1) = 1 

Putting the value of f(1.1) and f(1) in eq. (i), we get

\(\frac{f(1.1)-f(1)}{(1.1-1)}\) = \(\frac{1.21-1}{1.1-1}\) = \(\frac{0.21}{0.1}\) = 2.1

Hence, the value of \(\frac{f(1.1)-f(1)}{(1.1-1)}\) = 2.1

61.

State True/False 1. A local variable exist till the end of the program 2. A global variable destroyed when the sub function terminates

Answer»

1. False 

2. False

62.

Write a note on manipulators.

Answer»

Manipulator functions: Manipulator functions are special stream functions that change certain characteristics of the input and output. They are useful in the formatting of input and output streams.

Following are a few standard manipulators normally used in the stream classes:

1. end1

2. setbase

3. setw

4. setfill

5. setprecision

1. end1:

The end1 is an output manipulator to generate a carriage return or line feed character. The end1 may be used several times in a C++ statement.

For example,

cout<< “ a “ << end1 << “b” << end1;

A program to display a message on two lines using the end1 manipulator and the corresponding output is given below.

2. setbase():

The setbase() manipulator is used to convert the base of one numeric value into another base. Dec, hex, and oct are the common base converters in C++.

3. setw(): 

The setw ( ) stands for the set width. The setw ( ) manipulator is used to specify the minimum number of character positions on the output field a variable will consume. The general format of the setw manipulator function is setw(int w).

4. setfill():

The setfill ( ) manipulator function is used to specify a different character to fill the unused field width of the value. The general syntax of the setfill () manipulator is setfill( char f) which changes the fill character to f. The default fill character is a space.

5. setprccision(): 

The setprecision () is used to control the number of digits of an output stream display of a floating-point value. The general syntax of the setprecision () manipulator is setprecision (int p) which sets the precision for floating-point insertions to p. The default precision is 6.

63.

A variable or a function declared out side of all the functions is have ......... scope.

Answer»

A variable or a function declared out side of all the functions is have global scope.

64.

Explain getline() function with a suitable example.

Answer»

getline() function is used to read the whole line of text that ends with a newline character.

Here getline() function is invoked for reading character input into the variable line. When we type \n, the reading is terminated or size-1 characters are read. The newline is accepted but converted to null character.

# include <iostream>

int main()

{

char city [50];

cout<< “City Name :“;

cin.getline(city, 50);

cout<< “City Name : “<< city << end1;

return 0;

}

65.

Explain scope rules of functions and variables in a C++ program

Answer»

1. Local variable or function: 

A variable or function declared inside a function is called local variable or function. This cannot be accessed by the outside of the function.

Eg. 

main() 

{

int k;//local variable ,

cout<<sum(a,b); // local function

}

2. Global variable or function: 

A variable or function declared out side of a function is called global variable or function. This can be accessed by any statements. 

Eg

int k; // global variable 

int sum(inta, int b); //global function

main()

}

66.

Write down the operation performed by the following statements1. int l=strten(“Computer Program”); 2. charch [] = tolower(“My School”); 3. cout&lt;&lt;(strcmp(“High”, “Low”)&gt;0?toupper(“High”):tolower(“Low”));

Answer»

1. The built in function strlen find the length of the string i.e. 16 and assigns it to the variable I.

2. This is an error because tolower is a character function.

3. This is also an error because tolower and toupper are character functions.

67.

How do two functions exchange data between them? Compare the two methods of data transfer from calling function to called function.

Answer»

There are two methods they are call by value and call by reference 

1. call by value:

In call by value method, a copy of the actual parameters are passed to the formal parameters. If the function makes any change it will not affect the original value.

2. call by reference: 

In call by reference method, the reference of the actual parameters are passed to the formal parameters. If the function makes any change it will affect the original value.

68.

Write a short note on character functions.

Answer»

1. isalpha(): Returns a non-zero value if the argument is a A-Z or a-z letters.

For example, isalpha(‘a’) output: 1 means true isalpha(‘5’) output: 0 means false

2. islower():

Returns a non-zero value if argument is a small case alphabet. For example, islower(‘a’) output: 1 islower(‘A’) output: 0

3. isupper():

it is a character function that returns a non-zero value if argument is an upper case alphabet. For example, isupper(‘a’) output: 0 isupper(‘A’) output: 1

4. tolower( ):

It converts the capital alphabet character to lower case. For example, tolower(‘A’) output: a

5. toupper( ):

It converts the lower case alphabet character to upper case. For example, toupper(‘a’) output: A

69.

Name the two types of character functions.

Answer»

Character functions are classified as

1. Classification functions and

2. Conversion functions

70.

Supplying data to a function from the called function by using ........

Answer»

parameters (arguments).

71.

One among the following function prototypes is wrongly written. Identify it. Also given reason. (a) oat test (oat); (b) oat test (oat, int); (c) test (oat); (d) int test (int);

Answer»

(c) test(oat); 

Here the prototype contains no return type.

72.

Explain any five functions of header.

Answer»

1. a cos() function:

It is a mathematical function that returns the arc cosine value for the given argument. The argument value must be in the range -1 to 1, otherwise, a domain error is triggered. 

Syntax : float acos ( float arg);

2. cos() function:

It is a mathematical function that returns the cosine Value for the given radians.

Syntax: float cos( float arg );

3. ceil() function:

It is a mathematical function that returns the smallest integer value that is not less than the specified number. In other words, it returns the Round-Up value of a given number.

Syntax: float ceil( float num);

4. exp() function:

It is a mathematical function that returns the natural logarithm base “e” raised to the power equal to the argument.

Syntax: float exp( float num);

5. sqrt() function: It is a mathematical function that returns the square root of the given “num” value.

Syntax: float sqrt( float num);

73.

Give the difference between classification function and conversion function.

Answer»

1. Classification function:

name begins with the prefix is, and is used to determine the type of character.

2. Conversion function:

name begins with the prefix to and is used to determine the type of character.

74.

After the execution of a function, it is returned back to the main function by executing ....... keyword.

Answer»

After the execution of a function, it is returned back to the main function by executing return keyword.

75.

Give the usage of any two functions that generate pseudo-random numbers.

Answer»

int rand (void);

Returns a pseudo-random integral number in the range between 0 and RAND_MAX.

void srand (unsigned int seed);

The pseudo-random number generator is initialized using the argument passed as seed.

76.

Give the usage of isalpha().

Answer»

It returns a non-zero value if the argument is a A-Z or a-z letters. Otherwise it neutrons a zero.

For example, isalpha(‘a’) output: true-neutrons 1

isalpha(‘5’) output: false- neutrons 0.

77.

Write a C++ program to find the sum of first ‘N’ natural numbers using a user defined function.

Answer»

# include<iostream> 

using namespace std; 

int sum(int n)

{

int i,sum=0;

for(i=1;i<=n;i++)

sum+=i;

return sum;

}

int main()

{

int n;

cout<<"Enter the number of numbers to find the sum:";

cin>>n;

cout<<"The sum of first "<<n<<" natural numbers is:<< sum(n);

}

78.

Compare islower() and isupper() character functions with examples.

Answer»

islower(‘a’) output: true islower(‘A’) output: false

isupper(‘a’) output: false isupper(‘A’) output: false

79.

Give the usage of strcat() function with an example.

Answer»

Strcat() character function is used to combine two strings. The syntax is strcat(target_string, source_string);

80.

One of the following is not involved in the creation and usage of a user defined function (a) Dene a function (b) Declare a function (c) invoke a function (d) None of these

Answer»

(d) None of these

81.

The big programs are divided into smaller programs. This smaller programs are called .........

Answer»

The big programs are divided into smaller programs. This smaller programs are called Functions.

82.

…………. is the name of the function.(a) Pre – defined(b) Built – in(c) Library(d) All the above

Answer»

(d) All the above

83.

What are the different outputs generated by strcmp() function?

Answer»

The strcmp() function generates any one of the following outputs. Zero if both the strings are the same,

1. Positive integer if the first string is greater than the second string.

2. Negative integer if the first string is lesser than the second string.

84.

Compare strcmp() and strcmpi().

Answer»

strcmp(“PUC”, “PUC”) output: negative integer. – This is case sensitive and compare two strings.

Strcmpi(“PUC”, “PUC”) output: 0 (zero). – This is not case sensitive and strings

85.

The execution of the program begins at ....... function.

Answer»

main function.

86.

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()

87.

What are importance of void data type? void type has two important purposes:

Answer»

1. To indicate the function does not return a value.

2. To declare a generic pointer.

88.

Which function begins the program execution?(a) isalpha() (b) isdigit()(c) main()(d) islower()

Answer»

Answer is (c) main()

89.

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.

90.

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 same name.

An example using Scope Resolution Operator.

91.

Explain scope of variable with example.

Answer»

Scope refers to the accessibility of a variable. 

There are four types of scopes in C++

1. Local Scope

2. Function Scope

3. File Scope

4. Class Scope

1. 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:

 int main( )

{

int a,b; //Local variable

}

2. Function Scope:

  • The scope of variable within a function is extended to the function block and all sub-blocks therein. 
  • The lifetime of a function scope variable is the lifetime of the function block.

Example:

int. sum(intx, int y); //x and y has function scope.

3. File Scope:

  • A variable declared above all blocks and functions (including main()) has the scope of a file.
  • The lifetime of a file scope variable is the lifetime of a program.
  • The file scope variable is also called as global variable.

Example:

#include

using namespace std;

int x,y; //x and y are global variable

void main()

{

……..

4. Class Scope:

  • Data members declared in a class has the class scope.
  • Data members declared in a class can be accessed by all member functions of the class.

Example:

Class example

{

int x,y; //x and y can be accessed by

print() and void():

void print();

Void total();

};

92.

Given data: Principal amount Rs. 50000Number of years 5Rate of interest 7To 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

93.

Explain about generating random numbers with suitable program.

Answer»

The srand() function in C++ seeds the pseudo random number generator used by the rand() function. The seed for rand() function is 1 by default. It means that if no srand() is called before rand(), the rand() function behaves as if it was seeded with srand( 1). The srand() function takes an unsigned integer as its parameter which is used as seed by the rand() function. It is defined inor header file.

#include

#include using namespace std; int main()

{

int random = rand(); /* No srand() calls

before rand(), so seed = 1*/

cout << “\nSeed = 1, Random number = ” << random;

srand(10);

/* Seed= 10 */

random = rand();

cout << “\n\n Seed =10, Random number = ” << random;

return 0;

}

Output:

Seed = 1, Random number = 41

Seed =10, Random number 71

94.

Which of the following is the scope operator?(a) &gt;(b) &amp;(c) %(d) ::

Answer»

:: is the scope operator

95.

Write a program to illustrate “Pass by refe-rence vs value”

Answer»

#!/usr/bin/python # Function definition is here 

def changeme(mylist): “This changes a passed list into this function” 

mylist.append([l,2,3,4]); 

print “Values inside the function: “, mylist 

return # Now you can call changeme 

function mylist=[10,20,30]; 

changeme(mylist); 

print “Values outside the function: “, mylist 

It produce following result: 

Values inside the function: [10, 20,30, [1,2,3,4]] Values outside the function: [10,20, 30, [1,2,3,4]]

96.

Explain log(x) in Python with example.

Answer»

Description : The method log( ) returns natural logarithm of x, for x > 0. 

Syntax : Following is the syntax for log() method 

import math 

math.log(x) 

Note: This function is not accessible directly so we need to import math module and then we need to call this function using math static object. 

Parameters : x — This is a numeric expression. 

Return Value: This method returns natural logarithm of x, for x > 0. 

Example: The following example shows the usage of log() method.

# !/usr/bin/python 

import math # This will import 

math module 

print “math.log(100.12): ” , 

math.log(100.12) 

print “math.log(100.72): “, 

math.log(100.72) 

print “math.log(119L):”, 

math.log(119L) 

print “math.log(math.pi):”, 

math.log(math.pi)

This will produce the following result:

math.log(100.12):4.60636946656

math.log(100.72):4.61234438974

math.log(119L):4.77912349311

math.log(math.pi): 1.14472988585

97.

Explain pow(x, y) in python with example.

Answer»

Description : The method pow() returns returns the value of x to the power of y.

Syntax: Following is the syntax for pow() method import math math.pow(x,y) 

Note : This function is not accessible directly so we need to import math module and then we need to call this function using math static object. 

Parameters : x—This is a numeric expression, y—This is also a numeric expression.

Return Value : This method returns value of x to the power of y. 

Example: The following example shows the usage of pow() method.

# !/usr/bin/python 

import math # This will import math module

 print “math.pow(100, 2): “, 

math.pow(100,2) 

print “math.pow(100,-2): “, 

math.pow(100,-2) 

print “math.pow(2,4): “, 

math.pow(2,4) 

print “math.pow(3, 0): “, 

math.pow(3,0)

This will produce the following result:

math.pow(100, 2) :10000.0

math.pow(100,-2): O.OOOl 

math.pow(2, 4): 16.0 math.pow(3,0): 1.0

98.

The C++ program always have main() function to begin the program execution.(a) 1 (b) 2 (c) 3 (d) null

Answer»

Answer is (a) 1

99.

Write short note on pow() function in C++.

Answer»

The pow() function returns base raised to the power of 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

100.

What is function scope?

Answer»

Function Scope:

1. The scope of variables declared within a function is extended to the function block, and all sub – blocks therein.

2. The life time of a function scope variable, is the life time of the function block. The scope of.