source file name: SumSeries3.java import java.io.*; class A { int n; public A(int m) { n=m; } public void sum() { float sum=1.0f; float i=n; while(i>0) { float p=(int)Math.pow(2,i); sum=sum+(1/p); //System.out.println(p+","+sum); i--; } System.out.println(" Series Sum: "+sum); } } class SumSeri…
Read more14) Write a Java program that finds sum of series given 1+1/2+2/3+3/4…(n-1)/n using constructor instance variable.
source file name: SumSeries1.java class A { int n; public A(int m) { n=m; } public void sum() { float sum=1; float i=n; while(i>0) { sum=sum+((i-1)/i); i--; } System.out.println(sum); } } class SumSeries1 { public static void main(String args[]) { int i; i=Integer.parseInt(args[0]); A ob=new A(i); System.out.prin…
Read more13) Write a Java program that displays all divisible by 6 or 8 between 1 to y number using constructor instance variable.
source file name: Div6or8Demo.java import java.io.*; class A { int y; public A(int n) { y=n; } public void disp() { int d=1; while(d<=y) { if(d%6==0 || d%8==0) System.out.println(d); d++; } } } class Div6or8Demo { public static void main(String as[]) { int n=1; System.out.println("enter value: "); try {…
Read more10) Write a Java program that finds average marks of two subjects also display student name and marks using constructor instance variable.
source file name: MarksDemo.java class Marks { int sub1 , sub2; public Marks(int s1, int s2) // definition constructor { sub1=s1; sub2=s2; } } class Marks1 { String name; Marks m; public Marks1(String nm,int s1, int s2) // definition constructor { m=new Marks(s1,s2); name=nm; } public void display() { System.out.pr…
Read more9) Write a Java program that finds Factorial value given number using constructor instance variable.
source file name: FactDemo.java import java.io.*; class A { int y; public A(int n) { y=n; } public void disp() { int f=1; while(y>0) { f=f*y; y--; } System.out.println("Factorial value of given number is:="+f); } } class FactDemo { public static void main(String as[]) { int n=1; Syste…
Read more8) Write a Java program that checks given number is Divisible by 5 or not using constructor instance variable.
source file name: Div5Demo.java import java.io.*; class A { int y; public A(int n) { y=n; } public void disp() { if(y%5==0) System.out.println("given no is divisible by 5"); else System.out.println("given no is not divisible by 5"); } } class Div5Demo { public static void main(String as[…
Read more7)Write a Java program that finds Quadratic equation has Real or Complex roots using constructor a, b, c instance variables.
source file name: Quadratic.java class Quad { int a,b,c; public Quad(int p,int q,int r) { a=p;b=q;c=r; } public void disproots() { System.out.println("coefficents a:"+a+" b: "+b+" c: "+c); int d=b*b-4*a*c; if(d>=0) { System.out.println("root are real:"); double r1=(-b…
Read more6) Write a Java program that finds Slope , X-intercept and Y-intercept of Straight Line using constructor a,b and c instance variables.
source file name: Lines.java class Line { int a,b,c; public Line(int p,int q,int r) { a=p;b=q;c=r; } public void slope() { int m=a; System.out.println("slope is:"+m); } public void yintercept() { int yi; yi=a-c/b; System.out.println(" y intercept is: "+yi); } public void xinterc…
Read more5) Write a Java program that checks given number is perfect number or not using constructor instance variable.
source file name: NumberDemo.java class A { int y; public A(int n) { y=n; } public void divdisp() { int d=1; while(d<y) { if(y%d==0) System.out.print(d+" "); d++; } } public void perfectno() { int d=1; int sum=0; while(d<y) { if(y%d==0) sum=sum+d; d++; } if(sum==y) System.out.println(&qu…
Read more11) Write a Java program that checks given number is divisible by 4 or 6 but not both using constructor instance variable.
source file name: Div4or6Demo.java import java.io.*; class A { int y; public A(int n) { y=n; } public void disp() { if(y%4==0) System.out.println("Given number is Divisible by only 4 "); if(y%6==0) System.out.println("Given number is Divisible by only 6 "); if(y%4!=0 && y%6!=0) System.ou…
Read more12) Write a Java program that display all numbers between 1 to n that divisible by 5 using constructor instance variable.
source file name: Div5allDemo.java import java.io.*; class A { int y; public A(int n) { y=n; } public void disp() { int d=1; while(d<=y) { if(d%5==0) System.out.println(d); d++; } } } class Div5allDemo { public static void main(String as[]) { int n=1; System.out.println("enter value: "); try { DataInput…
Read moresource file name: MyServer.java import java.io.*; import java.net.*; public class MyServer { public static void main(String[] args) { try { ServerSocket ss=new ServerSocket(6666); Socket s=ss.accept();//establishes connection DataInputStream dis=new DataInputStream(s.getInputStream()); String str…
Read moresource file name: MyClient1.java import java.net.*; import java.io.*; class MyClient1{ public static void main(String args[])throws Exception{ Socket s=new Socket("localhost",3333); DataInputStream din=new DataInputStream(s.getInputStream()); DataOutputStream dout=new DataOutputStream(s.getOutpu…
Read moresource file name: Server1.java import java.io.*; import java.net.*; public class Server1 { public static void main(String[] args) { try { ServerSocket ss=new ServerSocket(1111); Socket s=ss.accept();//establishes connection DataOutputStream dout=new DataOutputStream(s.getOutputStream()); System.out…
Read more6) Write a Java program that uses interface Lockable and two classes File and Cupboard.
Define an interface Lockable containing functions- open() and close(). Define 2 classes, File and cupboard that implements Lockable interface with other details. Call the functions using the variable of Lockable. source file name: MediaDemo.java //interface Lockable have open().close() abstract methods interface Loc…
Read more5) Write a Java program that uses interface Controllable and two classes Television and Game .
Define an interface Controllable containing two functions- start() and stop(). Define 2 classes Television and Game that implements Controllable interface with other details. Call the functions using variable Controllable. source file name: LockDemo.java // interfaceControllable have start (),stop () abstract met…
Read more4) Write a Java program that uses interfaces ColdBlooded , OceanDwelling and classes Birds , Reptiles.
Interfaces are sometimes used to indicate which classes have a certain capability or characteristic. Consider the following classes and interfaces. The abstract class Animal has abstract subclasses named Bird and reptile. Classes Dove, eagle Hawk, Penguin and Seagull extend Bird. Classes Rattle Snake and Turtle exte…
Read more3) Write a Java program that uses several classes(Robot1, Robot2 and Robot3) and interface (Locomotion).
Write an application that combines several classes and interfaces. An abstract class Robot has concrete subclasses named RobotA, RobotB, RobotC. Class RobotA1 extends RobotA. Classes RobotB1 and RobotB2 extends RobotB. Class RobotC1 extends RobotC. The locomotion interface declares three methods name forward() and s…
Read more7) Write a Java program that gets and shows two numbers using object oriented terms.
source file name: simpleoo1.java class simpleoo1 { int a,b; void get(int m, int n) { a=m; b=n; } void show() { System.out.println(" a: "+a+" b: "+b); } public static void main(String dbj[]) { System.out.println("object oriented program: "); simpleoo1 ob1=new simpleoo1(); simpleoo1 ob2=…
Read more6) Write a Java program that interchange two values swap method and display these two numbers using disp method.
source file name: simple1.java class Swap { int a,b; void set(int m,int n) { a=m; b=n; } void show() { System.out.println("a="+a+" b="+b); } void swap() { int t=a; a=b; b=t; } } class simple1 { public static void main(String as[]) { Swap ob=new Swap(); ob.set(10,20); System.out.println("…
Read more5) Write a C++ program that finds Factorial value of number and finds Vowels and Consonants of given string using Inheritance.
source file name: Inher11.CPP #include<conio.h> #include<string.h> #include<iostream.h> class Fact { public : int fact(int n) { int f=1; while(n>0) { f*=n; n--; } return f; } }; class strdemo: public Fact { public: void Vowels(const char *str) { int cost=0,sp=0,vl=0;…
Read moresource file name: opequal,CPP #include<iostream.h> #include<conio.h> class Circle { int r; public: Circle(){} Circle(int n) { r=n; } void disp() { cout<<"\n radius= "<<r <<endl; } Circle operator=(int); }; Circle Circle::operator=(int n) { r=n; return *this; } int main() { Circ…
Read more5) Write a C++ program that displays employees details using constructors overloading.
source file name: constemp.CPP #include <iostream.h> #include <conio.h> #include <string.h> class Employee { int id;//data member (also instance variable) char name[20];//data member(also instance variable) float salary; public: Employee() { id = 10; …
Read moresource file name: copycst.CPP #include<iostream.h> #include<conio.h> class Point { private: int x, y; public: Point(int x1, int y1) { x = x1; y = y1; } // Copy constructor Point(const Point &p1) {x = p1.x; y = p1.y; } int getX() { return x; } int getY() { return y; } }; int main() …
Read more5) Write a C++ program that displays different Number of Parameters using Function Overloading.
source file name: funov5.CPP #include <iostream.h> #include <conio.h> // function with 2 parameters void disp(int a, float b) { cout << "Integer number: " << a; cout << " and float number: " << b << endl; } // function with double type single param…
Read more4) Write a C++ program that finds absolute values of two numbers using O-O function overloading.
#include<conio.h> #include <iostream.h> class FunABS { public: int abs(int n) { cout<<"\n In Integer fuction "<< endl; if(n<0) return -n; else return n; } float abs(float n) { cout<<" \n In float fuction "<< endl; if(n<0) return -n; else return n; } }; in…
Read more5) Write a C++ program that finds Area and Volume of Cube using Class and Objects.
source file name: OOP5.CPP #include <iostream.h> // create a class class Room { int len; int bd; int ht; public: void setdata(int a, int b, int c) { len=a; bd=b; ht=c; } long area() { return len * bd; } long volume() { return len * bd * ht; } }; int main() { // create obje…
Read moresource file name: Primeno3.CPP #include<conio.h> #include<iostream.h> int main() { int n,d; clrscr(); cout<<"\n enter any number: "; cin>>n; d=2; while(d<n) { if(n%d==0) { cout<<"\n given no is not prime no: "<<n; break; } else d++; } if(n==d) cout<<…
Read more4) Write a C++ program that finds input three digit number is Armstrong number or not.
source file name: Armstrong1.CPP #include<stdio.h> #include<conio.h> #include<iostream.h> int main() { int n,d; int sum=0,temp; clrscr(); cout<<"\n enter any 3 digit number: "; cin>>n; temp=n; while(n>0) { d=n%10; sum=sum+(d*d*d); n=n/10; } if(sum==temp) cout<<"…
Read more3)Write a C++ program to check whether the number entered is even ,odd , a positive , negative or zero.
source file name: odevens.CPP #include<stdio.h> #include<conio.h> #include<iostream.h> int main() { int n; //clrscr(); cout<<"\n enter any no."; cin>>n; if(n%2==0) cout<<"\n given no is even"; else cout<<"\n given no is odd"; if(n>0) cout<…
Read moresource file name: datedemo3.java import java.util.*; class datedemo3 { public static void main(String as[]) { String mon[]={"Jan","Feb","March","April","May","June", "July","August","Sep","Oct","Nov","De…
Read moresource fie name: datedemo2.java import java.util.*; class datedemo2 { public static void main(String as[]) { System.out.println("Date and Time demo program: "); Date d=new Date(); System.out.println("Today's Date and Time is: "+d); int day=d.getDay(); int mon=d.getMonth(); int year=d.getYear(…
Read more