0% found this document useful (0 votes)
2 views25 pages

Gr10 - Program Sheets

The document outlines a series of programming tasks that involve various algorithms and class structures in a programming language. Each program has specific requirements, such as calculating roots of quadratic equations, checking for special numbers, and managing rental charges for bikes. The tasks also include data manipulation, sorting, and user input handling across multiple scenarios.
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)
2 views25 pages

Gr10 - Program Sheets

The document outlines a series of programming tasks that involve various algorithms and class structures in a programming language. Each program has specific requirements, such as calculating roots of quadratic equations, checking for special numbers, and managing rental charges for bikes. The tasks also include data manipulation, sorting, and user input handling across multiple scenarios.
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

PROGRAM 1:

Write a program to input the values of a, b, c to determine the nature of the roots of
a quadratic equation and also calculate the values of the two roots.

Hint:

The standard form of a quadratic equation is ax2+bx+c=0

The nature of roots is given by the discriminant D,

Where D = b2-4ac

If D> 0 means Roots are real and unequal

If D=0 means Roots are real and equal

If D<0 means Roots are imaginary


−𝑏+√𝑏2 −4𝑎𝑐 −𝑏+√𝑑
R1 = 𝑥 = or 𝑥 =
2𝑎 2𝑎

−𝑏−√𝑏2 −4𝑎𝑐 −𝑏−√𝑑


R2= 𝑥 = or 𝑥 =
2𝑎 2𝑎

Sample Input:

Enter the co-efficients: 1 2 1

Sample Output:

Roots are equal

First Root: -1 Second Root: -1

Sample Input:

Enter the co-efficients: 2 -3 1

Sample Output:

Roots are positive and different

First Root: 1 Second Root: 0.5

Sample Input:

Enter the co-efficients: 2 -2 1

Sample Output:

Roots are imaginary


PROGRAM 2:

Write a program with the following specification

a) void niven_no() - to check whether the entered number is a Harshad number (or
Niven number) or not.

Hint: A number is said to be Harshad number (or Niven number), when a


given number is divisible by the sum of its digits.

Example:

Number = 171

Sum of digits = 1 + 7 + 1 =9

171 is divisible by 9

b) void duck_no(int) - to check whether the entered number is a Duck number or


not,

Hint: A number is said to be a duck number, if the number contains a 0 in it.

1798 is not a duck number

5071 is a duck number

c) boolean special_no() – to check whether the entered number is a special number


or not.

Hint:

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

Example:

Number = 145

1! + 4! + 5! = 1 + 24 + 120 = 145

d) int Armstrong_no(int) - to check whether a given number is an Armstrong number


using do-while statement

Hint: Armstrong number is a number that is equal to the sum of cubes of its
digits.

153 = 13 + 53+ 33 = 1 + 125 +27 = 153


PROGRAM 3:

Define a class called 'Mobike' with the following specifications:

Data Members Purpose

int bno To store the bike number

int phno To store the phone number of the customer

String name To store the name of the customer

int days To store the number of days the bike is taken on rent

int charge To calculate and store the rental charge

Member Methods Purpose

void input() To input and store the details of the customer

void compute() To compute the rental charge

void display() To display the details in the given format

The rent for a mobike is charged on the following basis:

Days Charge

For first five days ₹50.0 per day

For next five days ₹40.0 per day

Rest of the days ₹20.0 per day

Output:

Bike No. Phone No. Name No. of days Charge

xxxxxxx xxxxxxxx xxxx xxx xxxxxx


PROGRAM 4:

Write a program to find the answer for given series using function overloading
1 2 3 n
a. void find(int n) - To calculate S = + + ….+
2 3 4 𝑛+1
𝑥 𝑥2 𝑥3 𝑥𝑛
b. void find(int x, int n) - To calculate S = 1 + + + + ⋯+
2! 3! 4! (𝑛+1)!

Write a main method to create an object of the class and call the above method.
PROGRAM 5:

Write a program using function over loading based on the specification given below.

Class name:

Pattern

Member methods:

void print() - To print rightangled triangle

12

123

1234

12345

void print(int n) – To print inverted triangle

1 2 3 4 5

6 7 8 9

10 11 12

13 14

15

void print(String s) - String Pattern

BL

BLU

BLUE

BLUEJ

Write a main method to create object and invoke all the member methods
depending upon User’s choice. For an incorrect choice, an appropriate error message
should be displayed (Use if...else ladder for choice selection) and display the result.
PROGRAM 6:

Write a program to design a class overloading and a method display as follows:

void display(String str, int p) with one string argument and one integer argument. it
displays all the uppercase characters if 'p' is 1 otherwise, it displays all the lowercase
letters.

void display(String str, char ch) with one string argument and one character
argument. it displays all the vowels characters if 'ch' is 'v' otherwise, it displays all the
alphabets.

Write a main method to create object and invoke all the member methods and
display the result.
PROGRAM 7:

Define a class named MovieMagic with the following description:

Instance variables/data members:

