100% found this document useful (1 vote)
298 views45 pages

Grade 10 Computer Appications Project PDF

Here are the steps to write a menu driven program to check if a number is special or harshad: 1. Display a menu with options to check for special number or harshad number. 2. Read the user's choice. 3. If choice is 1, read a number from user and check if it is special number: - Separate each digit of the number - Calculate factorial of each digit - Sum the factorials - Check if sum equals the original number 4. If choice is 2, read a number and check if it is harshad: - Separate each digit of the number - Sum the digits - Check if original number is divisible by digit sum
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
100% found this document useful (1 vote)
298 views45 pages

Grade 10 Computer Appications Project PDF

Here are the steps to write a menu driven program to check if a number is special or harshad: 1. Display a menu with options to check for special number or harshad number. 2. Read the user's choice. 3. If choice is 1, read a number from user and check if it is special number: - Separate each digit of the number - Calculate factorial of each digit - Sum the factorials - Check if sum equals the original number 4. If choice is 2, read a number and check if it is harshad: - Separate each digit of the number - Sum the digits - Check if original number is divisible by digit sum
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/ 45

Computer

Project
2020-21
Name:
Karthikeya Kakarlapudi
Grade: X – F
Roll No:

Karthikeya Kakarlapudi 1
ACKNOWLEDGEMENT

I would like to thank Ms. Sarala for her valuable guidance

and help. She clarified all my queries about the project

without which I would not have been able to complete the

project. I would also like to thank my family for providing

all the necessary materials and my friends for helping me

with this project.

Karthikeya Kakarlapudi 2
INDEX
S.No. Programs Pg.No.
1. For Loop Pattern Program with switch-case 4-10
2. For Loop Series program 11-14
3. Number Programs (Special Number & Harshad 15-21
Number )
4. If-else without slab 22-26
5. HCF/GCD 27-30
6. Function (Parcel) 31-35
7. Function (Consecutive Natural Numbers) 36-39
8. Call by Reference(Finding midpoint using call by 40-44
reference)
9. Constructor (Finding the roots of a quadratic
equation)
10. Nested functions (Sum of factorial of even
digits)
11. Character function
12. Palindrome Words
13. Arranging letters in alphabetical order
14. Piglatin Word
15. Linear Search
16 Binary Search
17. Selection Sort
18. Bubble Sort
19. Row Sum and Column Sum
20. Matrix Subtraction

Karthikeya Kakarlapudi 3
Question 1:

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 1 2 3 4 5

2 1 5 4 3 2

3 2 1 2 3 4

4 3 2 1 4 3

5 4 3 2 1 3

Karthikeya Kakarlapudi 4
Program 1:

import java.util.Scanner;

public class PROJECT1

void patterns()

Scanner sc = new Scanner(System.in);

System.out.println("Enter 1 to print a normal triangle\n Enter 2 to print an inverted


triangle");

//taking input

int num = sc.nextInt();

int x;

int y;

switch (num)

case 1 : x = 1;

y = 1;

for(int i = 1; i<=5; i++)

x=y;

for(int k = 5-i; k>=1;k--)

System.out.print(" ");

Karthikeya Kakarlapudi 5
}

for( int j = 1; j<=i; j++)

System.out.print(x + " ");

x--;

System.out.println();

y++;

break;

case 2 : x=5;

int m = 12345;

int n = m;

int digit;

int reverse=0;

y=5;

for(int i = 1; i<=5; i++)

n=m;

for(int k = i-1;k>=1;k--)

System.out.print(" ");

Karthikeya Kakarlapudi 6
}

while(n>0)

//extracting digit

digit = n%10;

//reversing number

reverse= reverse*10 + digit;

n=n/10;

m=reverse/10;

while (reverse>0)

digit = reverse%10;

System.out.print(digit + " ");

reverse = reverse/10;

System.out.println();

break;

default:

//default case output

System.out.println("Incorrect number entered!");

Karthikeya Kakarlapudi 7
}

public static void main(String[]args)

//creating object

PROGRAM1 obj = new PROGRAM1();

obj.patterns();

Variable Description Table:

Variable Name Data type Purpose


num int To store user choice
x int To print pattern
y int To print pattern
i int Loop control variable
j int Loop control variable
k int Loop control variable
m int To print pattern
n int To print pattern
digit int To store extracted digit
reverse int To store reverse of number

Karthikeya Kakarlapudi 8
Output:

Karthikeya Kakarlapudi 9
Karthikeya Kakarlapudi 10
Question 2:

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

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

