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


Thursday, September 22, 2022

R20 CPP UNIT WISE QUESTIONS

Note  :( These questions are just to put you in understanding level )

UNIT-1  

Differentiate between procedural and object oriented approach. (7M)

What is an object? How is it different from an ordinary variable and a class?
Explain with an example.

State the important features of object oriented programming. (7M)

Describe the major parts of C++ Program.

Compare object oriented programming with procedure oriented programming. 

Compare the features of C Programming language to that of C++ Programming
language.

Mention advantages and disadvantages of object oriented programming over
functional programming.

Explain the following concepts used in object oriented paradigm. Message
passing, code reusability.

What are the drawbacks of conventional programming? Explain how object oriented
programming overcome them.

Explain polymorphism, data abstraction and data encapsulation with examples.

List the drawbacks of conventional programming. Explain how object oriented
programming overcome them.

Explain about polymorphism and encapsulation.

List the similarities and differences between C and C++.

Write about inheritance and abstraction.

Explain the key concepts of Object Oriented Programming.

Briefly write about the evolution of C++.

UNIT-2

Write a C++ program demonstrating the viability of new and delete operators for a
single variable as well as an array.

How will you destroy the objects initialized by the constructor in the program?

With an example explain the syntax for defining a class. 

What is function overloading? What are the principles of function overloading?

How memory is allocated to an object? State with an example.

Write a C++ program to define two overloaded functions to swap two integers and to
swap two characters.

How the member function can be defined inside class and outside the class?
Explain.

Write a program in C++ to find the factorial of a given number using recursion.

What is static function? What is its use? How a member of class be declared as
static?

Write a C++ program to define three overloaded functions to swap two integers, swap two
floats and swap two doubles.

What are recursive constructors? Explain with an example.

Define inline function. Write a C++ program for finding the area of a triangle using
inline functions.

What is function overloading? What are the principles of function overloading?

Write C++ Program that demonstrates the usage of static data member and static
member function.

Write C++ program to find the area of a circle, rectangle and triangle using
function overloading.

What is a constructor? Write different rules associated with declaring constructors.

UNIT-3

What is operator overloading? Write the rule to overload an operator.

What are the various types of situations that might arise in data conversion
between incompatible types? How can they be handled? 
Explain the visibility of base class members for the access specifiers: private, protected
and public while creating the derived class and also explain the syntax for creating
derived class.

Write a C++ program to exchange the values between two classes using friend
functions.

Describe various visibility modes available in C++. 

With an example, explain the syntax for passing arguments to base class constructors in
multiple inheritances.

Write a C++ program to overload binary ‘+’ operator which will add two complex
numbers of the form (a+ib).

Write a C++ program to implement multiple inheritances with public access specific.

Write C++ program to find the area of a circle, rectangle and triangle using
function overloading.

What is a constructor? Write different rules associated with declaring constructors.

What are different types of inheritance supported by C++? Give an example for
each.

Write a C++ program to overload increment operator.

Write a C++ program to demonstrate pointers to base and derived classes. 

Discuss about virtual functions with a C++ example.

UNIT-4

With an example, explain how virtual functions are hierarchical.

How to create a virtual destructor? What is the necessity of making it virtual?

Describe the mechanism of creating virtual functions in C++ with an example.

Write a C++ program that declare and use pointer to an object.

How virtual functions can be used to implement runtime polymorphism? Describe.

What is a pointer? How to declare a pointer to a class and an object?

How does polymorphism promote extensibility? Illustrate.

With an example explain how late binding can be achieved in C++.

What is dynamic binding? How it is different from static binding? List some
advantages of dynamic binding over static binding.

What is a virtual destructor? Explain with an example.

Explain the role of this pointer in C++ with a programming example.

UNIT-5

Write a C++ program that illustrates exception handling with the help of
keywords: try, throws and catch.

What is STL? Briefly explain the use of containers, vectors, lists and maps.

What are class templates? How are they different from classes? Explain with
sample C++ code.

hat should be placed inside try block and catch block? When do you use
multiple catch handlers?

Write a C++ program to insert elements into a list. 

What is a container? Give its significance. Give an overview on its types.

Can we overload a function template? Illustrate with an example.

What is the sequence of events when an exception occurs? Explain them. 

How to initialize elements of vectors and lists? Illustrate. 

What is the use of Iterator while using containers? Justify with an example.

What are macros? How are they different from preprocessor directives and templates? (7M)

Write a program to swap two variables using a function template. 

Explain briefly the three foundational items of standard template library.

Write a C++ program to add two integers, two floating point numbers and two
complex numbers using class templates. 

Explain how to catch multiple exceptions in C++.