Friday, August 16, 2024

2nd CSE R23 JAVA DAY TO DAY LAB/CLASS SOLUTIONS

 java tools

-------------------

javac

java

javap

appletviewer

javah

jdb

javadoc

// rect program

class Rect

{

    int len,bre;

    void get(int l,int h)

    {

        len=l;

        bre=h;

    }

    void area(){

        System.out.println("Area ="+len*bre)

    }

public static void main(String a[])

    {

        Rect r=new Rect();

        r.area();

        r.get(10,11);

        r.area();

    }

    

}

-------------------------17-8-24

import java.lang.Math;




public class Main

{

    public    static double PI=3.14F;

public static void main(String[] args) {

System.out.println(Math.sqrt(4));

System.out.println(Math.ceil(4.3));

System.out.println(Math.floor(4.3));

System.out.println(PI);

}

}

2.0

5.0

4.0

3.140000104904175

--------------------------------------------------------

import java.lang.Math;


class A{

    final void dis(){}

    

}

class B extends A

{

    void dis(){}

}



output:

Main.java:10: error: dis() in B cannot override dis() in A

    void dis(){}

         ^

  overridden method is final

1 error


-----------------------------------------------------

import java.lang.Math;


final class A{

     void dis(){}

    

}


class B extends A

{

    void dis(){}

}





public class Main

{

    public static void main(String[]a)

    {

    B bobj=new B();

    bobj.dis();

}

}


output:


Main.java:8: error: cannot inherit from final A

class B extends A

                ^

1 error



java tools

-------------------

javac

java

javap

appletviewer

javah

jdb

javadoc

// rect program

class Rect

{

    int len,bre;

    void get(int l,int h)

    {

        len=l;

        bre=h;

    }

    void area(){

        System.out.println("Area ="+len*bre)

    }

public static void main(String a[])

    {

        Rect r=new Rect();

        r.area();

        r.get(10,11);

        r.area();

    }

    

}

-------------------------17-8-24

import java.lang.Math;




public class Main

{

    public    static double PI=3.14F;

public static void main(String[] args) {

System.out.println(Math.sqrt(4));

System.out.println(Math.ceil(4.3));

System.out.println(Math.floor(4.3));

System.out.println(PI);

}

}

2.0

5.0

4.0

3.140000104904175

--------------------------------------------------------

import java.lang.Math;


class A{

    final void dis(){}

    

}

class B extends A

{

    void dis(){}

}



output:

Main.java:10: error: dis() in B cannot override dis() in A

    void dis(){}

         ^

  overridden method is final

1 error


-----------------------------------------------------

import java.lang.Math;


final class A{

     void dis(){}

    

}


class B extends A

{

    void dis(){}

}





public class Main

{

    public static void main(String[]a)

    {

    B bobj=new B();

    bobj.dis();

}

}


output:


Main.java:8: error: cannot inherit from final A

class B extends A

                ^

1 error


--------------inheritance-----------

import static java.lang.System.out;

class Student{

protected int sno;

protected String sname;

public Student() {

sno=10;

sname="xyz";

out.println("Student()");

}

public Student(int sn,String snm) {

sno=sn;

sname=snm;

out.println("Student(int,String)");

}

}

class Mpc extends Student{

private int maths,phy,che;

public Mpc() {

maths=phy=che=40;

out.println("Mpc()");

}

public Mpc(int sn,String snm,int m,int p,int c) {

super(sn,snm);

maths=m;phy=p;che=c;

out.println("Mpc(int,int,int)");

}

public void dis() {

out.println(sno+"\t"+sname);

out.println(maths+"\t"+phy+"\t"+che);

}

}


public class InheritanceTest {


public static void main(String[] args) {

Mpc m=new Mpc();

m.dis();

Mpc m1=new Mpc(101,"Raj",90,80,77);

m1.dis();

}


}


Output :

Student()

Mpc()

10 xyz

40 40 40

Student(int,String)

Mpc(int,int,int)

101 Raj

90 80 77


------------call by val --------------

class Swap{

    int x,y;

    

    public Swap(int a,int b){

        x=a;

        y=b;

    }

    public void swapval(){

        int tmp;

        tmp=x;x=y;y=tmp;

    }

    public void disval(){

        System.out.println("x="+x+"  y="+ y);

    }

}

public class CallByVal

{

public static void main(String[] args) {

int L=10,M=20;

Swap s=new Swap(L,M);

s.disval();

s.swapval();

System.out.println(L+"\t\t"+M);

}

}

---------------------- menu program--------------------

import java.util.Scanner;

class Account{

    int ano;

    double amt;

    public void addacc(int a,double amt){

        ano=a;

        this.amt=amt;

    }

    public void dis(){

        System.out.println(ano+"\t\t"+amt);

    }

    public void credit(double cr){

        amt+=cr;

    }

}

public class Main

{

public static void main(String[] args) {

    Account a=new Account();

    String ch;

    int cho;

    Scanner in=new Scanner(System.in);

    while(true){

    System.out.println("1  add account");

System.out.println("2  dis account");

System.out.println("3  credit amount");

System.out.println("0  EXIT");

System.out.println("Choice?");

ch=in.nextLine();

cho=Integer.parseInt(ch);

switch(cho){

    case 1:

        a.addacc(1001,10000.5);

        break;

    case 2:

        a.dis();

        break;

    case 3: a.credit(1000); break;

    case 0: System.exit(0);

    }

    

}

    }

}

-------------------------------------------------------------








Thursday, August 31, 2023

LINKS FOR MINI PROJECTS & GOOGLE CLASS ROOM LINKS FOR CPP

 

LINKS FOR C/CPP/JAVA/PYTHON MINI PROJECTS

 

The following are the links for Google class room:

Google Class Room Code for CSE-2 & 3 :  2d3wu5q

https://classroom.google.com/c/MTIyOTE2NTA2NDUy?cjc=2d3wu5q

 

Google Class Room Code for CSE-2 & 3 :  pe2eeyh

https://classroom.google.com/c/MTIyOTE2NTA2NDYy?cjc=pe2eeyh

 

 

The following are the links for mini projects source code

(  Note : Explore or google for more information  )

https://www.interviewbit.com/blog/c-projects/

 

https://www.codewithc.com/c-projects-with-source-code/

 

https://itsourcecode.com/free-projects/c-projects/c-projects-with-source-code-for-beginners/

 

https://www.crio.do/projects/?utm_source=adwords&utm_medium=Projects&utm_campaign=Other-Projects&utm_term=mini%20projects%20for%20cse&gad=1&gclid=Cj0KCQjw9MCnBhCYARIsAB1WQVWGmruJz7yiJWOILDOFkiLCwpbMJS5cn6TgP7vGegRbBc_CsRgl14MaApOZEALw_wcB

 

https://www.crio.do/blog/mini-projects-for-computer-science-engineers/

 

https://takeoffprojects.com/page/blog/mini-projects-for-cse

 

https://cselectricalandelectronics.com/c-programming-projects-with-source-code-coding-projects-ideas/

 

https://code-projects.org/c/languages/project/cprojects/

 

https://www.cppbuzz.com/projects/c/download-c-projects

 

https://www.codewithc.com/c-projects-with-source-code/

 

 

Minin Titles:

·         Sudoku Game.

·         Trading Application Project In C++

·         Casino Number Guessing Game.

·         Sales Management System.

·         Face Detection App with C++

·         Digital Calculator.

·         Tic-Tac-Toe

·        
Bank Management System

·         Calendar Application

·         Contact Management System

·         Cricket Score Sheet

·         Customer Billing System

·         Cyber Management System

·         Department Store Management System

·         Employee Record System

·         Hangman Game

·         Hospital Management System

·         Library Management System

·         Medical Store Management System

·         Modern Periodic Table

·         Pacman Game

·         Personal Diary Management System

·         Phonebook Application

·         Quiz Game

·         School Billing System

·         Snake Game

·         Student Record System

·         Telecom Billing System

·         Tic-Tac-Toe Game

·         Typing Tutor

·        
Banking Record System

·         Bookshop Management System

·         Bus Reservation System

·         Hotel Management System

·         Payroll Management System

·         Phonebook Management System

·         Railway Reservation System

·         Sales Management System

·         Student Database Management System

·         Student Report Card System

·         Supermarket Billing System

·         Telephone Directory System

Some Advanced Projects in C and C++:

These are some projects with wider scope, utilizing the advanced aspects and graphics of C and C++ programming.

·         Snakes and Ladders Game in C

·         Bike Race Game (using SDL) in C++

·         Database Management System (using wxWidgets) in C++

·         Fortune Teller (Predict Future) in C++

·         Helicopter Game (using SDL) in C++

·         Search Engine in C++

·         Tank Game in C++

·         Traffic Control Management System in C++

·         University Management System in C++

·         3D Bounce Ball Game in OpenGL

More C and C++ Projects:

More projects for you! We haven’t had the time to publish these projects, so we’ll just provide a download link to the ones mentioned below.

·         Copter Game (using Allegro) in C

·         Balloon Shooting Game in C++

·         Canteen Management System in C++

·         Casino Game in C++

·         Digital Clock in C++

·         Memory Game in C++

·         Music Store Management System in C++

·         School Fee Inquiry Management System in C++

·         Shuffle Game in C++

·         Snakes and Ladders Game in C++

·         Sudoku Game in C++

·         Telephone Billing System in C++

·         Travel Agency Management System in C++

 

 

 

Friday, May 5, 2023

Thread, Multi Thread & setting thread priority

 single thread program

class MyThread extends Thread{

    Thread t;

    public MyThread(String msg){

        t=new Thread(msg);

    }

    public void run()

    {

        

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

    try{

        t.sleep(1000);

        System.out.println(t.getName()+" : "+i);    

    }

    catch(Exception e)

    {

      e.printStackTrace();  

    }

        }

    }

}


public class Main

{

public static void main(String[] args) {

    MyThread t1=new MyThread("Theread-1"); 

t1.start();

}

}

-------------------------------------------------------------

multi thread


class MyThread extends Thread{

    Thread t;

    public MyThread(String msg){

        t=new Thread(msg);

    }

    public void run()

    {

        

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

    try{

        t.sleep(1000);

        System.out.println(t.getName()+" : "+i);    

    }

    catch(Exception e)

    {

      e.printStackTrace();  

    }

        }

    }

}


public class Main

{

public static void main(String[] args) {

    MyThread t1=new MyThread("Theread-1"); 

    MyThread t2=new MyThread("Theread-2"); 

    MyThread t3=new MyThread("Theread-3"); 

t1.start();

t2.start();

t3.start();

}

}

--------------------------------------------------------

thread priority


class MyThread extends Thread{

    Thread t;

    public MyThread(String msg){

        t=new Thread(msg);

    }

    public void run()

    {

        

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

    try{

        t.sleep(1000);

        System.out.println(t.getName()+" : "+i);    

    }

    catch(Exception e)

    {

      e.printStackTrace();  

    }

        }

    }

}


public class Main

{

public static void main(String[] args) {

    MyThread t1=new MyThread("Theread-1"); 

    MyThread t2=new MyThread("Theread-2"); 

    MyThread t3=new MyThread("Theread-3"); 

t1.start();

t1.setPriority(Thread.MAX_PRIORITY);

t2.start();

t3.start();

}

}


Monday, December 26, 2022

Exception Handling in C++ & Void pointer

 #include <iostream>

using namespace std;


int sum(int a,int b) throws (int,char)

{

    if(a<0 && b<0)

    throw  0;

    cout<<(a+b)<<endl;

}


int main()

{

    int age;

    cout<<"Enter age?";

    cin>>age;

    try{

        if(age<0)

        throw 0;

        else

            if(age>100)

            throw 'x';

            else

                if(age==0)

                {

                    throw 0.0;

                }

                else

                if(age==100){

                    throw "oho!";

                }

      cout<<"Age = "<<age<<endl;   

    }

    catch(char ch) //handler prog

    { 

        cerr<<"Illegal age";

    }

    catch(int ch) //handler prog

    { 

        cerr<<"Age can't be negative";

    }

    catch(float f){

        cerr<<"Age can't be zero";

    }

    catch(char *str){

        cout<<str;

    }

   catch(...) //default handler

   {

      

       cout<<"Unknown error "<<endl;

   }

    return 0;

}

---------------------------------------------------------------------------------

void pointer example

#include <iostream>

using namespace std;




int main(void)

{

    int no=100;

    float f=10.345F;

    void*n;

    n=&f;

    cout<<*(float*)n<<endl;

    return 0;

}




Wednesday, November 2, 2022

Inheritance simple,multi level and code reusability

//Simple inheritance

#include <iostream>

using namespace std;

//base class

class Student

{

    protected:

        int sno;

        char sname[20];

};

// derived clasds

class Mpc:public Student

{

    private:

        int maths,phy,che;

    public:

        void get()

        {

            cout<<"Enter no and name?";

            cin>>sno>>sname;

            cout<<"Enter Maths,phy & che marks?";

            cin>>maths>>phy>>che;

        }

        void dis(){

            cout<<sno<<"\t\t"<<sname<<endl;

            cout<<maths<<"\t\t"<<phy<<"\t\t"<<che<<"\n";

        }

            

    

};


int main()

{

    Mpc obj;

    cout<<sizeof(obj)<<endl;

    obj.get();

    obj.dis();

    return 0;

}





// multi level inheritance

#include <iostream>

using namespace std;

//base class

class Student

{

    protected:

        int sno;

        char sname[20];

};

// derived class

class Lang:public Student{

    protected:

        int eng,tel;

};

// derived clasds

class Mpc:public Lang

{

    private:

        int maths,phy,che;

    public:

        void get()

        {

            cout<<"Enter no and name?";

            cin>>sno>>sname;

            cout<<"Enter eng and tel marks?";

            cin>>eng>>tel;

            cout<<"Enter Maths,phy & che marks?";

            cin>>maths>>phy>>che;

        }