(ii) S = 0+1+1+2+3+5+8+……...upto n terms

Karthikeya Kakarlapudi 11
Program 2:

import java.util.Scanner;
public class PROJECT2
{
public static void main(String[]args)
{
//invoking output method
PROJECT2 obj = new PROJECT2();
obj.output();
}
void output()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number to use in the first series:");
int a = sc.nextInt();
System.out.println("Enter the number of terms to compute in both the series");
int n = sc.nextInt();
int power = 1;
int num = 2;
int factorial = 1;
int b = 1;
double sum1 = 0;
double sum2 = 0;
int x = 0;
int y = 1;
int z;
sum2 = x + y;
for(int i = 1; i<=n; i++)
{
factorial = 1;
for( int k = 1; k<=num; k++)
{
//factorial loop
factorial*=k;
}
sum1+=(((Math.pow(a,power))/factorial)*b);
b*=-1;
num+=2;
power+=3;
}
//first series output
System.out.println("The sum of the first series = "+sum1);
for( int j = 1; j<=(n-2); j++)
{
//fibbonaci summation loop

Karthikeya Kakarlapudi 12
z = x+y;
sum2+=z;
x=y;
y=z;
}
//second series output
System.out.println("The sum of the second series = "+sum2);
}
}

Variable Description Table:

Variable Name Data type Purpose


a int Number used in first series
n int Number of terms to compute
power int Power to which a has to
num int Denominator in first series
factorial int To store factorial of number
k int Loop control variable
b int To change parity of term
sum1 double To store sum of first series
sum2 double To store sum of second series
x int To store terms of Fibonacci sequence
y int To store terms of Fibonacci sequence
z int To store terms of Fibonacci sequence
i int Loop control variable
j int Loop control variable
k int Loop control variable

Karthikeya Kakarlapudi 13
Output:

Karthikeya Kakarlapudi 14
Question 3:

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

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

Karthikeya Kakarlapudi 15
Program 3:

import java.util.Scanner;
public class PROJECT3
{
public static void main(String[]args)
{
PROJECT3 obj = new PROJECT3();
obj.output();
}
void output()
{
//creating scanner class object
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
System.out.println("Enter 1 to check if it is a Special Number \n Enter 2 to check if it is Harshad
Number");
int a = sc.nextInt();
switch (a)
{
//switch case
case 1:
int digit;
int factorial=1;
int num2 = num;
int num3=0;
while(num2>0)
{
//while loop body
digit = num2%10;
for(int i =1;i<=digit;i++)
{
//factorial loop
factorial*=i;
}
num3 += factorial;
factorial=1;

Karthikeya Kakarlapudi 16
num2/=10;
}
if(num3==num)
{
System.out.println("The number entered is a Special Number");
}
else
{
System.out.println("The number entered was not a special number");
}
break;
case 2:
int sum = 0;
int d;
int num4 = num;
while(num4>0)
{
d = num4%10;
sum+=d;
num4/=10;
}
if(num%sum==0)
{
System.out.println("The number is a Harshad Number");
}
else
{
System.out.println("The number is not a Harshad Number");
}
break;
default:
//default case
System.out.println("Incorrect number entered!");
}
}
}

Karthikeya Kakarlapudi 17
Variable Description Table:

Variable Name Data type Purpose


num int Number to check
a int Switch case number
digit int To store extracted digit
factorial int To store factorial
num2 int To be used in place of num
num3 int To store sum of factorials
i int Loop control variable
sum int To store sum of digits
d int To store extracted digit
num4 int To store num for comparison

Karthikeya Kakarlapudi 18
Output:

Karthikeya Kakarlapudi 19
Karthikeya Kakarlapudi 20
Karthikeya Kakarlapudi 21
Question 4:

Write a program with the following specifications:

Class : Employee

Methods:

calculate( ) : To accept Employee_No, Name and Basic_Salary of

the employees and calculate the Gross Salary based


on the following conditions. Also display the values in
the given format.

Basic Salary DA(%) TA(%) HRA(%) PF(%)


>=20,000 53 12 10 8
>=10,000 to <20,000 45 10 12 7.5
<10,000 40 8 14 7

Gross_Salary = ( Basic_Salary + DA + TA + HRA ) – PF

EMPLOYEE No. NAME GROSS SALARY PF

************ ******* ********* **

Write a main method to create the object of the above class and call the above method
to calculate and print the Employee_No, Name, Gross_Salary and PF of an employee.

Karthikeya Kakarlapudi 22
Program 4:

import java.util.Scanner;
public class Employee
{
void calculate()
{
// scanner object creation
Scanner sc = new Scanner(System.in);
System.out.println("Enter Employee Name:");
String name = sc.nextLine();
System.out.println("Enter Employee No.:");
long employee_no = sc.nextLong();
System.out.println("Enter Basic Salary:");
int basicsalary = sc.nextInt();
double DA = 0;
double TA = 0;
double HRA = 0;
double PF = 0;
//if else conditions
if (basicsalary<10000&&basicsalary>=0)
{
DA = 40;
TA = 8;
HRA = 14;
PF = 7;
}
else if(basicsalary>=10000&&basicsalary<20000)
{
DA = 45;
TA = 10;
HRA = 12;
PF = 7.5;
}
else if(basicsalary>=20000)
{
DA = 53;
TA = 12;
HRA = 10;
PF = 8;
}
//output
if(basicsalary>0)
{
double gross_salary = basicsalary + basicsalary*((DA+TA+HRA-PF)/100);
PF = basicsalary*PF/100;
System.out.println("Employee No.\t\tName\t\tGross Salary\t\tPF");

Karthikeya Kakarlapudi 23
System.out.println(employee_no+"\t\t"+name+"\t\t"+gross_salary+"\t\t"+PF);
}
else
{
System.out.println("Incorrect Salary entered!");
}
}
public static void main(String[]args)
{
//object creation
Employee obj = new Employee();
//method invocation
obj.calculate();
}
}

Variable Description Table:

Variable Name Data type Purpose


name String Name of employee
employee_no long To store name of employee
basic salary int To store basic salary of employee
DA double Stores DA
TA double Stores TA
HRA double Stores HRA
PF double Stores PF

Karthikeya Kakarlapudi 24
Output:

Karthikeya Kakarlapudi 25
Karthikeya Kakarlapudi 26
Question 5:

Define a class sub1 in which define a method f1() to calculate and print hcf (highest
common factor) by division method of any two given numbers entered by user in the
main class. Define another class sub2 in which define a method f2() to calculate and
print the area and perimeter of a rectangle by using the required parameters accepted
in main class. Define main class to input the parameters required in the above two
methods and call the two functions.

[Hint : GCD

1. Decide the greater from two numbers.

2. Divide the greater number by smaller number, if remainder is zero, print


divisor(smaller number) as HCF, otherwise

3. Take divisor as number and remainder as divisor and repeat steps 2 and 3.]

Karthikeya Kakarlapudi 27
Program 5:

import java.util.Scanner;
public class PROJECT5
{
public static void main(String[]args)
{ //Scanner object creation
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number to find GCD:");
int x = sc.nextInt();
System.out.println("Enter the second number to find GCD:");
int y = sc.nextInt();
//object creation
sub1 obj1 = new sub1();
System.out.print("The GCD of the two numbers is: ");
System.out.print(obj1.f1(x,y));
System.out.println();
System.out.println("Enter the length of the rectangle to find its area: ");
int l = sc.nextInt();
System.out.println("Enter the breadth of the rectangle to find its area: ");
int b = sc.nextInt();
sub2 obj2 = new sub2();
System.out.print("The area of the rectangle is :");
System.out.print(obj2.f2(l,b));
}
}
public class sub1
{
int f1(int num1, int num2 )
{ //parameterized function
int remainder=Math.max(num1, num2)%Math.min(num1, num2);
while(num2!=0)
{ //while loop
remainder=Math.max(num1, num2)%Math.min(num1, num2);
num1 = num2;
num2 = remainder;
}
return num1;
}
}
public class sub2
{
long f2(int length, int breadth)
{ //parameterized constructor
long area = length*breadth;
return area;
}

Karthikeya Kakarlapudi 28
Variable Description Table:

Variable Name Data type Purpose


x int First number
y int Second number
l int Length of rectangle
b int Breadth of rectangle
num1 int Stores x in sub1
num2 int Stores y in sub2
remainder int remainder of num1 and num2
length long stores l in sub2
breadth long stores b in sub2
area long stores area of l and b rectangle

Karthikeya Kakarlapudi 29
Output:

Karthikeya Kakarlapudi 30
Question 6:

Define a class parcel having the following functions:


int calculate(int w1) : To calculate and return the service charge for the
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: 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

Karthikeya Kakarlapudi 31
Program 6:

import java.util.Scanner;
public class parcel
{
int calculate(int w1)
{ //parameterized constructor
int cost = 0;
if(w1<=100&&w1>=0)
{ //if condition
cost+=40;
}
else if(w1>100)
{
cost+=40;
w1-=100;
if(w1%50==0)
{
cost+=20*(w1/50);
}
else
{ //else condition
cost+=20*(w1/50)+20;
}
}
else
{
System.out.println("Invalid weight of object!");
}
return cost;
}
void display(int w2,String name2)
{ //double parameterized constructor
parcel obj1 = new parcel();
int charges = obj1.calculate(w2);
System.out.println("Name\t\t\tWeight of the Parcel\t\tCharges");
System.out.println(name2+"\t\t"+w2+"\t\t\t"+charges);
}
public static void main(String[]args)
{ //Scanner object creation
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name:");
String name = sc.nextLine();
System.out.println("Enter the weight of the parcel: ");
int weight = sc.nextInt();
parcel obj2 = new parcel();
obj2.display(weight, name);

Karthikeya Kakarlapudi 32
}
}

Variable Description Table:

Variable Name Data type Purpose


cost int Stores parcel cost in calculate() method
w1 int Stores parcel weight in calculate()
method
w2 int Stores parcel weight in display() method
name2 String Stores person’s name in display() method
charges int Stores parcel cost in display() method
name String Stores person’s name in main() method
weight int Stores parcel weight in main() method

Karthikeya Kakarlapudi 33
Output:

Karthikeya Kakarlapudi 34
Karthikeya Kakarlapudi 35
Question 7:

Write a program to input a positive natural number N and output all combination of
consecutive natural numbers which added up to give N
Example: If the N is 15 then output should be
1 2 3 4 5 = 15
4 5 6 = 15
7 8 = 15
Define a class consecutive that has the following functions.
private static void printSet(int i, int j) -> which print one line series of numbers starting

from i to j, as mentioned in the above format.

public static void main(int N) ->It accepts positive natural number N and invokes

the printSet(int,int) to print all number

of possibilities upto N, as mentioned in the

above example.

Karthikeya Kakarlapudi 36
Program 7:

import java.util.Scanner;

public class PROGRAM7


{
public static void main(int N)
{ //parameterized main method
int start = 1;
int end = (N + 1) / 2;
PROGRAM7 obj = new PROGRAM7();
while (start < end)
{ //while loop body
int sum = 0;
for (int i = start; i <= end; i++)
{
sum = sum + i;
if (sum == N)
{ //if condition body
obj.printSet(start,i);
System.out.print("="+N);
System.out.println();

}
if (sum > N)
break;
}
sum = 0; //reinitializing sum to 0
start++;
}
}
private static void printSet(int i, int j)
{ //output method
for (int k = i; k <= j; k++)

System.out.print(k + " ");


}
}

Karthikeya Kakarlapudi 37
Variable Description Table:

Variable Name Data type Purpose


N int input number
start int Start point of consecutive natural
numbers that add up to N
end int End point of numbers to check
sum int Stores sum of consecutive natural
numbers to compare to N
i int Start point of consecutive natural
numbers that add up to N in printSet()
method
j int End point of consecutive natural numbers
that add up to N in printSet() method
k int Output number

Karthikeya Kakarlapudi 38
Output:

Karthikeya Kakarlapudi 39
Question 8:

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
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

Karthikeya Kakarlapudi 40
Program 8:

import java.util.Scanner;

public class EvenFact

long n;

void input()

{//input method

Scanner sc = new Scanner(System.in);

System.out.println("Enter the number: ");

n = sc.nextLong();

long factorial (long f)

{//parameterized constructor

long factorial=1;

for(int i=1; i<=f; i++)

{//factorial loop

factorial*=i;

return factorial;

long evenDigit()

Karthikeya Kakarlapudi 41
long digit;

long num = n;

long sum = 0;

while(num>0)

{//while loop

digit = num%10;

if(digit%2==0)

long fact = factorial(digit);

sum+=fact;

num/=10;

return sum;

public static void main(String[]args)

{//object creation

EvenFact obj = new EvenFact();

obj.input();

long sum = obj.evenDigit();

System.out.println("The sum of even digits is: "+sum);

Karthikeya Kakarlapudi 42
Variable Description Table:

Variable Name Data type Purpose


n long Input number
f long Number whose factorial is to be found
factorial long Stores factorial
i int loop control variable
digit long Stores digit
num long Stores n in evenDigit() method
sum long Stores sum of even digits
fact long Stores factorial in evenDigit() method

Karthikeya Kakarlapudi 43
Output:

Karthikeya Kakarlapudi 44
Karthikeya Kakarlapudi 45

You might also like