Posts

Showing posts with the label class

Employee Management System Using Inheritance in Java

Image
This program will help you in creating an simple Employee Management System using java language. In this program a class emp is used which has name, id and salary as data members. inside it there are two methods namely get() and disp() which work as getting user input and displaying the output. Scanner class is used as well. This program is an implementation of array of objects. Sample Output : The Code here: import java.util.*; class emp { public String name; public int id,sal; public void get() { Scanner s=new Scanner(System.in); System.out.print("Enter The Name: "); name=s.next(); System.out.print("Enter The id: "); id=s.nextInt(); System.out.print("Enter The sal: "); sal=s.nextInt(); s.close(); } public void disp() { System.out.println("The Name of the employee is "+name+" having id: "+id+"and a salary worth to: "+sal); } } class MainClass extends emp { publ...

Find the roots of a given polynomial

This is a program which finds the roots of a given polynomian in the form of ax 2 +bx+c , where a, b and c are the inputs given by the user. In this program there is a method check() which checks if the value of the discrimainate is a positive number, if it is positive then we will get real roots. This progam is designed using Java. import java.util.Scanner; class poly { int a,b,c; double s1,s2,d; poly() { a=b=c=0; s1=s2=d=0.0; } void getit() { Scanner s=new Scanner (System.in); a=s.nextInt(); b=s.nextInt(); c=s.nextInt(); } boolean check() { d=(b*b)-(4.0*a*c); if(d>=0.0) return true; else return false; } boolean calc() { if(check()) { s1=((-b)+(Math.sqrt(d)))/(2.0*a); s2=((-b)-(Math.sqrt(d)))/(2.0*a); return true; } else return false; } void disp() { if(calc()) System.out.println("The Roots are: s1: "+s1+", "+s2); else ...

Complex Number Operations, Add, Sub,Mul and Div

This program can be used to perform operations such as addition, substraction, multiplication and division between two complex numbers. In this program, all the three types of constuctors are used, i.e. default, parameterised and copy constructor. Besides that a get() function is also used which will fetch input from the console. Overal this program will show you how to use constructors or functions to assign values to the variables of the object of the class. This Program is crafted using C++. #include<iostream> using namespace std; class complex { public: int a,b;//a+ib complex() { a=0; b=0; } complex(int a,int b) { this->a=a;// This is used to prevent Ambiguity. this->b=b; } complex(complex &obj) { a=obj.a; b=obj.b; } void get() { cout<<"Enter The Real Part: ";cin>>a; cout<<"Enter The Imaginary Part: ";cin>>b; } void add(complex ob1,com...