Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views8 pages

Functions

The document outlines a series of programming tasks involving the definition of functions and classes in a programming language. Each task specifies the creation of functions for mathematical operations, geometric calculations, and number properties, as well as the definition of classes for various entities like Student, Employee, and Electric Bill. The tasks include input/output operations and calculations, demonstrating fundamental programming concepts such as functions, classes, constructors, and method overloading.

Uploaded by

nitubinodsingh09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Functions

The document outlines a series of programming tasks involving the definition of functions and classes in a programming language. Each task specifies the creation of functions for mathematical operations, geometric calculations, and number properties, as well as the definition of classes for various entities like Student, Employee, and Electric Bill. The tasks include input/output operations and calculations, demonstrating fundamental programming concepts such as functions, classes, constructors, and method overloading.

Uploaded by

nitubinodsingh09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

FUNCTIONS

1. Define functions.
void add (int a, int b): to find and print sum of two numbers.
void product (int a, int b): to find and print product of two numbers.
Now in main(): input two numbers, find their sum and product using above defined functions.
2. Define functions.
void area(int l ,int b): to find and print area of rectangle
void perimeter (int l, Int b): to find and print perimeter of rectangle.
Now in main ( ): input length and breadth, find area and perimeter using above defined functions.
3. Define functions.
void area (int r): to find and print area of circle
void circum(int r): to find and print circumference of circle
Now in main(): input radius of a circle, find its area and circumference using above functions.
4. Define functions.
void checkprime (int x): to check and print is x a prime number or not?
Now in main(): input a number and check is it prime or not using above functions.
5. Define functions.
void volume (int l, int b,int h): to calculate and print volume.
void diagonal(int l,int b,int h): to calculate and print diagonal.
Now in main(): input length, breadth, height. Calculate and print its volume using above functions.
6. Define functions.
void checkPalindrome (int x): to check and print is x a palindrome number or not.
Now in main (): input a number and check is it palindrome or not using above function.
7. Define functions.
void checkspecial (int n): to check n is a special number or not?
(Special number : sum of factorial of digits = number)
Now in main(): input a number and check it is special number or not using above functions.
8. Define functions.
void checkSpy (int n): to check n is a spy number or not ?
(Spy number: when sum of digits = product of digits)
Now in main(): input a number and check is it a spy number or not using above functions.
9. Define functions.
int area (int I, int b): to find and return area of a rectangle.
int perimeter (int l, int b): to find and return perimeter of a rectangle.
Now in main(): input length, breadth from user. Find area and perimeter using above functions also print
their difference.
10. Define functions.
int sumFactor (int n) : to find and return sum of factors of n.(Perfect number: sum of factors = number)
Now in main (): to find its sum of factors using above functions and check is it perfect number or not.
11. Define functions:
int sumDigit (int a):to find and return sum of digits of n.(Niven number: number divisible by sum of
digits)
Now in main: input a number and find its sum of digits using above functions and check is it Niven
number or not?
12. Define function:
int countFactor (int n): to count and return number of factors of n.
Now in main(): print all two-digit prime numbers using above function.
13. Define function.
int countFactor (int n): to count and return number of factors of n.(Twin prime: A pair of prime numbers
with difference of two)
Now in main (): input two numbers and check they are twin prime or not ?To count factor use above
defined function.
14. Define functions.
int countFactor (int n): to count and return number of factors of n.
int reverse (int n): to find and return reverse of n.(Palprime number: when a number is prime as well as
palindrome)
Now in main() : input a number from user and check is it palprime or not?
15. Define functions.
int countDigit (int n): to count and return number of digits of n.(Automorphic number: When square
number contains the original number itself as its last digits)
Now in main (): input a number from user and check is it automorphic number or not? To count number
of digits using above functions.
16. Define overloaded functions area ().
void area (int r): to find and print area of a circle.
void area (int l, int b): to find and print area of rectangle.
Now in main(): input r, l, b find area of circle and rectangle.
17. Define overloaded function series ()
void series (int n): to print
1 4 9.....n terms
void series (int x, int n): to print table of x upto n terms.
Now in main (): use above functions to get the result.
18. Define overloaded function sumseries ( ):
void sumseries (int n): to find and print sum of
s = 1+2+3…..n terms
void sumseries (int x, int n): to find and print sum of
s = x+x2+x3+…n terms
Now in main ( ): print the above series.
19. Define overloaded function pattern ( ):
void pattern (int n):
when n=4
1 2 3 4 5
2 3 4 5
3 4 5
4
void pattern ( ):
1 2 3 4
5 6 7
8 9
10
20. Define overloaded function :
void pattern( char ch, int n):
when ch=# & n=4
1 2 3 4
# # #
1 2
#
void pattern(int n):
when n=3
* * *
* *
*
Use it main( )
21. Define overloaded function:
double perform (double r, double h): to calculate and return the value of CSA of cone
CSA= π rl
l= √ r 2 +h2
void perform (int r, int c): Use nested loop to generate the following format
when r=3, c=5,
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
void perform (int m, int n, char ch): to print the quotient of the division of m and n if ch is Q else print
the remainder of the division of m and n if ch is R.
22. Define overloaded function :
void print( ): to print the following format
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
void print (int n): to check whether the number is a lead number or not.
(Lead number – sum of even digits = sum of odd digits)
23. define overloaded function :
void number (int num, int d): to count and display the frequency of a digit in a number.
eg: num = 2565685
d=5
frequency of digit 5 = 3
void number (int n): to find and display the sum of even digits of a number.
Write main ( ).
24. Define overloaded function:
void sumseries (int n, double x): to find and display the sum of the given series
x x x
s= − + ….n
1 2 3
void sumseries ( ):to find and display the sum of given series.
s = 1+(1*2)+(1*2*3)+……..+(1*2*….*20)
25. Define overloaded function:
void display ( ): to print using method loop
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
void display (int n): to print square root of each digit of given number
eg: n = 43
o/p :
1.732050808
2.0
26. Define function:
Boolean isPerfectsquare (int n): to check given number is perfect square or not ?
Now in main ( ): Input ten values from users find the sum of perfect square using above function.
27. Define overloaded function:
double volume (double r): with radius ( r ) as argument , returns the volume of sphere using the formula
4
∗22
V= 3
∗r 3
7
double volume (double h, double r): with height(h), radius (r) as arguments, and returns volume of
cylinder using
22 2
V = ∗r ∗h
7
double volume (double l, double b, double h): with length(l), breadth(b) sand height(h) as arguments,
returns the volume of a cuboids using
V = l*b*h
28. WAP to consider the following prototype :
boolean even (int n): which checks whether the given number is even or not.
Now in main( ): input a number and check and print.
29. Create a method with the following prototype :
int fact (int n): which finds the factorial of a number and returns it.
Now in main ( ): call function and print value.
30. WAP to create a method with the following prototype:
int reverse (int n): which reverses the given number.
Now in main ( ): input a number and check whether reverse number is same as original number.Use
above functions.
31. Define overloaded function :
1 2 3
double series (int n): + + … .n terms
2 3 4
1 3 5
x x x
double series (int x, int n): + + … . n terms
2 4 6
Now in main( ): input values and call the above functions.
32. Define overloaded function:
void pattern (int n): which prints the following pattern
when n=5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
void pattern (char ch, int m, int n): which prints the following pattern
when ch=@
m=4
n=3
@@@@
@@@@
CLASS
33. Define class: Student
Data member: roll, name, marks
Member methods:
void input ( ): to accept roll, name and marks
void output ( ): to print roll, name and marks
Now in main ( ): input details of a student and print the same on screen using above class and methods.

34. Define class: Employee


Data member:
empno: to store Employee number
name: to store Employee name
basic: to store basic salary
gross: to store gross salary
Member methods:
void indata ( ): to input empno, name, and basic
void calc ( ): to calculate Gross salary
gross=basic+hra+da
hra=40%of basic
da=60%of basic
void show ( ): to print empno, name, and gross salary.
Now in main ( ): make an object of class and call methods to perform required operation.

35. Define class: Rectangle


Data members: len, bre, area, perimeter
Member methods:
void input ( ): to accept len, bre
void calculate ( ): to find area and perimeter of rectangle
void display ( ): to print area and perimeter
Now in main ( ): make an object of the class and call methods to get area and perimeter

36. Define class: Elecricbill


Data members:
String n: name of customer
int units: number of units consumed
double bill: amount to be paid
Member methods:
void accept ( ): to accept name of customer, number of units consumed
void calculate ( ):to calculate bill as per
Number of unit Rate per unit
first 100 units Rs 2.00
next 200 units Rs 3.00
above 300 units Rs 5.00
A surcharge of 2.5% charged if the number of units consumed is above 300.
void print ( ): name, number of units consumed, bill amount.
Now in main ( ): call above methods.
37. Define class: Mobike
Data members:
int bno: to store bike number
int phno: to store phone number
String name: to store name
int days: to store number of days for which bike have been taken on rent
int charge: to find and store the charge to be paid
Member methods:
void input ( ): to accept details of a customer.
void compute ( ): to compute charge of taking bike on rent. Charge is as follows:
First five days-Rs 500/day
Next five days-Rs 400/day
Next five days-RS 200/day
void display ( ): to display details in given format
Bike number Phone number Name Number of days Charge
----- ----- ---- ------ ----
Now in main ( ): create an object of Mobike class and call member methods to print charge
CONSTRUCTOR
38. Define class: Library
Data members:
int acc_no
String title
String author
int late: to store number of days late
int fine: to sore the fine amount
Member methods:
Library ( ): to initialize data members by their default value
void input: to input acc_no, title, author, number of days late
void compute ( ): calculate and store the fine charged at the rate 2 per day
void display ( ): to display the details in the following format
Accession number Title Author Fine
Write in main ( ): To make an object of above class class and call the member methods.