        void dis(){

            cout<<sno<<"\t\t"<<sname<<endl;

            cout<<eng<<"\t\t"<<tel<<"\n";

            cout<<maths<<"\t\t"<<phy<<"\t\t"<<che<<"\n";

        }

};


int main()

{

    Mpc obj;

    cout<<sizeof(obj)<<endl;

    obj.get();

    obj.dis();

    return 0;

}


output :

Enter no and name?101 Scott

Enter eng and tel marks?66 77

Enter Maths,phy & che marks?88 99 90

101             Scott

66              77

88              99              90


-------------------------

// multi level multi line inheritance

#include <iostream>

using namespace std;

//base class

class Student

{

    protected:

        int sno;

        char sname[20];

};

// derived class

class Lang:public Student{

    protected:

        int eng,tel;

};

//derived class

class Pc:public Lang{

    protected:

        int phy,che;

};

// derived clasds

class Mpc:public Pc

{

    private:

        int maths;

    public:

        void get()

        {

            cout<<"Enter no and name?";

            cin>>sno>>sname;

            cout<<"Enter eng and tel marks?";

            cin>>eng>>tel;

            cout<<"Enter Maths,phy & che marks?";

            cin>>maths>>phy>>che;

        }

        void dis(){

            cout<<sno<<"\t\t"<<sname<<endl;

            cout<<eng<<"\t\t"<<tel<<"\n";

            cout<<maths<<"\t\t"<<phy<<"\t\t"<<che<<"\n";

        }

};

// derived clasds

class Bpc:public Pc

{

    private:

        int bot,zoo,phy,che;

    public:

        void get()

        {

            cout<<"Enter no and name?";

            cin>>sno>>sname;

            cout<<"Enter eng and tel marks?";

            cin>>eng>>tel;

            cout<<"Enter phy,che,bot & zoo marks?";

            cin>>phy>>che>>bot>>zoo;

        }

        void dis(){

            cout<<sno<<"\t\t"<<sname<<endl;

            cout<<eng<<"\t\t"<<tel<<"\n";

            cout<<bot<<"\t\t"<<phy<<"\t\t"<<che<<"\t\t"<<zoo<<"\n";

        }

};

int main()

{

    Mpc m;

    m.get();

    m.dis();

    Bpc b;

    b.get();

    b.dis();

    return 0;

}


Enter no and name?101 Babe

Enter eng and tel marks?45 56

Enter Maths,phy & che marks?56 67 78

101             Babe

45              56

56              67              78

Enter no and name?102 Scott

Enter eng and tel marks?78 76

Enter phy,che,bot & zoo marks?56 56 56 56

102             Scott

78              76

56              56              56              56


---------------------------------------------------------

// concept of reusability of code

#include <iostream>

using namespace std;

//base class

class Student

{

    protected:

        int sno;

        char sname[20];

    public:

        void get(){

            cout<<"Enter no and name?";

            cin>>sno>>sname;

        }

        void dis(){

            cout<<sno<<"\t\t"<<sname<<endl;

        }

};

// derived class

class Lang:public Student{

    protected:

        int eng,tel;

    public:

        void get(){

            Student::get();

            cout<<"Enter eng and tel marks?";

            cin>>eng>>tel;

        }

        void dis(){

            Student::dis();

            cout<<eng<<"\t\t"<<tel<<"\n";

        }

};

//derived class

class Pc:public Lang{

    protected:

        int phy,che;

    public:

        void get(){

            Lang::get();

            cout<<"Enter Phy and che marks?";

            cin>>phy>>che;

        }

        void dis(){

            Lang::dis();

            cout<<phy<<"\t\t"<<che<<"\n";

        }

};

// derived clasds

class Mpc:public Pc

{

    private:

        int maths;

    public:

        void get()

        {

            Pc::get();

            cout<<"Enter Maths marks?";

            cin>>maths;

        }

        void dis(){

            Pc::dis();

            cout<<maths<<"\n";

        }

};

// derived clasds

class Bpc:public Pc

{

    private:

        int bot,zoo;

    public:

        void get()

        {

            Pc::get();

            cout<<"Enter bot & zoo marks?";

            cin>>bot>>zoo;

        }

        void dis(){

            Pc::dis();

            cout<<bot<<"\t\t"<<zoo<<"\n";

        }

};

int main()

{

    Mpc m;

    m.get();

    m.dis();

    Bpc b;

    b.get();

    b.dis();

   

    return 0;

}


output:

Enter no and name?101 Babe

Enter eng and tel marks?55 55

Enter Phy and che marks?66 66

Enter Maths marks?78

101             Babe

55              55

66              66

78

Enter no and name?102 Tiger

Enter eng and tel marks?67 78

Enter Phy and che marks?78 89

Enter bot & zoo marks?78 78

102             Tiger

67              78

78              89

78              78