0% found this document useful (0 votes)
29 views4 pages

CLASS X User Defined Methods Worksheet

The document is a worksheet for Class X focusing on user-defined methods in programming. It includes various tasks such as differentiating concepts, writing function prototypes, defining classes with specific attributes and methods, and answering multiple-choice questions related to programming principles. Additionally, it covers assertions and their explanations, as well as practical coding exercises for students to implement.

Uploaded by

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

CLASS X User Defined Methods Worksheet

The document is a worksheet for Class X focusing on user-defined methods in programming. It includes various tasks such as differentiating concepts, writing function prototypes, defining classes with specific attributes and methods, and answering multiple-choice questions related to programming principles. Additionally, it covers assertions and their explanations, as well as practical coding exercises for students to implement.

Uploaded by

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

CLASS X: WORKSHEET FOR USER DEFINED METHOD

1. Differentiate between:
a. Call by value and Call by Reference
b. Actual parameter and Formal Parameter
c. Pure function and Impure Function
d. public,private and protected access specifier
e. class variable and instance variable
f. static and non static function
2. Write the prototype of a function check which takes an integer as an argument 2018
and returns a character.
3. A function PosChar which takes a String argument and a character argument and 2016
returns an integer value.
4. 2016
Define a class ParkingLot with following description:
Instance variables/data members
int vno : To store the vehicle number
int hours : To store the number of hours the vehicle is parked in the parking lot
double bill : To store the bill amount

Member Methods
void input(): To input and store vno and hours.
void calculate(): To compute the parking charge at the rate of Rs 3 for the first hour
or part thereof, and Rs 1.50 for each additional hour or part thereof.
void display(): To display the detail

Write the main() to create object and call above functions

5. Define a class to overload the method display as follows: SPECIMEN 2024


void display( ): To print the following format using nested loop
1
12
123
1234
12345
void display(int n): To print the square root of each digit of the given number.

6. Define a class called with the following specifications: SPECIMEN 2024


Class name: Eshop
Member variables:
String name: name of the item purchased
double price: Price of the item purchased
Member methods:
void accept(): Accept the name and the price of the item using the methods of
Scanner class.
void calculate(): To calculate the net amount to be paid by a customer, based on the
following criteria:
Price Discount
1000 – 25000 5.0%

25001 – 57000 7.5 %

57001 – 100000 10.0%


More than 100000 15.0 %
void display(): To display the name of the item and the net amount to be paid.
Write the main method to create an object and call the above methods.
7. Write the function prototype of a public function of class Sample by observing the
given code:
Sample obj=new Sample();
boolean x=obj.func(34,”XYZ”);
8. Define a class to overload the method display() as follows: SPECIMEN 2025
void display(): To print the following format using nested loop.
12121
12121
12121
void display(int n, int m): To print the quotient of the division of m and n if m is
greater than n otherwise print the sum of twice n and thrice m.
double display(double a, double b, double c): to print the value of z where z = p × q
p = (a + b) / c
q=a+b+c

9. Assertion: A constructor cannot be overloaded.


Reason: A constructor can be overloaded, just like methods, to provide multiple
ways to initialize objects.

(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct
explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct
explanation of Assertion (A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true
10. Assertion: A user-defined method can be called multiple times.
Reason: A user-defined method can be called multiple times from different parts of
the program.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct
explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct
explanation of Assertion (A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true
11. Assertion: A user-defined method can access private data members.
Reason: A user-defined method can access private data members of the same class.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct
explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct
explanation of Assertion (A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true
12. Define a class named movieMagic with the following description: 2023
Data Members Purpose

int year To store the year of release of a movie

String title To store the title of the movie

To store the popularity rating of the movie


float rating
(minimum rating=0.0 and maximum rating=5.0)

Member Methods Purpose

movieMagic() Default constructor to initialize numeric data members to 0 and String data member to

void accept() To input and store year, title and rating

void display() To display the title of the movie and a message based on the rating as per the table giv
Ratings Table
Rating Message to be displayed

0.0 to 2.0 Flop

2.1 to 3.4 Semi-Hit

3.5 to 4.4 Hit

4.5 to 5.0 Super-Hit


Write a main method to create an object of the class and call the above member
methods.

13. Define a class with the following specifications: SPECIMEN 2025


Class name: Bank
Member variables:
double p – stores the principal amount
double n – stores the time period in years
double r – stores the rate of interest
double a – stores the amount
Member methods:
void accept() – input values for p and n using Scanner class methods only.
void calculate() – calculate the amount based on the following conditions:
Time in (Years) Rate %

Up to 1/2 9

> 1/2 to 1 year 10

> 1 to 3 years 11

12

> 3 years

void display() – displays the details in the given format:


Principal Time Rate Amount
xxx xxx xxx xxx
Write the main() method to create an object and call the above methods.

14. Consider the following class : 2014


class myClass{
static int x=3,y=4;
int a=2,b=3;}
i) Name the variables for which each object of the class will have its own
distinct copy.
ii) Name the variables which are common to all objects.
15. Which keyword is used that a function does not return any value?
a.Void b.void c.no_value d. VOID
16. is the first line of a function.
a.function definition b.blueprint c.start d.function prototype
17. keyword creates class variables.
a.static b.class c.final d.none of these
18. Multiple Choice Questions

1. What is the purpose of a constructor in a class?


a) To declare variables
b) To define methods
c) To initialize objects
d) To inherit properties

2. What is the difference between a static function and an instance function?


a) Static function belongs to the class, instance function belongs to the object
b) Static function belongs to the object, instance function belongs to the class
c) Static function is called automatically, instance function is called explicitly
d) Static function is used for inheritance, instance function is used for polymorphism

3. Can a constructor be declared as static?


a) Yes
b) No
c) Only for primitive data types
d) Only for reference data types

4. What is the purpose of the "return" statement in a function?


a) To exit the function
b) To return a value from loop
c) To call another function
d) To declare a variable

You might also like