39. Define class: movieMagic


Data members:
int year: to store year of release of movie
String title: to store title of the movie
double rating: to store the popularity rating of the movie.
(Minimum rating=0.0, maximum rating=5.0)
Member methods:
movieMagic ( ): Default constructor to initialize data members
void accept ( ): to input and store year, title, and rating.
void display ( ): to display title of movie and a message based on the rating table below
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi - Hit
3.5 to 4.5 Hit
4.6 to 5.0 Super - Hit
Now in main ( ): Create an object and call above member methods.

40. Define class: FruitJuice


Data members:
int product _code
String flavor
String pack_type
int pack_size
int product_price
Member methods:
FruitJuice ( ): to initialize data members
void input ( ): to input and store the product code, flavor, pack type, pack size and product prize.
void discount ( ): to reduce product prize by 10.
void display ( ): to display the product code, flavor, pack type, pack size and product prize.
Now in main ( ): Call above defined functions.

41. Define class: Wage


Data members:
name: to store name
wages: to store daily wages
overtime: to store overtime amount
salary: to store monthly salary
hrs: to store total number of hours worked
Member methods:
Wage (…): parameterized constructor to initialize name, wages, hrs and assign 0.0 to overtime, salary.
void calc ( ): to calculate overtime and salary.
salary = wage*30+overtime
overtime = hrs*500
void output ( ): to print name and salary
Now in main ( ): input name, wages and hrs and make object of class then call methods of class to find
and print salary.

42. Define class: StuResult


Data members: roll, name, phy, chem, bio, min (minimum marks to pass), avg.
Member methods:
StuResult (…): to initialize roll, name and marks of phy, chem, bio.
void calc ( ): to calculate avg
void result ( ): to print result pass/fail as avg is greater than or equal to passing marks. Passing marks is
stored in min.
Now in main ( ): input roll, name, marks of three subjects from user make object of above e class and
print the result by calling appropriate functions.

You might also like