NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

Sunday, October 21, 2012

Java program to implement multiple inheritance


import java.io.*;
interface bookinfo
{          public void getbookdata()throws IOException;
            public void putbookdata();
}
interface basicinfo
{          public void getbasicdata()throws IOException;
            public void putbasicdata();
}
interface otherinfo
{          public void getotherdata()throws IOException;
            public void putotherdata();
}

class book implements bookinfo,basicinfo,otherinfo
{          String Bname,Bauthor, Blanguage,Bpublisher;
            int Bprice, Bcopies,Byear;
            BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));

public void getbookdata()throws IOException
{          System.out.println("Enter the Book name:");
            Bname=br.readLine();
            System.out.println("Enter the author's name:");
            Bauthor=br.readLine();
}

public void putbookdata()
{ System.out.print(Bname+"\t"+Bauthor+"\t");
}

public void getbasicdata()throws IOException
{          System.out.println("Enter the language:");
            Blanguage=br.readLine();
           
            System.out.println("Enter the published year:");
            Byear=Integer.parseInt(br.readLine());
            System.out.println("Enter the price");
            Bprice=Integer.parseInt(br.readLine());
}

public void putbasicdata()
{          System.out.print(Blanguage+"\t\t"+Byear+"\t"+Bprice+"\t");
}

public void getotherdata()throws IOException
{          System.out.println("Enter the number of copies:");
            Bcopies=Integer.parseInt(br.readLine());
            System.out.println("Enter the publisher:");
            Bpublisher=br.readLine();
}


public void putotherdata()
{          System.out.print(Bcopies+"\t"+Bpublisher+"\t\t");
}
}

class interfaceEg
{
public static void main(String s[])throws IOException
            {
              book it[];
               BufferedReader br=new BufferedReader(new
               InputStreamReader(System.in));
               System.out.println("How much entries..?");
               int k=Integer.parseInt(br.readLine());
               it=new book[k];
               for(int i=0;i<k;i++)
               { it[i]=new book();
               }
             
                for(int i=0;i<k;i++)
               {
               int j=i+1;
               System.out.println("ENTER DETAILS OF THE BOOK :   "+j);
               it[i].getbookdata();
               it[i].getbasicdata();
               it[i].getotherdata();
               }
             
             System.out.println("\n\n***********-----------------Book
              details-----------------************\n");
              System.out.println("Book\tAuthor\tLanguage\tYear\tPrice\tCopies
             \tPublisher");
             System.out.println("............................................................................");
             for(int i=0;i<k;i++)
               {
                
               it[i].putbookdata();
               it[i].putbasicdata();
               it[i].putotherdata();
               }
              }
             }
Output
  

Java program to find largest among 3 numbers


import java.io.*;
class largest
{
 int a,b,c,large;
 void read()throws IOException
 {
            BufferedReader br=new BufferedReader( new InputStreamReader(System.in));
            System.out.println("Enter 3 numbers");
            a=Integer.parseInt(br.readLine());
            b=Integer.parseInt(br.readLine());
            c=Integer.parseInt(br.readLine());
 }
 void check()
 {    if(a>b & a>c)
       large=a;
    else if(b>c)
       large=b;
    else 
       large=c;
   System.out.println("The largest number is "+large);
 }
 public static void main(String s[])throws IOException
 {         largest n=new largest();
            n.read();
            n.check(); }
}   

Output


Java program to illustrate method overloading


class area
{
  int l,b,r;
  float s;
  void sample(int l,int b)
  {
   s=b*l;
   System.out.println("area of rectangle="+s);
  }
  void sample(int r)
   {
    s=r*r;
    System.out.println("area of square="+s);
   }
  public static void main(String s[])
   {
     area a=new area();
     a.sample(5,3);
     a.sample(6);
   }
}

Output

Java program to find reverse of a number


import java.io.*;
class reverse
{
  int num,temp,p;
  reverse(int a)
  {num=a;
    temp=num;
    p=0;}
  void findreverse()
   { while(temp>0)
        {p=p*10+temp%10;
          temp/=10;}
    System.out.println("Reverse of "+num+" is "+p);
  }
  public static void main(String s[])throws IOException
  {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the number to reverse");
    int n=Integer.parseInt(br.readLine());
    reverse r=new reverse(n);
    r.findreverse();
  }
}


Output

Java program to print amstrong numbers upto given number


import java.io.*;
class strangenum
{int num,temp,d,s;
  strangenum(int a)
  { num=a;}
  void gen_strange()
  { System.out.println("strnge numbers are");
       for(int i=0;i<=num;i++)
        {temp=i;
          s=0;
          while(temp>0)
          { d=temp%10;
             s+=d*d*d;
             temp/=10; }
      if(s==i)
        System.out.println(i); }
  }
  public static void main(String s[])throws IOException
  { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     System.out.println("Enter the limit");
     int a=Integer.parseInt(br.readLine());
     strangenum st=new strangenum(a);
     st.gen_strange();}
}

Wednesday, October 17, 2012

Program to perform the addition of complex numbers



#include<iostream.h>
#include<conio.h>
class comp
{ private:
int r,i;
public:
void get();
void disp(comp,comp);
comp();
};
comp::comp()
{
r=0;
i=0;
}
void comp::get()

{
cout<<"\n\nEnter a complex number :-";
cout<<"\n\n\nEnter real part :\t";
cin>>r;
cout<<"\n\n\nEnter imaginary part:\t";
cin>>i;
cout<<"\n\n\nComlex number you entered :\t"<<r<<"+"<<i<<"i";
}
void comp::disp(comp a1,comp a2)
{
comp c;
c.r=a1.r+a2.r;

c.i=a1.i+a2.i;
cout<<"\n\n\n---------------------------------\n\n\nSum of the given complex numbers ="<<c.r<<"+"<<c.i<<"i";
}
void main()
{ clrscr();
comp a1,a2;
a1.get();
a2.get();
a1.disp(a1,a2);
getch();
}


Sample input and output

Enter a complex number
Enter real part:2
Enter imaginary part:3
Enter a complex number
Enter real part:1
Enter imaginary part:3
Sum of the given complex numbers =3+6i