int year - to store the year of release of a movie

String title - to store the title of the movie.

float rating - to store the popularity rating of the movie.(minimum rating = 0.0 and
maximum rating = 5.0)

Member Methods:

(i) MovieMagic() : Default constructor to initialize numeric data members to 0 and


String data member to "".

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

(iii) void display() : To display the title of a movie and a message based on the rating
as per the table below.
Rating Message to be displayed
0.0 to 1.0 Flop
1.0 to 2.0 One time watchable
2.0 to 3.0 Semi-Hit
3.0 to 4.0 Hit
4.0 to 5.0 Block Buster

Write a main method to create object and invoke all the member methods
PROGRAM 8:

Write a program with the following specifications.

Class Name:

Fixed_Deposit

Data Member / Instance variable:

String name – to store customer name

double pamt - to store principal amount deposited

int yrs – to store number of years

int age – to store years

Member methods:

Fixed_Deposit() – to initialize the data members with its default value.

void input() - to input the customer name, principal amount deposited, number of
years, and age.

void compute() - to calculate the maturity value of a fixed deposit account for the
given interest rates
[Link] years Person < 60 Senior citizen
Upto 1 year 6% PA 6.5% PA
Upto 2 year 6.25% PA 6.75% PA
Upto 3 year 6.5% PA 7% PA
More than 3 year 6.75% PA 7.25% PA

void output() – to display the customer name, principal amount deposited, number
of years, age and maturity value.

Write a main method to create object and invoke all the member methods.
PROGRAM 9:

The basic salary of the employees is undergoing a revision.

Define a class called Salary_Revision with the following specifications:

Data Members:

String name: to store name of the employee

int bas: to store basic salary

int expn: to store number of years of experience of the employee

double inc: to store increment given to the employee

double nbas: to store new basic salary(basic + increment)

Member Methods:

Salary_Revision(String name, int b, int e) - to initialize all data members

void calculate() – to calculate increment based on the experience as per


the criteria mentioned below:

Experience Increment
Upto 3 years Rs. 1000 + 10% of basic
More than 3 years & upto 5 years Rs. 3000 + 12% of basic
More than 5 years Rs. 5000 + 15% of basic

display() – to display the details as follows

Name Basic Experience Increment Revised Basic

xxxx xxxxx xxxxx xxxxxx xxxxx

Write a main method to create object of a class and call all the above member
methods.
PROGRAM 10:

Write a program to compute bill amount with the following specifications:

Class Name:

Telephone

Data Member / Instance variable:

double amt – to store bill amount

int no – for [Link] calls made

String Name – for customer name

Member Methods:

Telephone(String , int ) : parameterized constructor to initialize Customer Name and


[Link] calls made.

void compute( ) : To calculate the Bill amount to be paid based on the following
conditions.

No. of Calls Charges


First 250 Rs. 1
Next 100 Rs. 1.20 / minute
Next 150 Rs. 1.50 / minute
Excess Rs. 1.75 / minute

A rent or Rs.350 is charged as well as tax of 15% on the total bill for each customer.

void print() – To display customer name, bill number, bill amount.

Write a main program to create object and invoke all the methods.
PROGRAM 11:

Create a class Even_Fact having following details:

Data Member:

no - long type

Member methods:

Even_Fact(long x) : Assign the value of “n”.

long factorial(int num) : to return the factorial of a given number

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:

Enter a number

754921

(4!+2!)

Sample Output:

26
PROGRAM 12:

Define a class Area in which define 2 methods

void find_area(int s) to calculate and print the area of square,

void dind_area(double r) to calculate and print the area of circle,

by using the required parameters accepted in MAIN class

Define another class Volume in which define 2 methods

double Sphere() to calculate and return Volume of sphere and return to the
4
MAIN. (Hint : volume = 𝜋𝑟 3 )
3

double Cylinder(double r, double h) - to calculate and return volume of cylinder


to MAIN.(Hint : volume = πr2h)

using input entered by user in the MAIN class.

Define MAIN class to input the parameters required for the above methods and call
the above functions. use swich case (menu driven) to call the selected function.
PROGRAM 13:

Write a program to input a set of 20 alphabets. Convert each alphabet into its
opposite case. Find and display the number of vowels and number of consonants
present in the set of given alphabets. (Use functions of Character wrapper class.)

Sample Input:

Enter 20 alphabets

QaDfRtsfghjseIonmplc

Sample Output :

Alphabets in Opposite case:

qAdFrTSFGHJsEiOnMPlC

No. of Vowels : 4

No. of Consonants: 16
PROGRAM 14:

Write a program to Input a string. Count and print the number of words present in it.

Sample Input:

Enter a sentence

I am learning JAVA using BLUEJ. It is a stand-alone application.

Sample Output:

No. of words present 11

Sample Input:

Enter a sentence

The lion is a muscular, broad-chested cat family animal.

Sample Output:

No. of words present 9


PROGRAM 15:

