Computer Project Questions Gr 10_AY 22_23

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

COMPUTER PROJECT – AY 22-23

Question 1:
For Loop Pattern Program using switch-case
Write a program to generate a pattern of numbers in the form of a triangle or in the form of an
inverted triangle depending upon User’s choice. For an incorrect choice, an appropriate error
message should be displayed.

Sample Input: Enter your choice 1 Enter your choice 2

1 A A A A A
2 3 C C C C
4 5 6 E E E
7 8 9 10 G G
I
Question 2:

For Loop Series program

Write a program to calculate and print the sum of each of the following series within one
class:

𝑎 𝑎4 𝑎7 𝑎10
(i) S1 = 2! - + - + ………..upto n terms
4! 6! 8!

(ii) S2 = 0+1+1+2+3+5+8+……...up to m terms

Question 3:

Number Programs (Special Number & Harshad Number )

Write a menu driven program to accept a number from the user and check whether it is a
Special number or a Harshad number.

a) A number is said to be a special number, if the sum of the factorial of each digits of the
number is same as the original number. Eg.1! + 4! + 5! = 1 + 24 + 120 = 145

1
b) A Harshad number is an integer that is divisible by the sum of its digits.

Eg.171

Sum of digits = 1 + 7 + 1 =9

171 is divisible by 9

Question 4:

Function (FruitJuice – using Instance variable)

Define a class named FruitJuice with the following description:

Instance variables/data members:

int productCode: stores the product code number.

String flavour: stores the flavour of the juice (e.g. orange, apple, etc.).

String packType: stores the type of packaging (e.g. tetra-pack, PET bottle, etc.).

int packSize: stores package size (e.g. 200, 400, etc.).

int productPrice: stores the price of the product.

Member functions:

(i) void input(): to input and store the productCode, flavour, packType, packSize and
productPrice.

(ii) void discount(): to reduce the product price by 10%.

(iii) void display(): to display the productCode, flavour, packType, packSize and productPrice.

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

Question 5:

Function (Parcel)

Define a class parcel having the following functions:

int calculate(int w1) : To calculate and return the service charge for the

2
transportation of any parcel according to the

following criteria:

Up to 100 gms : Rs.40

For each additional 50 gms or part thereof : Rs.20

[ For Example: If wt. of the parcel = 180 gms.

For 100 gms. = Rs.40

For next 50 gms. = Rs.20

For remaining 30 gms. = Rs.20 ]

void display(int w2, String name2) : Invoke the calculate(int) to display the

total amount to be paid by the person as given

below:

Name Weight of the parcel Charge

……… ……….. ……….

Write a main method to create an object par of the class and call the required method.

Eg : Sample Input : Wt. of the parcel = 180 gms.

Sample Output: Total Charge = Rs.80

Question 6:

Nested functions (Sum of factorial of even digits)


Create a class EvenFact having following details:
Data Member
n : long type
Member methods
void input( ) : Accept the value of ‘n’.
long factorial(long f) : to return the factorial of a given number

3
long evenDigit() : to find the sum of the factorial of even digits of a given
number and return the value.
Write a main method to call the above required function and print the value.
Sample Input: 754921
(4!+2!)
Sample Output : 26

Question 7:

Function Overloading - 1

Create the following overloaded functions and write a main method to call the functions
based on the user’s choice:

(i) int volume (int side) – to find and return volume of cube using (side*side*side)

(ii) double volume(double l, double b, double h) – to find and return volume of cuboid using
(length*breadth*height)

(iii) double volume(double r,double h) – to find and return volume of cylinder using (𝜋𝑟 2 ℎ)

Question 8:

Function Overloading - 2

Design a class to overload a function num_cal() as follows:

(i) void num_cal(int num, char ch) with one integer argument and one character argument. It
computes the square of an integer if choice ch is ‘s’ or ‘S’ else computes its cube.

(ii) void num_cal(int a, int b, char ch) with two integer arguments and one character
argument. It computes the product of integer arguments if ch is ‘p’ or ‘P’ else adds the
integers.

