CBSE Coding Class 8 Solution – Functions in Depth
CBSE Coding Class 8 Solution Student Handbook Chapter 3 Functions in Depth all Questions and Answers Solution by Coding Teacher. Net Ex. Here provided all Coding Solution for Class 8.
(1) How does the use of functions help in programming?
Answer: Reduces the repetition of the same set of statements many times.
Reason: A function reduces duplication of code and increases the chances that the set of steps can easily reused again and again in the program.
(2) Functions cannot return a value?
Answer: False
Reason: Functions do return a value whenever it is get called.
Standard Questions
(1) What are functions in programming?
Answer: A function is a block of statement that performs a specific task. We can use same set of statements every time we want to perform the task .The programmer will give this action a simple name. Giving a simple name to a function, increases the chances that the set of steps can easily talked about and reused again and again in the program.
(2) What are the benefits of using functions? Answer: Benefits of using functions –
A.) Functions helps us improve the reusability of the code. Same function can be used in any other program.
B.) Functions helps us improve the readability of the code.
C.) Functions reduces the size of the code.
D.) Errors could be easily traced by using functions.
(3) Is it possible to return a value from function? If yes, how?
Answer: Yes, a function can give an output or return a value. That makes a function more useful. The usefulness of using a function in a program comes to use when an operation performed inside a function gives back a value, which can be used later in the program to generate results.
Example : To calculate the square and cube of a number using a functions, and then add the results generated from the function and print them.
square_of_number(input1)
{
result1 = input1 * input1
return Result
}
cube_of_number(input2)
{
result2 = input2* input2*input2
return result
}
val1 = square_of_number(2)
val2 = cube_of_number(3)
val3 = val1 + val2
Print(“sum of both the functions is” ,val3)
(4) What are function parameters?
Answer: Function parameters are variables which are taken as inputs to the function to do a task when the function is called. Function parameters are used to import arguments into functions. They are the names that present in the function definition where real values is being passed to the function..
For example: We need to calculate the volume of a cube, we need three variables length, breadth and height. The formula to calculate the volume of a cube is length*Breadth*height. We can make a function named VolumeOfCuboid which takes parameters L, B and H.
Now the function would look like
Volume Of Cuboid (L, B, H)
{
return L * B * H
}
Higher Order Thinking Skills(HOTS)
(1) Define a function to calculate the cube of a number. The function should take a number as argument and return the cube of that number.
Answer:
(2) Define a function to calculate volume of a sphere. The function should take radius of the sphere as argument. Use the function for calculating cube of a number to calculate the volume of the sphere. The function should return the calculated volume. Call the function to get the volume of a sphere.
Answer:
(3) Define a function to calculate the simple interest of an amount. The function should take the amount, the rate of interest and the time duration as arguments. The function should return the calculated simple interest.
Answer:
Applied Project
(1) Problem Statement: A branch manager of a reputed bank wants you to develop a software to calculate the simple interest. Create a program on Minecraft to calculate the simple interest using functions. Let the Principle amount = 100000 Time =2 years Rate =5 %.
Answer: