FOP Assignment U 4 To U 6
FOP Assignment U 4 To U 6
24. State whether the following initialization of an array is valid or invalid with proper
reason.
A)float item[3][2]={0,1,2,3,4,5};
B)int m[3,5]={1,2,3,4,5};
1. Write a C++ or Java program to find the maximum and minimum number among three
numbers using a function.
2. Write a C++ or Java program to check whether a number is prime or not using a
function.
3. Write a C++ or Java program to calculate the factorial of a number using a function.
4. Enlist the elements of the user defined function. Explain each element of the function
in detail.
5. List out the categories of function. Explain each of them with examples.
6. Explain a function category with argument and without return type with an example.
7. Explain a function category with no argument and without return type with an example.
8. Explain a function category with argument and with return type with an example.
9. Explain a function category with no argument and with return type with an example.
10. What is recursion? Explain with an appropriate example.
11. What do you understand by method? Explain method creation with multiple parameters
by giving a proper example.
12. Write a C++ or JAVA function namely InArray() that takes in an integer array, No of
elements in array and search value and it returns the number of times search value is
stored in the array.
13. What do you understand by method? Write any two advantages to use methods. Explain
method creation with a single parameter by giving a proper example.
14. Write a C++ or JAVA function namely MaxValIndex() that takes in an integer array,
No of elements in an array and it returns the index number that has maximum value in
the array.
15. Write a C++ or JAVA program that uses the user defined function Swap() to
interchange the value of two variables.
16. Explain the three elements of the function.
17. Write a program using a function that computes X^Y for integer x and y and returns
double type value.
18. How many maximum and minimum values can function return?
19. Write any two rules for defining function name.
20. Write a prototype of function "Display" that accepting an integer array as argument and
returns float value.
21. Find out error in following function given below.
void total(int value1, value2, value3)
{
return value1 + value2 + value3;
}
}
23. What will be the output of the following code?
#include<iostream>
using namespace std;
void addprint()
{
int s = 1;
s++;
cout << s;
}
int main()
{
addprint();
addprint();
addprint();
return 0;
}
Unit 6
1. Write a C++ or JAVA program create a PlayerScore calss which having two properties
namely runs and no of balls and following methods:
void setscore(int r, int b) - it sets the values of object properties.
int isfifty() - it return true if score is between 50 to 99 otherwise false.
int iscentury() - it return true if score is more than equal to 100 otherwise false.
float strickrate() - it returns the strick rates (run * 100 / noofballs).
void display()-it display player details with status of fifties, century and strickrate.
Write a main() to demonstrate the class methods functionality.
2. What do you mean by class and object? How to create an object?
3. Explain different types of access specifiers.
4. Create a C++ or JAVA class namely employee which contains three members like
emp_id, emp_name, and total yearly income and following methods.
void input() - it accepts employee details from user.
float totaltax() - it calculate the tax and return it based on the following criteria.
Amount Tax Percentage on total Yearly income
Less than 500000 10 %
>=500000 20 %
void display() - it display employee details with tax.
Write a main() to demonstrate the class methods functionality.
5. How to call class instance methods through object? Give an appropriate example.
6. Define a class Banksystem which contains following:
7. Data Members:
− Name of account holder
− Account Number
− Balance
Member Functions:
- To get details of the account
− To display the balance
− To search account by account number
Write C++ program for aboveBanksystem that handles five customers.
8. Define a class Student which contains following:
Data Members:
− Name of student
− Enrollment number of student
− Contact number of student
Member Functions:
− To get details of the student
− To display details of the student