Computer Science Class 11 Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 38

1

SEVENTH DAY ADVENTIST


SENIOR SECONDARY SCHOOL.

A PROJECT SUBMITTED IN THE PARTIAL FULLFILLMENT


OF CLASS-XI ISC COMPUTER SCIENCE EXAMINATION
FOR SESSION- 2023-24.

NAME: SK RISHAD RAHMAN.


CLASS: X. SECTION: SCIENCE ROLL NO: 19.
SUBJECT: COMPUTER SCIENCE.
DATE OF SUBMISSION: 16/10/2023 .

_________________ __________________
Internal Examiner External Examiner
Approval Approval

2
ABOUT MYSELF
I am SK RISHAD RAHMAN, and I am currently a student in the 11th
grade. Life as a student has been wonderful so far and would expect to
be wonderful when I go to the college for my further studies and become
a good engineer. I have experienced both triumphs and challenges
during my school life, which have helped to shape me into the person I
am now.

3
ACKNOWLEDGEMENT
I want to be really grateful to my computer teacher Mrs. Fancy
Roy Choudhury and our Council ISC for providing such an
informative project to us. While doing this project, it helped me
a lot as all of my doubts were getting cleared as I was
progressing in this project.
I also thank to my fellow friends, parents and my tuition
teacher for helping me in doing this project. They motivated me,
guided me and helped me all through the project and complete
in limited time.
I have done this project not only for marks but to increase my
knowledge in this particular subject.
Last but not least once again I want to thank to all who helped
me, and motivated me and guided me while doing my project.

SK RISHAD RAHMAN
CLASS ‘XI’ SCIENCE.

4
Table of Contents
1. Introduction…………………………………………………… 6
2. Programs……………………………………………………….. 11
3. Conclusion……………………………………………………… 37
4. Bibliography…………………………………………………… 38

5
INTRODUCTION
Introduction To Object Oriented Programming.
Object-oriented programming aims to implement real-world
entities like inheritance, hiding, polymorphism, etc in
programming. The main aim of OOP is to bind together the data
and the functions that operate on them so that no other part of the
code can access this data except that function. Types of high level
languages are:
a. Procedure-Oriented.
b. Object Oriented.

OBJECT ORIENTED LANGUAGES.


Object-oriented programming (OOP) is a computer
programming model that organizes software design around
data, or objects, rather than functions and logic. An object can
be defined as a data field that has unique attributes and
behavior.
Advantages of object oriented programming language are:
a. Data values are secured.
b. Mishandling of data is protected.
c. Error detection and correction become easier.
d. Easier in coding complex programs.
Examples: Java, C++, Small Talk, Eiffel, Python.

6
PRINCIPLES OF OBJECT ORIENTED PROGRAMING (OOP):
 Data Abstraction: Objects in an OOP language provide an
abstraction that hides the internal implementation details.
Similar to the coffee machine in your kitchen, you just need to
know which methods of the object are available to call and which
input parameters are needed to trigger a specific operation.
 Encapsulation: In object-oriented computer programming (OOP)
languages, the notion of encapsulation (or OOP Encapsulation)
refers to the bundling of data, along with the methods that
operate on that data, into a single unit. Many programming
languages use encapsulation frequently in the form of classes.
 Inheritance: When a class derives from another class. The child
class will inherit all the public and protected properties and
methods from the parent class. In addition, it can have its own
properties and methods. An inherited class is defined by using
the extends keyword.
 Polymorphism: Polymorphism is one of the core concepts of
object-oriented programming (OOP) and describes situations in
which something occurs in several different forms. In computer

7
science, it describes the concept that you can access objects of
different types through the same interface.

Elementary Concept of Objects and Classes.


Introduction
An object is an entity having a specific identity, specific characteristics
and specific behavior. A class is a blue print that represents a set of
objects that share common characteristics and behavior. Take the
example of a house. An architect will have the blueprints for a house.

8
Types of Class and Objects:
1. Real World Class and Objects: a car is an object. The car
has attributes, such as weight and color, and methods,
such as drive and brake. A Class is like an object
constructor, or a "blueprint" for creating objects.
2. Software Class and Objects: A class is a blueprint from
which you can create the instance, i.e., objects. An object
is the instance of the class, which helps programmers to
use variables and methods from inside the class. A class is
used to bind data as well as methods together as a single
unit. Object acts like a variable of the class.

9
Some Meaningful Terms of Object and Class:
 Class is an object factory: A class is used to create similar
objects and possess different characteristics and common
behaviors. Hence, class is called an object factory.
 Object is instance of a class: The data members declared
