edited computer project

Upload: abhishek-kumar

Post on 04-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Edited Computer Project

    1/111

    INDEX

    S. no. TOPIC Page no.1 PROGRAM 1 2-82 PROGRAM 2 9-133 PROGRAM 3 14-184 PROGRAM 4 19-225 PROGRAM 5 23-316 PROGRAM 6 32-377 PROGRAM 7 38-428 PROGRAM 8 43-509 PROGRAM 9 51-59

    10 PROGRAM 10 60-6711 PROGRAM 11 68-7012 PROGRAM 12 71-7513 PROGRAM 13 76-7814 PROGRAM 14 79-8215 PROGRAM 15 83-8616 PROGRAM 16 87-9217 PROGRAM 17 93-9718 PROGRAM 18 98-10119 PROGRAM 19 102-10420 PROGRAM 20 105-110

  • 7/30/2019 Edited Computer Project

    2/111

    Question 1- Define a classTWO_D with following data members:

    N=size of the array

    int arr[][]- a square matrix of N X N

    Member functions:

    TWO_D(int nn) : to initialize N=nn and to create matrix.void input( ) : to input matrix elements.

    int has(int y) : returns 1 if y belongs to matrix arr[][] else it returns 0.

    void check( ) : to remove all duplicate elements only single copy should

    be there of each element in matrix and insert new

    element at that position.

    void print( ) : to print the matrix.

    Also write main( ). In main both matrix the original one and after deletion.

    ALGORITHM

    START STEP 1- Input the elements into the square matrix of size 3 as arr[ ][ ].

    STEP 2- Print the matrix.

    STEP 3- Initialize first element of matrix into two variables-max and min which are to

    store smallest and the biggest element of the matrix. STEP 4- Initialize a variable I and assign 0 to it.

    STEP 5- Initialize another variable j and assign 0 to it.

    STEP 6- If [i][j]th element of matrix arr is greater than max, assign the value of that

    element to max.

    STEP 7- If [i][j]th element of matrix arr is smaller than min ,assign the value of that

    element to min.

    STEP 7- Increment js value by 1 and repeat step 6 and 7 as long as it does not

    become 2.

    STEP 8- Increment is value by and repeat from step 6 to 8 as long as it does notbecome 2.

    STEP 8- Initialize a variable m as 0.

    STEP 9- Initialize a variable k as min.

    STEP 10- Initaliaze a variable c as 0.

    STEP 11- Initialize a variable i as 0.

    STEP 12- Initialize a variable j as 0.

    2

  • 7/30/2019 Edited Computer Project

    3/111

    STEP 13- If k is equals to [i][j]th element of the matrix, c is incremented.

    STEP 14- Just when c gets greater than 1, user is asked to input a new number which

    is again checked if its in already in matrix or no through linear search. If the new number

    is already present in the matrix, user is again asked to input any number, not already

    present in the matrix. But if the new number is not in the matrix, the new number isassigned to that [i][j]th position.

    STEP 15- j is incremented by 1 and i4th step is reapeated as long as it does not

    become equals to 2.

    STEP 16- i is incremented by 1 and steps are reapeated from 12 to 15 as long as it

    does not become equals to 2.

    STEP 17- k is incremented by 1 and steps are reapeated from 10 to 16 as long as it

    does not become equals to max.

    STEP 18- m is incremented by 1 and steps are reapeated from 9 to 17 as long as it is

    less than 9.

    STEP 19- Again the matrix is printed in which all duplicate elements are replaced

    with new numbers.

    STOP

    import java.io.*;

    class TWO_D

    { //class startsint arr[][];

    int N; //data members initialized

    TWO_D(int nn)

    { //parametrizes constructor

    N=nn;

    arr=new int[N][N];

    }

    void input()throws IOException

    { //function to enter the elements into the matrix

    BufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));

    System.out.println("enter the elements in the matrix");

    for (int i=0;i

  • 7/30/2019 Edited Computer Project

    4/111

    {

    for (int j=0;j

  • 7/30/2019 Edited Computer Project

    5/111

    for (int m=0;m

  • 7/30/2019 Edited Computer Project

    6/111

    } //function over

    public void print()

    { //function to print the matrix

    for (int i=0;i

  • 7/30/2019 Edited Computer Project

    7/111

    OUTPUT

    enter the elements in the matrix

    11

    22

    33

    11

    22

    33

    1122

    33

    11 22 33

    11 22 33

    11 22 33

    enter a new no.

    22

    enter a new no. not present in matrix121

    enter a new no.

    232

    enter a new no.

    343

    enter a new no.

    454

    enter a new no.

    33enter a new no. not present in matrix

    565

    enter a new no.

    676

    enter a new no.

    7

  • 7/30/2019 Edited Computer Project

    8/111

  • 7/30/2019 Edited Computer Project

    9/111

    Question 2-Consider following inheritance path where Student is base class

    Above classes are showing data members

    Write contructors for passing various attributes for all the three classes and

    Average( ) for the class CommerceStudent and ScienceStudent which returns

    average marks. Also write display( ) for all the three classes to display the data

    members and average too.

    Student

    Name

    Address

    rollno

    CommerceStudentMarksAcc

    MarksEco

    ScienceStudentMarksphy

    MarksMaths

    9

  • 7/30/2019 Edited Computer Project

    10/111

    ALGORITHM

    START STEP 1- Pass values to the data members of sciencestudent as

    "Saumya","Maruti Puram",25,58,52.

    STEP 2- Pas values to the data members of commercestudent as "Bittu","Janki

    Puram",11,78,99.

    STEP 2- In both the above steps, last two values are the marks of two subjects.

    STEP 3- Average marks are calculated for both the objects by dividing the sum

    of marks of both the subjects by 2.

    STEP 4- Details are printed: name, address, roll no., marsk of both subjects and

    their average. STOP

    class mn

    { //main classvoid main()

    { //main function

    Sciencestudent ob=new Sciencestudent("Saumya","Maruti Puram",25,58,52);

    //object created for first derived class

    Commercestudent obc=new Commercestudent("Bittu","Janki Puram"

    ,11,78,99); //object created for second derived class

    ob.display(); //funtion calling

    obc.display();}

    } //main class over

    class Student

    { //begins the base class

    10

  • 7/30/2019 Edited Computer Project

    11/111

    String name;

    String address;

    int rollno; //data memebers intialized

    Student(String u,String v,int w)

    { //parametrized constructorname=u;

    address=v;

    rollno=w;

    }

    void display()

    { // function to display the general details of the student

    System.out.println("name of the student-"+name);

    System.out.println("address-"+address);System.out.println("roll no.-"+rollno);

    }

    } //base class ends

    class Commercestudent extends Student

    { //first derived class begins

    int markseco;

    int marksacc;Commercestudent(String a,String b,int c,int d,int e)

    { //parametrized constructor

    super(a,b,c); //providing values to the base class data members

    marksacc=d;

    markseco=e;

    }

    double average()

    { //function to return the average of the 2 asked sunject marks

    double ave=(markseco+marksacc)/2;return ave;

    }

    void display()

    { //function to display all the details

    super.display(); //prints the general details

    11

  • 7/30/2019 Edited Computer Project

    12/111

    double y=average(); //y holds the average marks

    System.out.println("average marks-"+y);

    } //function over

    } //first derived class over

    class Sciencestudent extends Student

    { //second derived class begins

    int marksphy;

    int marksmaths;

    Sciencestudent(String f,String g,int h,int i,int j)

    { //parametrized constructor

    super(f,g,h); //providing values to the base class data members

    marksphy=i;marksmaths=j;

    }

    double average()

    { //to calculate the average marks of the 2 asked marks

    double ave=(marksphy+marksmaths)/2;

    return ave;

    }

    void display(){ //to display all the details

    super.display(); //display base class data members

    double y=average();

    System.out.println("average marks-"+y);

    }

    } //second derived class over

    12

  • 7/30/2019 Edited Computer Project

    13/111

    OUTPUT

    name of the student-Saumya

    address-Maruti Puram

    roll no.-25

    average marks-55.0

    name of the student-Bittuaddress-Janki Puram

    roll no.-11

    average marks-88.0

    13

  • 7/30/2019 Edited Computer Project

    14/111

    Question 3- Define a classTWO_D with following data members :

    in arr[][]- a square matrix of N X N

    N- size of the array

    Member functions:

    TWO_D(int nn) : to initialize N=nn and to create matrix

    void input( ) : to input matrix elements

    void check( ) : to print the smallest in each row along with the

    matrix.void sort( ) : to sort each row in descending order using any

    sorting technique.

    void print( ) : to print the matrix.

    Also write main( ).

    ALGORITHM

    START

    STEP 1- Create a square matrix of size 4.

    STEP 2- Input elements into the matrix.

    STEP 3- Initialize a variable k as 0.

    STEP 4- Initialize [i][0]th element of the matrix as a variable min.

    STEP 5- Initialize a variable m as 0.

    STEP 6- If [k][m]th element is lesser than min, [k][m]th element is assigned to

    the variable min.

    STEP 7- Increment ms value by 1 and repeat step 6 as long as it is less then 4.

    STEP 8- Increment ks value by 1 and repeat the steps from 4 to 7 as long as it

    is less than 4.

    STEP 9- At the end of each iteration of k loop, the smallest element of [k]th

    row of the matrix is printed.

    14

  • 7/30/2019 Edited Computer Project

    15/111

    STEP 10- Initialize a variable k as 0.

    STEP 9- Initialize a variable i as 0.

    STEP 10- Initialize a variable j as 0.

    STEP 11- If [i][j]th elements is greater than [i][j+1]th element of the matrix,

    they are swapped. STEP 12- Increment js value by 1 and repeat step 11 as long as it is less than 3.

    STEP 13- Increment Is value by 1 and repeat steps from 10 to 12 as long as it

    is less than 4.

    STEP 14- Increment ks value byy 1 and repeat steps from 9 to 13 as long as it

    is less than 4.

    STEP 15- Print the matrix.

    STOP

    import java.io.*;

    class TWO_D1

    { //class starts

    int arr[][];

    int N; // data members initialized

    TWO_D1(int nn)

    { //parametrized constructorN=nn;

    arr=new int[N][N];

    }

    void input()throws IOException

    { //function to input elements in the matrix

    BufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));

    System.out.println("enter the elemets");for (int i=0;i

  • 7/30/2019 Edited Computer Project

    16/111

    }

    void check()

    { //function to print the smallest element in each row

    print(); //function calling to print the elements in the inputted order

    for (int k=0;k

  • 7/30/2019 Edited Computer Project

    17/111

    { //function to print the matrix

    for (int i=0;i

  • 7/30/2019 Edited Computer Project

    18/111

  • 7/30/2019 Edited Computer Project

    19/111

    44 8 6 6

    Question 4- Fractions are numbersand num is the numerator and den is thedenominator and denis not equal to 0. Some of the methods in class Division are

    given below:

    Class Name : Division

    Data members : num and den of integer types.

    Member functions-

    Division(int, int) : constructor, first argument is numerator and

    second argument is denominator.

    int hcf(int, int) : find the hcf of two numbers.int lcm(int, int) : find the lcm(using hcf)

    void reduce( ) : reduce current Division objects to its lowest

    terms e.g. 1000/3000 is 1/3.

    Division addto(Division f) : to add current Division object to Division f and

    return the sum as a Division object. E.g. the sum

    of 2/9 and 5/18 is .

    Also write main( ).

    ALGORITHM

    START STEP 1- From the two numbers, c and d, find the smaller one and store it in

    min. STEP 2- Initialize a variable i as 1 and find the highest number which when

    divides both the number, c and d, leaves no remainder and store it in h.

    STEP 3- Increment is value by 1 and repeat step 2 as long as it is less than

    equals to min.

    STEP 4- Find the lcm by using the formula: lcm=product of two numbers/their

    hcf.

    19

  • 7/30/2019 Edited Computer Project

    20/111

  • 7/30/2019 Edited Computer Project

    21/111

  • 7/30/2019 Edited Computer Project

    22/111

  • 7/30/2019 Edited Computer Project

    23/111

  • 7/30/2019 Edited Computer Project

    24/111

  • 7/30/2019 Edited Computer Project

    25/111

    STOP

    import java.io.*;class main

    { //main class begin

    void diplay()throws IOException

    {

    graduatestudent ob= new graduatestudent(); //base class object is created

    System.out.println();

    System.out.println();

    ob.input();

    ob.print();

    }

    } //main class over

    class person

    { //base class begin

    String name;

    int age,rollno;

    double per; //data members initialized

    void input()throws IOException{ //function to input general details

    BufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));

    System.out.println("enter general details");

    name=in.readLine();

    25

  • 7/30/2019 Edited Computer Project

    26/111

    age=Integer.parseInt(in.readLine());

    rollno=Integer.parseInt(in.readLine());

    per=Double.parseDouble(in.readLine());

    }

    } //base class overclass graduatestudent extends person

    { //derived class begin

    double div; //% of first divisioners

    String subject;

    int s,t; //s is to store the index of top scorer

    int year;

    int employed;

    //various arrays are initialized to store details of 10 detailsString nm[]=new String[10];

    int a[]=new int[10];

    int r[]=new int[10];

    double marks[]=new double[10];

    String sub[]=new String[10];

    void input()throws IOException

    { //function to input details

    t=0; //t holds the no. of working graduatesBufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));

    System.out.println("enter % of first divisioners");

    div=Double.parseDouble(in.readLine());

    System.out.println("enter the year");

    year=Integer.parseInt(in.readLine());

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    27/111

  • 7/30/2019 Edited Computer Project

    28/111

  • 7/30/2019 Edited Computer Project

    29/111

    enter general details

    "Payal"

    10

    12

    99enter employed(1) or not(0)

    0

    enter subject

    "Drawing"

    enter general details

    "Nitika"

    20

    4498

    enter employed(1) or not(0)

    1

    enter subject

    "Accounts"

    enter general details

    "Shruti"

    1840

    88.5

    enter employed(1) or not(0)

    0

    enter subject

    "History"

    enter general details

    "Aparna"

    1022

    66.7

    enter employed(1) or not(0)

    0

    enter subject

    29

  • 7/30/2019 Edited Computer Project

    30/111

    "English"

    enter general details

    "Kavya"

    18

    27100

    enter employed(1) or not(0)

    1

    enter subject

    "Physics"

    enter general details

    "Preeti"

    1334

    99

    enter employed(1) or not(0)

    0

    enter subject

    "GK"

    enter general details

    "Shreya"11

    6

    94.5

    enter employed(1) or not(0)

    0

    enter subject

    "Biology"

    enter general details

    "Shivani"17

    33

    98.5

    enter employed(1) or not(0)

    0

    30

  • 7/30/2019 Edited Computer Project

    31/111

  • 7/30/2019 Edited Computer Project

    32/111

  • 7/30/2019 Edited Computer Project

    33/111

  • 7/30/2019 Edited Computer Project

    34/111

  • 7/30/2019 Edited Computer Project

    35/111

  • 7/30/2019 Edited Computer Project

    36/111

  • 7/30/2019 Edited Computer Project

    37/111

    OUTPUT

    enter the date

    23

    11

    1995

    enter the date

    2310

    2012

    no. of days between 23/11/1995 and 23/10/2012 is 6179

    37

  • 7/30/2019 Edited Computer Project

    38/111

    Question 7- A principal of a school needs to find the highest and the lowest marks

    scored by the student and also the merit list on marks from highest to lowest in a

    class of 10 students. The classes student and meritlist are declared for above

    activities with following details:-

    Class name : student

    Data members/instance variables:

    Tot[10] : (double) an array to store total marks of 10

    students out 500 each.

    Stud[10] : string array to store name of 10 students of a

    Class.

    Rollno[10] : string array to store roll no. of 10 students of

    a class.

    Member function/method:-

    void readdetails( ) : to input names and marks of 10 students.

    Marks are given out of 500 each. And to

    assign rollnos. From 200101 to 200110.

    void printresult( ) : to print students scoring highest and lowest

    marks in the class along with names and

    rollno. of students.

    Class Name : meritlist

    Data members/instance variables : NONE

    Member function/methods:-

    void generatemerit( ) : to generate merit list of 10 students on the

    basis of total marks along with of students.

    38

  • 7/30/2019 Edited Computer Project

    39/111

    void printmerit( ) : to print merit list of 10 students in three

    columns in the following format:

    ROLL NO. NAME MARKS SCOREDXXXX XXXXXX XXXXXX

    XXXX XXXXXX XXXXXX

    XXXX XXXXXX XXXXXX

    ALGORITHM

    STEP 1- Three arrays are created: tot, name and rollno of size 10.

    STEP 2- Initialize a variable c as 200101.

    STEP 3- Initialize a variable i as 0. STEP 4- In each iteration, a name and total marks are inpuuted as [i]th element

    inot arrays tot and name.

    STEP 5 - is value is incremented and step 4 is repeated With each iteration, c is

    assigned as [i]th element into array rollno and then c is incremented by 1. This step is

    performed as long as I is less than 10.

    STEP 6- Initialize a variable i as 0.

    STEP 7- Initialize a variable j as 0.

    STEP 8- It is checked if [j]th element is lesser than [j+1]th element of array tot

    or not. If it is, then [j+1]th element of arrays tot, name and rollno is assigned as [j]th

    element of the arrays and former values of [j]th element of these arrays are assigned to[j+1]th elements of these arrays.

    STEP 9- js value is incremented by and step 8 is repeated as long as it is less

    than 9.

    STEP 10- is value is incremented by 1 and steps are repeated from 7 to 9 as

    long as it is less than 10.

    STEP 8- All three arrays are printed in proper format.

    STEP 9- [0]th and [9]th element of these arrays are printed as highest scorer

    and lowest scorer respectively.

    39

  • 7/30/2019 Edited Computer Project

    40/111

    import java.io.*;

    class main

    { //class starts

    void mn()throws IOException

    { //main functionname ob=new name(); //object created

    ob.readlist();

    ob.generatemerit(); //required functions are called

    }

    } //main class over

    class student

    { //base class startsint tot[]=new int[10];

    String name[]=new String[10];

    int rollno[]=new int[10]; //data members initialized

    void readlist()throws IOException

    { //function to input the details begins

    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

    System.out.println("Enter name,total out of 500");

    int c=200101; //first roll no.for(int i=0;i

  • 7/30/2019 Edited Computer Project

    41/111

    if (tot[j]

  • 7/30/2019 Edited Computer Project

    42/111

    {

    System.out.println(rollno[i]+ "\t\t" +name[i]+ "\t\t" +tot[i]);

    }

    } //function over

    } //derived class over

    OUTPUT

    Enter name, total out of 500

    111

    Saumya222

    Charul

    333

    Deeksha

    444

    Gauri

    121

    Kopal232

    Himani

    343

    Shruti

    12

    Neha

    345

    Aish

    454Aditi

    Highest marks 454 are scored by Aditi having rollno.-200110

    Lowest marks 12 are scored by Neha having rollno.-200108

    ROLL NO. NAME MARKS OBTAINED

    200110 Aditi 454

    42

  • 7/30/2019 Edited Computer Project

    43/111

    200104 Gauri 444

    200109 Aish 345

    200107 Shruti 343

    200103 Deeksha 333

    200106 Himani 232200102 Charul 222

    200105 Kopal 121

    200101 Saumya 111

    200108 Neha 12

    Question 8- Define a class Binary with following data members:

    String n1, n2

    And following member functions:

    Binary( ) :constructor

    int check(String n) : returns 1 if n is a binary number else it returns 0.

    void input( ) : to input 2 binary numbers in n1, n2 with decimals.

    String Dec_to_bin(String h) : to return binary equivalent of h. Eg. If h=5.625

    binary eq=101.101

    String Bin_to_dec(String h) : to retuen decimal equivalent of h. Eg if h=101.101

    decimal eq=5.625void sum( ) : to print sum of n1 and n2 in binary number system

    and decimal number system.

    Eg.

    n1=111.101

    n2=110.01

    Sum in binary number system is 1101.111

    Sum in decimal number system is 13.875

    ALGORITHM

    START STEP 1- Input two strings, n1 and n2 which consists of only numbers.

    43

  • 7/30/2019 Edited Computer Project

    44/111

    STEP 2- Two strings, op1 and op2, are initialized.

    STEP 3- A number is binary only and only if it has 1s, 0s or a decimal(.).

    STEP 4- If a string is a binary number, 1 is returned else 0 is returned.

    STEP 5- Step 4 is performed for n1 and n2 and returned values are stored in x

    and y respectively. STEP 6- If x is 1, n1 is changed into a decimal number and stored in string form

    in op1. Else if x is 0, then n1 is simply assigned in op1.

    STEP 7- If y is 1, n2 is changed into a decimal number and stored in string form

    in op2. Else if y is 0, then n2 is simply assigned in op2.

    STEP 8- op1 and op2 are changed into double type and stored in a and b

    respectively.

    STEP 9- a nd b are added and stored in a variable of double type c.

    STEP 10- Initialize a string to_bin.

    STEP 11- c is changed into string type and stored in to_bin. STEP 12- Initialize a string type variable in_bin. Change the string to_bin into a

    string which has binary equivalent of c and store it in in_bin.

    STEP 13- Print c and in_bin.

    STOP

    import java.io.*;class Binary

    { //class begins

    String n1;

    String n2; //data members initialized

    Binary()

    { //constructor

    n1="";

    n2="";}

    void input()throws IOException

    { //function to provide 2 strings

    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

    System.out.println("enter the two strings");

    44

  • 7/30/2019 Edited Computer Project

    45/111

    n1=in.readLine();

    n2=in.readLine();

    }

    int check(String n)

    { //function to check if the string is binary number or notint c=0;

    int len=n.length();

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    46/111

    System.out.println("given number is not binary");

    }

    else

    {

    int x=0;int len=h.length();

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    47/111

    if(ch==49)

    {

    temp=temp+(1*Math.pow(2,y));

    }

    else if(ch==48)

    {

    temp=temp+(0*Math.pow(2,y));

    }

    y--;

    }

    sum=sum+temp;

    }

    else

    { //if decimal is not there

    int a=Integer.parseInt(h);

    int y=0;

    while(a!=0)

    { sum+=a%10*Math.pow(2,y);

    y++;

    a=a/10;

    }

    }

    }

    String dec="";

    dec=dec.valueOf(sum);

    return dec;} //function over

    String Dec_to_bin(String h)

    { //function to convert decimal no. to binary no.

    String real="";

    int y=check(h);

    47

  • 7/30/2019 Edited Computer Project

    48/111

    if(y==1)

    {

    System.out.println("given string is binary already");

    return "";

    }else

    {

    int x=0;

    int len=h.length();

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    49/111

  • 7/30/2019 Edited Computer Project

    50/111

  • 7/30/2019 Edited Computer Project

    51/111

    Question 9- Define a class trr with following data members:

    trr ar[4][4]

    And following functions:

    void input( ) : to input a 4 X 4 matrix

    void transpose(trr M) : to print transpose of matrix M

    void sum( ) : to print sum of each row and each column and

    primary diagonal and print in following format:

    1 1 1 2 5

    2 2 2 4 7

    1 2 1 2 6

    2 2 3 3 10

    Sum=6 7 7 11 7

    void sort( ) : to sort only border elements in ascending order infollowing format of arr[][].

    If arr[][] is

    1 2 3 4 1 2 3 3

    5 6 7 8 9 6 7 4

    9 1 2 3 8 1 2 4

    51

  • 7/30/2019 Edited Computer Project

    52/111

    4 5 6 7 7 6 5 5

    Also write main( ).

    ALGORITHM

    START STEP 1- Create a square matrix with size of 4.

    STEP 2- Input elements into the matrix

    STEP 4- Initialize a variable i as 0.

    STEP 5- Initialize a variable sum as 0.

    STEP 6- Initialize a variable j as 0.

    STEP 7- [i][j]th element of the matrix is printed and sum is incremented with [i]

    [j]th element.

    STEP 8- j is incremented by 1 and step 7 is repeated as long as it is less than 4.

    STEP 9- i is incremented by 1 and steps 5 to 8 are repeated as long as it is less

    than 4.

    STEP 8- At one repeatition of steps from 5 to 8, sum has the sum of all the

    elements of [i]th row of the matrix which is then printed..

    STEP 9- Initialize a variable i as 0.

    STEP 10- Initialize a variable c_sum as 0. STEP 11- Initialize a variable j as 0.

    STEP 13- c_sum is incremented with [i][j]th element.

    STEP 14- Increment js value by 1 and repeat step 13 as long as it is less than 4.

    STEP 15- Increment is value by 1 and repeat steps 10 to 14 as long as it is less

    than 4.

    STEP 16- At one repeatition of steps from 10 to 12, c_sum has the sum of all

    the elements of [i]th row of the matrix which is then printed.

    STEP 17- Initialize a variable p_sum as 0.

    STEP 18- Initialize a variable as 0.

    STEP 19- p_sum is then incremented with [i][i]th element of the matrix.

    STEP 20- is value is incremented by 1 and step 19 is repeated as long as it is

    less than 4.

    STEP 21An array of 12 elements is created in which all the border elements of

    the matrix are stored.

    STEP 22- Initialize a variable i as 0.

    52

  • 7/30/2019 Edited Computer Project

    53/111

  • 7/30/2019 Edited Computer Project

    54/111

    {

    for(int j=0;j

  • 7/30/2019 Edited Computer Project

    55/111

    System.out.print(c_sum+"\t");

    }

    int p_sum=0;

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    56/111

  • 7/30/2019 Edited Computer Project

    57/111

    }

    //border elements done

    for(int i=1;i

  • 7/30/2019 Edited Computer Project

    58/111

  • 7/30/2019 Edited Computer Project

    59/111

    11

    22

    33

    44

    5566

    77

    88

    99

    99

    88

    77

    6655

    44

    33

    1 2 3 4 10

    5 6 7 8 26

    9 9 8 7 336 5 4 3 18

    21 22 22 22 18

    1 2 3 3

    9 6 7 4

    8 9 8 4

    7 6 5 5

    11 22 33 44

    55 66 77 88

    99 99 88 77

    66 55 44 33

    59

  • 7/30/2019 Edited Computer Project

    60/111

    11 55 99 66

    22 66 99 55

    33 77 88 44

    44 88 77 33

    Question 10Design a program to accept a day number (between 1 and 366), year

    (4 digits) from the user to generate and display the corresponding date. Also accept

    N (1

  • 7/30/2019 Edited Computer Project

    61/111

    STEP 5- Initialize an integer variable m as 2 which would be used later for

    calculation of the month of the date

    STEP 6- If s would less than or equals to 31 then mns value would be 1 and

    dds value would be s itself.

    STEP 7- If s is greater than 31 and less than or equals to 59 and the year is nota leap year or if s is greater than 31 and less than or equals to 60 and the year is a leap

    year then dd would be 31 less day_no and mns value is 2

    STEP 8- If s is greater than 59 and its not a leap year then s would be 59 less s

    and then a loop is created which is iterated as long as s is greater than or equal to 31.

    In each iteration, ss vaule is decremented by 31 (as maximum number of days in a

    month is 31) and ms value is incremented by 1.

    STEP 9- If s is greater than 60 and its a leap year then s would be 60 less s and

    then a loop is created which is iterated as long as s is greater than or equal to 31. In

    each iteration, ss vaule is decremented by 31 (as maximum number of days in a

    month is 31) and ms value is incremented by 1.

    STEP 10- If m is greater than 3 and less than oe equals to 5 then xs value is 1

    STEP 11- If m is greater than 5 and less than or equals to 8 then xs value is 2.

    STEP 12- If m is greater than 8 and less than equals to 10 then xs value is 3.

    STEP 13- If m is greater than 10 the n xs value is 4.

    STEP 14- Final value of dd would be sum of ss value and xs value and mns

    value is one more than ms value.

    STEP 15- Create a String array arr whose size is 13.

    STEP 16- Keep the first value of arr empty and then sequentially assign all

    twelve months names between elements os index no. 1 and 12.

    STEP 17- Initialize a String variable suf which would store the suffix to be

    written after after the day.

    STEP 18- If dd lies between 11 and 19 then sufs value is th, else if dds last

    digit is 1 then suf value is st, else if dds last digit is 2 then sufs value is nd, else

    if dds last digit is 3 then sufs value is rd and in all other conditions sufs value is

    th.

    STEP 19- Print dd followed by suf, then a space followed by the mnth

    element of the array arr and again a space followed by year.

    STEP 20- A new integer variable nday_no is initialized which is the sum of

    day_no and N.

    STEP 21- If year is a leap year and nday_no is greater than 366 then nday_no

    is 366 less than nday_no but if is not a leap year and nday_no is greater than 365 then

    nday_no is 365 less than nday_no. In both the cases, year is incremented by 1.

    STEP 22- Now all the steps from step no.2 till 19 are repeated.

    61

  • 7/30/2019 Edited Computer Project

    62/111

    STOP

    import java.io.*;

    class calc

    {//class started

    int N;

    int day_no;

    int year; //data members initialized

    calc()

    { //default constructor

    N=0;

    day_no=0;

    year=0;} //constructor over

    void input()throws IOException

    { //function to input values to data members

    BufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));

    62

  • 7/30/2019 Edited Computer Project

    63/111

  • 7/30/2019 Edited Computer Project

    64/111

    int s=days; //initialising day no. as 's'

    if (yr%4==0)

    { //when its a leap year:

    if(s31)&&(s60)

    { //when day no. is greater than 60:

    s=s-60; //subtracting first 60 days of the year

    while(s>=31)

    { //31 as maximum no. of days in a month can be 31 only

    s=s-31;

    m++;

    }//calculating extra days as per the months

    if((m>3)&&(m5)&&(m8)&&(m10)

    64

  • 7/30/2019 Edited Computer Project

    65/111

    {

    x=4;

    }

    dd=s+x; //day of the date would also include extra days

    mn=m+1; //month of the date would be one more than the calculated as'm'

    }

    } //all probable conditions for the date in the leap year checked

    else if(yr%4!=0)

    { //same conditions would be checked to calculate the date in an year which

    is not a leap year

    if(s31)&&(s59)

    { //59 as in a normal year total no. of days in first two months is 59

    s=s-59;

    while(s>=31)

    {

    s=s-31;

    m++;

    }

    if((m>3)&&(m5)&&(m

  • 7/30/2019 Edited Computer Project

    66/111

    x=2;

    }

    else if((m>8)&&(m10)

    {

    x=4;

    }

    dd=s+x;

    mn=m+1;

    }}

    String arr[]={"", "January", "February", "March", "April", "May", "June",

    "July","August", "September", "October", "November",

    "December"}; //array of all the months such a way that the

    index number is the month number of the year

    String suf=""; // 'suf' is the variable for the suffix after the day

    if((dd>=11)&&(dd

  • 7/30/2019 Edited Computer Project

    67/111

  • 7/30/2019 Edited Computer Project

    68/111

    OUTPUT

    enter limit such that 1

  • 7/30/2019 Edited Computer Project

    69/111

    START STEP 1- Input a value to data member limit.

    STEP 2- If n is equal to c, then return 1. Else if n is equals to 1 or on being

    divided by c leaves no remainder then return 0. If above two values are not satisfied

    then this step is again repeated with variables n remaining the same and (c+1) actingas new c.

    STEP 3- If m is equals to 0 then s is returned else remainder of m on being

    divided by 10 is stored in a new variable r, s is multiplied by 10 and then to it is added

    r and this value is again stored in s, and then this step is repeated with (m/10) acting as

    new m.

    STEP 4- Initialize a variable i as 0.

    STEP 5- Assign 0 as value to data member s.

    STEP 6- Step 1 is repeated with variables i and 2 and returned value is stored in

    a new variable x.

    STEP 7- Step 2 is repeated with i acting as m and returned value is stored in anew variable y.

    STEP 8- If y is equals to i and x is 1, then print i.

    STEP 9- Increment is value by 1 and repeat steps from 5 to 8 as long as it is

    less than or equals to limit.

    STOP

    import java.io.*;class Number

    { //class began

    int limit,s;

    Number(int l)

    { //constructor

    limit=l;

    s=0;

    }int prime(int n,int c)

    { //recursive function to see if the no. is prime or not

    if(n= =c)

    {

    return 1;

    69

  • 7/30/2019 Edited Computer Project

    70/111

    }

    else if((n%c= =0)||(n= =1))

    {

    return 0;

    }else

    {

    return prime(n,c+1); //repeating the same function

    }

    }

    int reverse(int m)

    { //function to return the reverse of the no.

    if(m= =0){

    return s;

    }

    else

    {

    int r=m%10;

    s=s*10+r;

    return reverse(m/10);}

    }

    void print()

    { //to print prime palindrome no. bet 1 and limit

    System.out.println("prime palindrome numbers between 1 to "+limit);

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    71/111

    }

    }

    void main()

    { //function to call the print function

    print();}

    } //class over

    OUTPUT

    prime palindrome numbers between 1 to 100

    2

    3

    5

    7

    11

    Question 12- NIC institutes resource manager has decided to network thecomputer resources like printer, storage media etc, so that minimum resources

    and maximum sharing could be availed. Accordingly printers are linked to a

    centralized system and the printing jobs are done on a first cum first served

    basis only. This is like the first persons job will get done first and the next

    persons job will be done as the next job in the list and so on. In order to avoid

    collision, the restriction is that no more than 20 printing jobs can be added.Define the class PrintJob with the following detail:

    Class name : PrintJobData members/instance variable:job[] : array of integers to hold the printing jobs.

    newjob : to add a new printing job into the array.

    capacity : the maximum capacity of the integer array.

    front : to point to the index of the frony.

    71

  • 7/30/2019 Edited Computer Project

    72/111

    rear : to point to the index of the last.

    Member functions:

    PrintJob( ) : constructor to initialize the data member

    capacity=20, front=rear= -1 and call thefunction creatjob( ).

    void createjob( ) : to create an array to hold the printing jobs.

    void addjob( ) : adds the new printing job to the end of the last

    printing job, if possible, otherwise displays

    the message Printjob is full, cannot add any

    more.

    void removejob( ) : removes the printing job from the front if the

    printing job is not empty, otherwise displaysthe message Printjob is empty.

    Also write main( ) for above class.

    ALGORITHM

    START

    STEP 1- Create an array of size 20.

    STEP 3- If rears value is 19 a message is printed Printjob is full,cannot add

    more" else rear is incremented by 1 and newjob is assigned as the value of [rear]th

    element of the array and if fronts value is -1 then its incremented.

    STEP 4- If fronts value is -1, a message is printed Printjob is empty. elsefronts value is incremented.

    STEP 5- Now user is asked to input either 1 or 2 or 3.

    STEP 6- If its 1 then step 3 is performed, else if its 2 step 4 is performed. Else if

    its 3, array is printed. If user gives any other input than these 3, a message is

    displayed- wrong input.

    STEP 7- Step 5 and 6 are continued as long as user does not input 3.

    72

  • 7/30/2019 Edited Computer Project

    73/111

    STOP

    import java.io.*;

    class printjob{ //class begin

    int job[];

    int newjob;

    int capacity;

    int front;

    int rear; //data members initialized

    printjob()throws IOException

    { //constructor

    capacity=20;

    front=-1;

    rear=-1;

    job=new int[capacity];

    createjob();

    }

    void createjob()throws IOException

    { //function to input values into the array

    job=new int[20];} //function ends

    void addjob()throws IOException

    {

    if(rear= =19)

    {

    System.out.println("Printjob is full,cannot add more");

    }

    else{

    BufferedReader in= new BufferedReader(new

    InputStreamReader(System.in));

    System.out.println("enter the printjob");

    int x=Integer.parseInt(in.readLine());

    73

  • 7/30/2019 Edited Computer Project

    74/111

  • 7/30/2019 Edited Computer Project

    75/111

  • 7/30/2019 Edited Computer Project

    76/111

    2

    enter choice

    enter 1 to input

    enter 2 to delete

    enter 3 to display and exit3

    wrong input

    Question 13- Define a class Recursion with following data members

    String str

    Int v, w

    And following functions:

    Recursion( ) : constructor.

    void accept( ) : to input any string.

    void count(int ) : to count number of words starting with a

    vowel in str and store in data member v andnumber of words in w using recursion.

    void display( ) : to print number of words starting with vowels

    and words in str.

    Also write main( ).

    76

  • 7/30/2019 Edited Computer Project

    77/111

    ALGORITHM

    START STEP 1- Initialize three data members- string type str and two integer types v

    and w.

    STEP 2- Calculate the length of str and store it in a variable l.

    STEP 3- Begin this step with i as 0. As long as i is less than l, we extract out the

    [i]th character of str and store it in ch. If ch is any vowel then v is incremented by 1

    else if ch is a space then w is incremented by 1 and again this step is repeated with

    (i+1) acting as new i.

    STEP 4- (w+1) is the no. of words in str which are printed and v is number of

    words starting with vowel which is again printed.STOP

    import java.io.*;

    class recursion

    { //class begin

    String str;

    int v,w; //data members initialized

    recursion()

    { //constructorstr="";

    v=0;

    w=0;

    }

    void accept()throws IOException

    77

  • 7/30/2019 Edited Computer Project

    78/111

  • 7/30/2019 Edited Computer Project

    79/111

    } //class over

    OUTPUT

    enter the string

    "Saumya is a good boy"

    no. of words 5no. of words starting with vowels 2

    Question 14- Define a class unique with following data members:

    int arr[10]

    And following methods:

    void input( ) : to input 10 integers in arr.

    int check(int n) : returns 1 if n is a unique no. else it returns 0.

    A unique no. is a no. whose all the digits are

    different (eg. 1273 is unique but 121 is notunique.)

    void print( ) : to print the original array and then print all the

    unique numbers in the array with proper

    messages.

    Also write main( ).

    79

  • 7/30/2019 Edited Computer Project

    80/111

  • 7/30/2019 Edited Computer Project

    81/111

    { //function to input all ten elements in an array

    BufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));

    System.out.println("enter all the 10 elements of the array");

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    82/111

  • 7/30/2019 Edited Computer Project

    83/111

  • 7/30/2019 Edited Computer Project

    84/111

    ALGORITHM

    START

    STEP 1- Create three objects ob1 with argument 5, ob2 with argument 10 andob3 with argument 0.

    STEP 2- Input elements into the array of object ob1 and then print it.

    STEP 3- Input elements into the array of object ob2 and then print it.

    STEP 4-Initialize 0 as value of a new variable x.

    STEP 5- Create a loop from 0 to 4.

    STEP 6- Assign [i]th element of the array of object ob1 as value of [x]th

    element of the array of object ob3.

    STEP 7- x is incremented by 1.

    STEP 8- Create a loop from 0 to 9. STEP 9- Assign [i]th element of the array of object ob2 as value of [x]th

    element of the array of object ob3.

    STEP 10- x is incremented by 1.

    STEP 11- Print the array of object ob3.

    STOP

    import java.io.*;

    class array

    { //class begin

    int a[];

    int size; //data members initialized

    array(int n){ //parametrized constructor

    size=n;

    a=new int[size];

    }

    void input()throws IOException

    84

  • 7/30/2019 Edited Computer Project

    85/111

  • 7/30/2019 Edited Computer Project

    86/111

  • 7/30/2019 Edited Computer Project

    87/111

  • 7/30/2019 Edited Computer Project

    88/111

  • 7/30/2019 Edited Computer Project

    89/111

  • 7/30/2019 Edited Computer Project

    90/111

    for(int m=0;m

  • 7/30/2019 Edited Computer Project

    91/111

  • 7/30/2019 Edited Computer Project

    92/111

    } //function ends

    } //class over

    OUTPUT

    enter the elements

    12

    3

    4

    5

    enter the elements

    92

  • 7/30/2019 Edited Computer Project

    93/111

    6

    7

    8

    9

    1011

    2 4 6 8 10

    enter the elements

    1

    2

    2

    2

    31 2 3

    Question 17- Define a class pattern with following data members and functions:

    int size, int arr[ ][ ]

    void input( ) : to input size(>=3) and to create array.

    void print( ) : to generate following matrix.

    If n is odd If n is even

    If n=5 o/p if n=4 o/p

    4 2 1 3 5 1234

    93

  • 7/30/2019 Edited Computer Project

    94/111

    9 7 6 8 10

    14 12 11 13 15 4123

    19 17 16 18 20

    24 22 21 23 25 3412

    2341

    ALGORITHM

    START

    STEP 1- Input a number as size

    STEP 2- Create a matrix of that size.

    STEP 3- If value of size is an odd then then initialize 1 as value of a new

    variable y.

    STEP 4- Find the middle of the size as x.

    STEP 5- Start assigning values from middle of each row.

    STEP 6- But if size is even values are assigned from the [i][i]th position where I

    varies from 0 to the size.STOP

    import java.io.*;

    class pattern

    { //class started

    int size; //data member for the size of the array

    int arr[][]; //data member for the array

    pattern()

    { //constructor

    size=0;

    94

  • 7/30/2019 Edited Computer Project

    95/111

    }

    void input()throws IOException

    { //function to input the value of size

    BufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));System.out.println("enter any number greater than 3");

    size=Integer.parseInt(in.readLine());

    arr=new int[size][size]; //creates the array of size 'size'

    } //function ends

    void print()

    { //function to assign values in the matrix

    if(size%2!=0)

    { //if the size of the array is an odd numberint y=1; //first element in the matrix

    int x=size/2; //middle point array

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    96/111

    }

    }

    else if(size%2= =0)

    { //if the size of the array is an even number

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    97/111

  • 7/30/2019 Edited Computer Project

    98/111

    34 32 30 29 31 33 35

    41 39 37 36 38 40 42

    48 46 44 43 45 47 49

    enter any number greater than 3

    41234

    4123

    3412

    2341

    Question 18- A class arithmetic is defined to perform arithmetic operation on

    the expression given. The expression given contains only one operator(+, -, *

    or /). The expression should be input as a string and the output should be a

    number. Assume that only integer constants and an operator is given as theexpression. E.g. INPUT 10*7

    OUTPUT 70

    The description of the class is given below:

    Class name : arithmetic

    Data members : String expr, double result

    98

  • 7/30/2019 Edited Computer Project

    99/111

  • 7/30/2019 Edited Computer Project

    100/111

    STEP 14- If chs Unicode value is 42, then product of a and b is stored in result.

    STEP 15- If chs Unicode value is 47, then a is divided by b and its quotient is

    stored in result.

    STEP 16- Result is then printed.

    STOP

    import java.io.*;

    class arithmetic

    { //class starts

    String expr;

    double result; //data membersvoid accept()throws IOException

    { //function to input values to data members

    BufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));

    System.out.println("enter a string containing digits and any of the arithmetic

    operators only");

    expr=in.readLine();

    }void calculate( )

    { //function to calculate the result from mathematical expression

    char ch=' '; //to store the arithmetic operator

    int x=0; //to store the index of the arithmetic operator in the string

    expression

    int len=expr.length(); //to store the length of string expression

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    101/111

    break; //stops the iteration once operator is found

    }

    }

    String op1=expr.substring(0,x); //stores first half of the expression as op1

    String op2=expr.substring(x+1); //stores the second half of the expression asop2

    double a=Double.parseDouble(op1); //op1 is converted into double type as a

    double b=Double.parseDouble(op2); //op2 is converted into double type as

    b

    int c=0;

    c=(int) ch; //stores the unicode value of the operator

    if (c==43)

    { //unicode value of + is 43result=a+b;

    }

    else if(c==45)

    { //unicode value of - is 45

    result=a-b;

    }

    else if(c==42)

    { //unicode value of * is 42result=a*b;

    }

    else if(c==47)

    { //unicode value of / is 47

    result=a/b;

    }

    } //function ends with the final value of result

    void print()

    { //function to display the string expression and the resultcalculate(); //function is called

    System.out.println("the expression given by the user "+expr); //string

    expression is displayed

    System.out.println(result); //result is displayed

    } //function ends

    101

  • 7/30/2019 Edited Computer Project

    102/111

    void main()throws IOException

    { //main function

    accept(); //input function is called

    print(); //print function is called

    } //main function ends} //class ends

    OUTPUT

    enter a string containing digits and any of the arithmetic operators only

    122/4

    the expression given by the user 122/4

    30.5

    Question 19- Define a class Number with following specifications:

    Data members:

    int limit, (you can assume other data members also)

    Member functions:

    Number( ) : constructor to initialize limit=0.

    Number(int L) : constructor to initialize limit=L.

    int length(int n) : returns length of number n. Using recursion.

    102

  • 7/30/2019 Edited Computer Project

    103/111

  • 7/30/2019 Edited Computer Project

    104/111

    { //parametrized constructor

    limit=L;

    }

    int length(int n)

    { //function to return the number of digits to nif(n/10==0)

    {

    return 1;

    }

    else

    { //returns(1+calls again to the function)

    return(1+length(n/10));

    }} //function ends

    int power(int h)

    { //function to return 10 to power h

    if(h==1)

    { //when 10 to power is 1,the number is 10 itself

    return 10;

    }

    else{ //else the number is 10*(calls the function again(h-1))

    return(10*power(h-1));

    }

    } //function ends

    void automorphic()

    { //function to check if the number is automorphic or not

    for(int i=1;i

  • 7/30/2019 Edited Computer Project

    105/111

    }

    }

    } //function ends

    void main()

    { //main functionNumber ob=new Number(100); //object is created with an arguement

    ob.automorphic(); //automorphic function is called

    } //function ends

    } //class ends

    OUTPUT

    1

    5

    6

    2576

    Question 20- Define a class Matrix with following specifications:

    Data members:

    int arr[ ][ ] a matrix of 3 X 3.

    Member functions:

    void input( ) : to input a 3X3 matrix.

    Matrix multiplication(Matrix M1) : to return multiplication of matrix M1

    and current matrix object.

    105

  • 7/30/2019 Edited Computer Project

    106/111

    Matrix sort(Matrix M1) : to sort each row of matrix M1 in

    ascending order using selection sort and

    returns it.

    void print( ) : to print the matrix.

    Write main( ) for above class.

    ALGORITHM

    START

    STEP 1- Create three matrices. STEP 2- For first two matrices, the size is 3.

    STEP 3- Values are inputted into the matrices and then printed.

    STEP 4- Initialize a variable k as 0.

    STEP 4- Initialize a variable i as 0.

    STEP 5- 0 is initialized as a value of new integer variable sum.

    STEP 6- Initialize a variable j as 0.

    STEP 7- sum is incremented with product of [k][j]th element of first matrix and

    [j][i]th element of second matix.

    STEP 8- Increment js value by 1 and repeat step 7 as long as it is less than 3.

    STEP 9- sums value is assigned to the [k][i]th element of third matrix.

    STEP 10- Increment is value by 1 and repeat steps from 5 to 9 as long as it is

    less than 3.

    STEP 11- Increment ks value by 1 and repeat steps from 4 to 10 as long as it is

    less than 3.

    STEP 12- Third matrix is printed.

    STEP 13- Initialize a variable i as 0.

    STEP 14- Selection sort of [i]th row of first matrix is performed

    STEP 15- Increment is value by 1 and repeat step 14 as long as it is less than 3.

    STEP 16- Print this sorted matrix.STOP

    106

  • 7/30/2019 Edited Computer Project

    107/111

    import java.io.*;

    class matrix

    { //class begins

    int arr[][]=new int[3][3]; //matrix is created

    void input()throws IOException{ //values are inputted into the matrix

    BufferedReader in=new BufferedReader(new

    InputStreamReader(System.in));

    System.out.println("enter elements into the matrix");

    for(int i=0;i

  • 7/30/2019 Edited Computer Project

    108/111

    int sm=m1.arr[i][j];

    int pos=j;

    for(int k=j+1;km1.arr[i][k]){

    sm=m1.arr[i][k];

    pos=k;

    }

    }

    int t=m1.arr[i][j];

    m1.arr[i][j]=m1.arr[i][pos];

    m1.arr[i][pos]=t; //swapping done} //selection sort done

    }

    return m1; //object is returned

    } //function over

    matrix multiplication(matrix m1)

    { //function to multiply curent matrix matrix and M1 and then return it

    matrix obj=new matrix();

    for(int k=0;k

  • 7/30/2019 Edited Computer Project

    109/111

    { //main function

    matrix ob1=new matrix(); //first object

    matrix ob2=new matrix(); //second object

    matrix ob3=new matrix(); //third object

    matrix ob4=new matrix(); //fourth objectob1.input();

    ob1.print();

    ob2.input();

    ob2.print();

    ob3=ob1.multiplication(ob2);

    System.out.println("multiplication of two matrices:");

    ob3.print();

    ob4=sort(ob1);System.out.println("sorted matrix");

    ob4.print();

    } //function over

    } //class ends

    OUTPUT

    enter elements into the matrix1

    5

    0

    11

    33

    109

  • 7/30/2019 Edited Computer Project

    110/111

    55

    67

    99

    3

    1 5 0

    11 33 55

    67 99 3

    enter elements into the matrix

    11

    55

    88

    4477

    1

    5

    8

    6

    11 55 88

    44 77 15 8 6

    multiplication of two matrices:

    231 440 93

    1848 3586 1331

    5108 11332 6013

    sorted matrix

    0 1 511 33 55

    3 67 99

    110

  • 7/30/2019 Edited Computer Project

    111/111