Computer
Project
By Manasvi Gupta
ACKNOWLEDGEMENT
I would like to thank my
teachers and friends for
motivating me to complete this
project. Special gratitude to my
Computer teacher Mr. Sarfarz Sir
for providing the guidelines of
the project and solving all my
queries regarding this project.
Thank you.
gghh
bbn
nhjjh
Define a class matrix to sort and determine the largest and the
smallest element with the following details:
Data members/ Instance variables
Mat[][]: an integer array to store the elements
int r, int c : to store size of an array
Member Functions:
Matrix( int m ,int n): Constructor to initialize instance variable
and create array.
void read() : input elements of array
void sort(Matrix A): sorts the elements present in Matrix A in
ascending order and stores the rest in mat of current object
void display(): print mat in form of matrix
Also define the main function to initiate the above tasks.
import java.util.Scanner;
public class Matrix
{
int Mat[][]; int r, c;
Matrix(int m , int n)
{
r=m;
c=n;
Mat = new int [r][c]; }
void read()
{
Scanner sc = new Scanner (System .in);
for (int i =0; i<r; i++)
{ System.out.println(“ ENTER ELEMENTS”);
Mat[i][j]= sc.nextInt();
}}
void sort()
{
int arr[]= new int [A.r * A.c];
Int k =0;
for(int i = 0; i<A.r;i++)
for( int j=0; j<A.c;j++)
arr[k++]=A mat[i][j];
int n =A.r*A.c;
for(int i =0;i<n-1;i++)
for(int j =0; j<n-1;j++)
If (arr[j]>arr{j+1])
{int temp= arr[j];
arr[j] =arr[j+1];
arr[j+1]= temp;}int k=0;
for(int i=0; i<A.r;i++)
for(int j =0; j <A.c;j++)
this Mat[i][j]= arr[k++];
this.r= A.r;
this.c= A.c;
}
void display()
{
for(int i= 0;i <r ; i++)
{ for (int j= 0; j<c ; j++)
System.out. println(Mat[i][j]);
{System.out.println();
}}
public static void()
{Matrix A= new Matrix(5,4);
A.read();
System.out. println(“Original Matrix”);
A.display();Matrix B= new Matrix(3,4); B.sort(A);
System.out. println(“Arranged Matrix”);
B.display();
}}
ALGORITHM:
Step 1: Start
Step 2:
Step 3:
Step 4:
A class no. has been defined to find the frequency of the following of each digit present in
the number, sum of digits at even numbered position and to display results
Class Name : Number
Data Members/ Instance Variables :
Num: long integer type
Member function
Number( ): default constructor
Number(long n): parameterized constructor to initialize num
void digitfrequency (): to find the frequency of each digit present in the number and display
it.
void sumdigit(): to find the sum of digits at even numbered position (with unit place).
Also define the main function .
import java.util.Scanner;
public class Number{
Long num;
 computer Science project.pdf

computer Science project.pdf

  • 1.
  • 2.
    ACKNOWLEDGEMENT I would liketo thank my teachers and friends for motivating me to complete this project. Special gratitude to my Computer teacher Mr. Sarfarz Sir for providing the guidelines of the project and solving all my queries regarding this project. Thank you.
  • 3.
  • 4.
    Define a classmatrix to sort and determine the largest and the smallest element with the following details: Data members/ Instance variables Mat[][]: an integer array to store the elements int r, int c : to store size of an array Member Functions: Matrix( int m ,int n): Constructor to initialize instance variable and create array. void read() : input elements of array void sort(Matrix A): sorts the elements present in Matrix A in ascending order and stores the rest in mat of current object void display(): print mat in form of matrix Also define the main function to initiate the above tasks.
  • 5.
    import java.util.Scanner; public classMatrix { int Mat[][]; int r, c; Matrix(int m , int n) { r=m; c=n; Mat = new int [r][c]; } void read() { Scanner sc = new Scanner (System .in); for (int i =0; i<r; i++) { System.out.println(“ ENTER ELEMENTS”); Mat[i][j]= sc.nextInt(); }} void sort() {
  • 8.
    int arr[]= newint [A.r * A.c]; Int k =0; for(int i = 0; i<A.r;i++) for( int j=0; j<A.c;j++) arr[k++]=A mat[i][j]; int n =A.r*A.c; for(int i =0;i<n-1;i++) for(int j =0; j<n-1;j++) If (arr[j]>arr{j+1]) {int temp= arr[j]; arr[j] =arr[j+1]; arr[j+1]= temp;}int k=0; for(int i=0; i<A.r;i++) for(int j =0; j <A.c;j++) this Mat[i][j]= arr[k++]; this.r= A.r; this.c= A.c; } void display()
  • 9.
    { for(int i= 0;i<r ; i++) { for (int j= 0; j<c ; j++) System.out. println(Mat[i][j]); {System.out.println(); }} public static void() {Matrix A= new Matrix(5,4); A.read(); System.out. println(“Original Matrix”); A.display();Matrix B= new Matrix(3,4); B.sort(A); System.out. println(“Arranged Matrix”); B.display(); }} ALGORITHM: Step 1: Start Step 2: Step 3: Step 4:
  • 11.
    A class no.has been defined to find the frequency of the following of each digit present in the number, sum of digits at even numbered position and to display results Class Name : Number Data Members/ Instance Variables : Num: long integer type Member function Number( ): default constructor Number(long n): parameterized constructor to initialize num void digitfrequency (): to find the frequency of each digit present in the number and display it. void sumdigit(): to find the sum of digits at even numbered position (with unit place). Also define the main function . import java.util.Scanner; public class Number{ Long num;