within a class are also known as instance variables. When
an object of a class is created, it includes instance variable
described within the class. This is the reason that object is
called as instance of a class.
 Class is a user defined data type: When user creates a
class it becomes a data type for his program. Thus class is
referred to as a user defined data type. This data type
includes different primitive types such as int, float, char,
etc. Hence, it is also said to Composite Data Types.

PROGRAMMES
10
1. Write a program to accept any three- letter word and print all
the probable three- letter combinations. No letter should
repeat in the output.
Sample Input: TOP
Sample Output: The required combinations of the word:
TOP, TPO, OPT, OTP, PTO, POT

import java.util.*;

public class Eg_19

public static void main()

String str;

int i,j,p,k;

Scanner sc=new Scanner(System.in);

System.out.println("Enter a three letter word");

str=sc.nextLine();

p=str.length();

System.out.println("All possible combinations of the word are :");

for(i=0;i<p;i++)

for(j=0;j<p;j++)

11
for(k=0;k<p;k++)

if(i!=j && j!=k && k!=i)

System.out.print(str.charAt(i)+""+str.charAt(j)+""+str.charAt(k));

System.out.println();

OUTPUT OF THE PROGRAM

2. Write a program to input a number. Display the product of the


successors of even digits of the number entered by user.
Input: 2745
12
Output: 15
[Hint: The even digits are: 2 and 4
The product of successor of even digits is: 3*5= 15]

import java.util.*;
public class EvenSuccessor
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = sc.nextInt();
int orgNum = num;
int prod = 1;
while (num != 0)
{
int digit = num % 10;
num /= 10;
if (digit % 2 == 0)
prod = prod * (digit + 1);
}
if (prod == 1)
System.out.println("No even digits in " + orgNum);
else
System.out.println("Product of even digits successors is " + prod);
}
}

OUTPUT OF THE PROGRAM:

13
3. Write a program to input a number and check whether it is
'Magic Number' or not. Display the message accordingly.
A number is said to be a magic number if the eventual sum of
digits of the number is one.
Sample Input : 55
Then, 5 + 5 = 10, 1 + 0 = 1
Sample Output: Hence, 55 is a Magic Number.
Similarly, 289 is a Magic Number.

import java.util.*;
public class MagicNumber
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number to check: ");
int num = sc.nextInt();
int n = num;
while (n > 9)
{
int sum = 0;
while (n != 0)
{
int d = n % 10;

14
n /= 10;
sum += d;
}
n = sum;
}
if (n == 1)
System.out.println(num + " is Magic Number");
else
System.out.println(num + " is not Magic Number");
}
}
4. Write a program to find the sum of the given series to ‘n’
terms by using function name sum(int). Write the main
program to display the sum of the series.
S= (1*2) + (2*3) + (3*4) +------------------------------------- to ‘n’
terms.

import java.util.*;
public class Series
{
int sum(int a)
{
int i,s=0;
for(i=1;i<a;i++)
s=s+(i*(i+1));
return(s);
}
public static void main()
{
Scanner sc=new Scanner(System.in);
int p,n;
System.out.println("Enter the value of n");
n=sc.nextInt();
Series ob=new Series();

15
p=ob.sum(n);
System.out.println("The sum of the series is "+p);
}
}

OUTPUT OF THE PROGRAM:

5. Write a program to accept a number and check whether the


number is prime or not. Use the function name as check (int n).

import java.util.*;
public class Prime
{
int check(int n)
{
int i,c=0,f=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if(c==2)
f=1;
return(f);

16
}
public static void main()
{
int a,k;
Scanner sc=new Scanner(System.in);
System.out.println("Enter your number");
a=sc.nextInt();
Prime ob= new Prime();
k=ob.check(a);
if(k==1)
System.out.println(a+"is a prime number");
else
System.out.println(a+"is not a prime number");
}
}

17
OUTPUT OF THE PROGRAM:

18
6. Write a program by using a class with the following
specifications:
Class name : Prime
Data members/instance variables : int n
Member Methods :
Prime() : default constructor to initialize n
Void input(int x) : to assign ‘n’ with ‘x’
Void display() : to check whether the number is prime or not.

public class Prime


{
int n;
Prime()
{
n=0;
}
void input(int x)
{
n=x;
}
void display()
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if(c==2)
System.out.println(n + "is a prime number");
else
System.out.println(n + "is not a prime number");
}

19
}

OUTPUT OF THE PROGRAM:


STEP 1:

STEP 2:

STEP 3:

20
7. Write a program in java to accept an array from the user and
insert an element given by the user in the position given by the
user.

import java.util.*;
public class Insert
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int i,n,ele,pos;
int arr[]=new int[10];
System.out.println("Enter number of array elements");
n=sc.nextInt();
System.out.println("Enter array elements");
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
System.out.println("Enter the element to be inserted");
ele=sc.nextInt();
System.out.println("Enter position of insertion");
pos=sc.nextInt();
for(i=n-1;i>=pos;i--)
arr[i+1]=arr[i];
arr[pos]=ele;
n++;
System.out.println("Array elememts after insertion");
for(i=0;i<n;i++)
System.out.println(arr[i]);
}
}

21
OUTPUT OF THE PROGRAM:

8. Write a program in java to accept an array from the user and


delete an element given by the user in the position given by the
user.

import java.util.*;
public class Deletion
{
public static void main()
{
int i,n,pos;
int arr[]=new int[10];
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of array elements");
n=sc.nextInt();
System.out.println("Enter array elements");
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
System.out.println("Enter position of element to be deleted");

22
pos=sc.nextInt();
for(i=pos+1;i<n;i++)
arr[i-1]=arr[i];
n--;
System.out.println("Array elements after deletion");
for(i=0;i<n;i++)
System.out.println(arr[i]);
}
}

OUTPUT OF THE PROGRAM:

9. Write a program in java to accept two arrays from the user


and merge the given array in the third array.

import java.util.*;
public class Merging
{
public static void main()
{
int i,n,m,p,pos;
Scanner sc =new Scanner(System.in);
System.out.println("Enter number of array elements in array arr1");
23
n=sc.nextInt();
System.out.println("Enter number of array elements in array arr2");
m=sc.nextInt();
System.out.println("Enter number of elements in merged array arr3");
p=sc.nextInt();
int arr1[]=new int[n];
int arr2[]=new int[m];
int arr3[]=new int[p];
System.out.println("Enter elements in array arr1");
for(i=0;i<n;i++)
arr1[i]=sc.nextInt();
System.out.println("Enter elements in array arr2");
for(i=0;i<m;i++)
arr2[i]=sc.nextInt();
for(i=0;i<n;i++)
arr3[i]=arr1[i];
for(i=0;i<m;i++)
arr3[n+i]=arr2[i];
System.out.println("Array elements after merging");
for(i=0;i<p;i++)
System.out.println(arr3[i]);
}
}

OUTPUT OF THE PROGRAM:

24
10. Write a program in java to store different numbers in 4x4
matrix in a Double Dimensional Array. Display the highest and
the lowest number among the stored number in the matrix.

import java.util.*;
public class highLow
{
public static void main()
{
int i,j,max=0,min=0;
int num[][]=new int [4][4];
Scanner sc=new Scanner(System.in);
System.out.println("Enter the numbers in the 4x4 matrix:");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
num[i][j]=sc.nextInt();
}
}
System.out.println("The elements of 4x4 matrix are:");
for(i=0;i<4;i++)
25
{
for(j=0;j<4;j++)
{
System.out.print(num[i][j]+ " ");
}
}
System.out.println();
min=num[0][0];max=num[0][0];
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(min>num[i][j])
min=num[i][j];
if(max<num[i][j])
max=num[i][j];
}
}
System.out.println("The highest number :" +max);
System.out.println("The lowest number :" +min);
}
}
OUTPUT OF THE PROGRAM:

11. Write a program in Java to store the numbers in 4x4 matrix


in Double Dimensional Array. Display the sum of:
i) Left diagonal elements.
26
ii) Right diagonal elements.
iii) Difference between the sum of left and right diagonal
elements.

import java.util.*;
public class LeftRight
{
public static void main()
{
int i,j,ld=0,rd=0,k=3;
int num[][]=new int[4][4];
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number in 4x4 matrix :");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
num[i][j]=sc.nextInt();
}
}
System.out.println("The elments of 4x4 matrix are:");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(num[i][j]+" ");
}
System.out.println();
}
for(i=0;i<4;i++)
{
ld=ld+num[i][i];
}
for(j=0;j<4;j++)

27
{
rd=rd+num[j][k];
k=k-1;
}
System.out.println("The sum of left diagonal :"+ld);
System.out.println("The sum of right diagonal :"+rd);
System.out.println("The diff. between left and right diagonal : "
+(ld-rd));
}
}
OUTPUT OF THE PROGRAM:

12. Write a program in java to accept two numbers and find