Write a program to input a word in lower case letters, check and print whether it is a
palindrome or not also display the word in Uppercase letters.

Sample Input:

Enter a word

application

Sample Output:

Word in Uppercase : APPLICATION

APPLICATION is not a palindrome.

Sample Input:

Enter a word

malayalam

Sample Output:

Word in Uppercase : MALAYALAM

MALAYALAM is a palindrome word.


PROGRAM 16:

Write a program to print the longest word present in the sentence.

Sample Input:

Enter a sentence

Minicomputer is a medium size multiprocessing computer.

Sample Output:

Longest word: multiprocessing


PROGRAM 17:

Write a program to accept a word and convert it into lower case, if it is in upper case.
Display the new word by replacing only the vowels with the letter following it.

Sample Input:

Enter a word

India

Sample Output :

New word : jndjb


PROGRAM 18:

Write a program that encodes a word in “Piglatin”. To translate word into Piglatin
word, convert the word into uppercase and then place the first vowel of the original
word as the start of the new word along with the remaining alphabets. The alphabets
present before the vowel being shifted towards the end followed by “AY”.

Sample Input:

Enter a word

India

Sample Output:

Piglatin word : INDIAAY

Sample Input:

Enter a word

program

Sample Output:

Piglatin word : OGRAMPRAY


PROGRAM 19:

Write a program to input roll numbers, names and marks in 3 subjects of ‘n’ number
of students in five single dimensional arrays. Calculate average marks of each student
and store in a single dimensional array. Calculate the sum and average marks of all
students. Display roll number, name and remark of all students based on the
average marks and the criteria given below:

Average Marks Remark

85 to less than equal to 100 Excellent

75 to less than 85 Distinction

60 to less than 75 First Class

Less than 60 Pass

Student name Sub1 Sub2 Sub3 Total Percentage Remark

XXXXX XX XX XX XX XXXXX XXXXX


PROGRAM 20:

Write a program to read 20 double elements in an array named ‘sub’. Arrange first
10 elements in ascending order and last 10 elements in descending order. (Use
Bubble sort technique).

Sample Input:

Enter 20 Double elements

1.5 -9.2 0.5 12.3 2.7 5.1 6.6 125.2 36.2 50.7 12.3 45.45 -
86.2 9.10 14.5 56.2 89.9 10.5 0.5 3.1

Sample Output:

First 10 elements in ascending order

-9.2 0.5 1.5 2.7 5.1 6.6 12.3 36.2 50.7 125.2

Next 10 elements in descending order

89.9 56.2 45.45 14.5 12.3 10.5 9.10 3.1 0.5 -86.2
PROGRAM 21:

Write a program to input a person name and print the characters of name in
ascending order. (Use Selection sort technique)

Sample Input:

Enter a name

Dinosaur

Sample Output:

Name in ascending order

Dainorsu
PROGRAM 22:

Write a program to enter 10 different names along with their phone numbers, enter
a name in the terminal window and search whether the name is present or not. If
name is present then display the name along with the phone number otherwise
display appropriate message. (Linear search).

Sample Input:

Enter 10 names and their phone numbers

saniya 9865458965

amar 9632587410

ram 9874563211

anitha 9632104587

raju 8963215471

wincent 8356897410

flora 7896321054

tina 7702222311

banu 7025631236

chitra 9023165478

Enter name to be searched

flora

Sample Output:

flora present in 6 position

flora 7896321054
PROGRAM 23:

Write a program to read “n” number of names in an array and name to be searched.
Find the position of the searching element in an array and print its position (Binary
search).

Sample Input:

Enter [Link] names

Enter 5 names in ascending order

Arjun Emma George Jack Tina

Enter name to be searched

Jack

Sample Output:

Jack present in 3 position

Sample Input:

Enter [Link] names

Enter 5 names in ascending order

George Jack Tina

Enter name to be searched

Ani

Sample Output:

Ani not present


PROGRAM 24:

Write a program to read elements for a square matrix. Find

a. Sum of left diagonal elements


b. Sum of right diagonal elements
c. Sum of each row
d. Sum of each column

print the 2D array in matrix format, also the answers.

Sample Input:

Enter [Link] rows/columns

Enter 16 elements

10 20 30 40 50 60 70 80 50

Sample Output:

3 x 3 Matrix:

10 20 30

40 50 60

70 80 50

Sum of left diagonal elements : 110

Sum of right diagonal elements: 130

Sum of row 1 elements : 60

Sum of row 2 elements : 150

Sum of row 3 elements : 200

Sum of column 1 elements : 120

Sum of column 2 elements : 150

Sum of column 3 elements : 140


PROGRAM 25:

Write a program to read a N x M matrix. Display the original matrix. Also find and
print the transpose of entered matrix.

Sample Input:

Enter [Link] rows

Enter [Link] columns

Enter 16 elements

10 20 30 40 50 60

Sample Output:

Original Matrix:

10 20

30 40

50 60

Transpose Matrix:

10 30 50

20 40 60

You might also like