(iii) void num_cal(String str1, String str2) with two String arguments prints whether the two
strings are equal or not.

Write a main method to call all the above functions.

4
Question 9:

Constructor (Finding the roots of a quadratic equation)


Write a program in java to find the roots of a quadratic equation ax2 +bx+c =0 with the
following specifications:
Class Name : Quad
Data Members: float a,b,c,d (a,b,c are the co-efficient and d is the
discriminant), r1 and r2 are the roots of the equation.
Member methods:
Quad(float x, float y, float z) : to initialize a with x, b with y, c with z and d with 0
void calculate() : Find d = b2 – 4ac
if d<0 then print “Roots not possible” otherwise find the roots and print.
r1= (-b+ √𝑑)/2a and r2= (-b-√𝑑)/2a)

Question 10:

String and Character functions - 1


Write a program in Java to input two strings of same length and form a new word in such a
way that, the first character of the first word is followed by the first character of the second
word and so on. If the strings are not of same length, then print the message “Invalid Input”.

Sample Input: String 1: BALL

String 2: WORD

Output: BWAOLRLD

Question 11:

String and Character functions - 2


Write a program to assign a full path and file name as given below. Using library functions,
extract and display the file path, file name and file extension separately as shown.
Sample Input: C:\Users\admin\pictures\flower.jpg

5
Output path: C:\Users\admin\pictures\
File name : flower
Extension: jpg

Question 12:

String and Character functions - 3


Write a program to accept a String in uppercase and replace all the vowels with ‘@’ present
in the String.

Sample Input : “TATA STEEL IS IN JAMSHEDPUR”


Output: T@T@ ST@@L @S @N J@MSH@DP@R

Question 13:

String and Character functions - 4


Write a program to accept a word in lower case and display the new word after removing all
the repeated letters.

Sample Input: applications

Output: aplictons

Question 14:

Finding the count of Palindrome words

Write a program to declare an array to accept and store five words. Display the number of
palindrome words.

Sample Input: MADAM

TEACH

RACECAR

6
EXAM

MALAYALAM

Sample Output: Number of palindrome words : 3

Question 15:

Bubble sort

Write a program in Java to input five city names in an array. Using bubble sort arrange them
in descending order and display the same.
Sample input: AGRA
MUMBAI
CHENNAI
DELHI
PUNE
Sample output:
PUNE
MUMBAI
DELHI
CHENNAI
AGRA

Question 16:

Sum of array elements

Write a program to create two separate arrays A and B. Accept 6 numbers for each array A
and B. Find Sum1 and Sum2 as follows and print Sum1 and Sum2:

Sum1=Elements in odd subscript of array A + Elements in even subscript of B.


Sum2= Elements in odd subscript of array B + Elements in even subscript of A.

7
Question 17:

Linear Search - 1
Write a program to initialize an array of 10 names and initialize another array with their
respective telephone numbers. Using linear search technique, search for a name given by
the user in the list. If found, display “Search successful” and print the name along with the
telephone number, otherwise display “Search Unsuccessful. Name not enlisted”.

Question 18:

Linear Search - 2
Write a program to accept name and monthly salary of 5 employees and store them in two
separate arrays. Display the names of the employees who earn more than Rs.50000 per
month, using linear search.

Question 19:

Binary Search - 1

Write a program to input 5 numbers in an array in ascending order. Take another input num,
search it in the array using binary search technique and print the position of the num if
found in the array, otherwise print the message “Element not found”.

Question 20:

Binary Search – 2

Write a program to initialize the String array name[ ] with the values {“Vijay”, ”Subha”, “Ria”,
”Hari”, “Anita”}. Accept a name of the student from the user. Using the binary search
technique, find whether the name is present in the given list of elements or not. If the name is
present, then print “Name is found in the index __” else print the message “Name is not
found in the list “. (Note: Elements are arranged in descending order).

********

You might also like