the sum of the numbers using method by creating an object of
the class. However, the method returns the sum to the main
method to display the result.

import java.util.*;

28
public class Addition
{
int sum(int a,int b)
{
int c;
c=a+b;
return(c);
}
public static void main()
{
int m,n,k;
Scanner sc=new Scanner(System.in);
Addition ob=new Addition();
System.out.println("Enter two numbers");
m=sc.nextInt();
n=sc.nextInt();
k=ob.sum(m,n);
System.out.println("The sum of two numbers :"+k);
}
}
OUTPUT OF THE PROGRAM:

13. Write a program by using a class with the following


specifications:
Class name : Profit_Loss
Data members/instance variables : int cp, sp
Methods:
Profit_Loss () : default constructor to initialize cp,sp

29
Void input (int a, int b) : to assign ‘cp’ with ‘m’ and ‘sp’ with
‘n’
Void display () : to calculate and display either profit percent
(pp) or loss percent (lp)

public class Profit_Loss


{
int cp,sp,pr,loss;
double pp,lp;
Profit_Loss()
{
cp=0;
sp=0;
}
void input(int m,int n)
{
cp=m;
sp=n;
}
void display()
{
if(sp>cp)
{
pr=sp-cp;
pp=(double)pr/cp*100;
System.out.println("The profit percent :"+pp);
}
if(cp>sp)
{
loss=cp-sp;
lp=(double)loss/cp*100;
System.out.println("The loss percent :"+lp);
}
}

30
}

OUTPUT OF THE PROGRAM:


STEP 1:

STEP 2:

STEP 3(Profit output):

31
STEP 4(Loss output):

14. Write a program in java to input a base number and an


index. The program calculates and displays the magnitude of
index, raised to a base by using recursive function.
Sample Input:
Enter a base number :5
Enter index :4
Sample Output : 625 (i.e.,54 )

import java.util.*;
public class Npower
{
int power(int n,int p)
{
if(p==0)
return(1);
else
return(n*power(n,p-1));
}
public static void main()
{
Scanner sc=new Scanner(System.in);
int num,p,ans;
System.out.println("Enter the base value");
num=sc.nextInt();
System.out.println("Enter power of the base value");

32
p=sc.nextInt();
Npower ob=new Npower();
ans=ob.power(num,p);
System.out.println(num+" to the power "+ p + " is "+ans);
}
}
OUTPUT OF THE PROGRAM:

15. Fibonacci series is generated as given below:


0,1,1,2,3,5,8,13………
Here, each successive term is the sum of its previous two terms.
Thus, you can conclude as:
(i) If n=0 or n=1 then function returns Tn [T refers term].
(ii) If n>1 then function returns Tn-2+Tn-1.
Write a program to generate the elements of Fibonacci series
up to a given limit entered by the user. The program follows a

33
recursive function to return Tth Fibonacci element, where T is
the term number.

import java.util.*;

public class Fseries

int fiboseries(int num)

if(num==1)

return(0);

else if(num==2)

return(1);

else if(num>2)

return(fiboseries(num-1)+fiboseries(num-2));

else

return(-1);

public static void main()

Scanner sc=new Scanner(System.in);

System.out.println("Enter number of terms to display");

int n,p=0;

n=sc.nextInt();

34
Fseries ob=new Fseries();

System.out.println("The Fibbonacci Series");

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

p=ob.fiboseries(i);

System.out.print(p+ ", ");

}}

OUTPUT OF THE PROGRAM:

16. Write an algorithm to enter a number and check whether


the number is prime or not.

Algorithm: The different steps are:


Step 1: Start.
Step 2: Accept a number ‘n’ from the console.
Step 3: Take a counter as c = 0.
Step 4: Repeat for i= 1, 2, 3 ….., n.
If (remainder (n/i)=0)
c=c+1.
end for.
Step 5: if (c = 2).
35
then
Display (“Prime Number”)
else
Display (“Not a Prime Number ”);
Step 6: Stop.

------x------

CONCLUSION
As you have seen, computers are an exciting addition to the writing
process. Computers are a resource, just as there are many different
writing resources, and should be used as such. They are an undisputedly
important tool to the writer, but you cannot complete a project with just
one tool.

36
BIBLIOGRAPHY
THEORY: APC UNDERSTANDING COMPUTER SCIENCE ISC
CLASS 11 and ‘GOOGLE’.
PROGRAMS: APC UNDERSTANDING COMPUTER SCIENCE ISC
CLASS 11.
‘KNOWLEDGEBOAT’ FROM ‘GOOGLE’.

37
38

You might also like