Monday 29 July 2013

W.A.P. to Make Calculator Using Applet in JAVA

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Calculator extends Applet
implements ActionListener
{
    String msg=" ";
    int v1,v2,result;
    TextField t1;
    Button b[]=new Button[10];
    Button add,sub,mul,div,clear,mod,EQ;
    char OP;
   
    public void init()
    {
        Color k=new Color(120,89,90);
        setBackground(k);
        t1=new TextField();
        GridLayout g1=new GridLayout(4,5);
        setLayout(g1);
        for(int i=0;i<10;i++)
        {
            b[i]=new Button(""+i);
        }
        add=new Button("add");
        sub=new Button("sub");
        mul=new Button("mul");
        div=new Button("div");
        mod=new Button("mod");
        clear=new Button("clear");
        EQ=new Button("EQ");
        t1.addActionListener(this);
        add(t1);
        for(int i=0;i<10;i++)
        {
                add(b[i]);
        }
       
        add(add);
        add(sub);
        add(mul);
        add(div);
        add(mod);
        add(clear);
        add(EQ);
        for(int i=0;i<10;i++)
        {
            b[i].addActionListener(this);
        }
        add.addActionListener(this);
        sub.addActionListener(this);
        mul.addActionListener(this);
        div.addActionListener(this);
        mod.addActionListener(this);
        clear.addActionListener(this);
        EQ.addActionListener(this);
    }
   
    public void actionPerformed(ActionEvent ae)
    {
        String str=ae.getActionCommand();
        char ch=str.charAt(0);
        if(Character.isDigit(ch))
        t1.setText(t1.getText()+str);
        else
            if(str.equals("add"))
            {
                v1=Integer.parseInt(t1.getText());
                OP='+';
                t1.setText("");
            }
            else if(str.equals("sub"))
        {
            v1=Integer.parseInt(t1.getText());
            OP='-';
            t1.setText("");
        }
        else if(str.equals("mul"))
        {
            v1=Integer.parseInt(t1.getText());
            OP='*';
            t1.setText("");
        }
        else if(str.equals("div"))
        {
            v1=Integer.parseInt(t1.getText());
            OP='/';
            t1.setText("");
        }
        else if(str.equals("mod"))
        {
            v1=Integer.parseInt(t1.getText());
            OP='%';
            t1.setText("");
        }
        if(str.equals("EQ"))
        {
            v2 = Integer.parseInt(t1.getText());
            if(OP= ='+')
                result = v1+v2;
            else if(OP= =' - ')
                result = v1- v2;
            else if(OP= =' * ')
                result = v1 * v2;
            else if(OP = = '/')
                result = v1 / v2;
            else if(OP = =' %')
                result = v1 % v2;
            t1.setText(""+result);
        }
        if(str.equals("clear"))
        {
            t1.setText("");
        }
    }
}



Sunday 28 July 2013

Write a Applet for Drawing Human Face

import java.awt.*;
import java.applet.*;
public class face extends Applet
{
    public void paint(Graphics g)
    {
        g.drawOval(40, 40, 120, 150);
        g.drawOval(57, 75, 30, 20);
        g.drawOval(110, 75, 30, 20);
        g.fillOval(68, 81, 10, 10);
        g.fillOval(121, 81, 10, 10);
        g.drawOval(85, 100, 30, 30);
        g.fillArc(60, 125, 80, 40, 180, 180);
        g.drawOval(25, 92, 15, 30);
        g.drawOval(160, 92, 15, 30);
    }

}


Output




Applet in Interactive Input to an Applete

import java.awt.*;
import java.applet.*;

public class Bhargav extends Applet
{
                       TextField text1,text2;
                       
                      public void init( )
                        {
                                    text1 = new TextField(8);
                                    text2 = new TextField(8);
                                    add(text1);
                                    add(text2);
                                    text1.setText("0");
                                    text2.setText("0");                             
                       }

                       public void paint(Graphics g)
                       {
                                 int x = 0, y = 0, z = 0;
                                 String s1,s2,s;
                                 g.drawString("Input a number in each box",10,50);
                         
                                  try
                                 {
                                                      s1 = text1.getText( );
                                                      x = Integer.parseInt(s1);
                                                      s2 = text2.getText( );
                                                      y= Integer.parseInt(s2);
                                  }
                                  catch( Exception ex) { }
                                  z = x + y;
                                  s = String.valueOf (z);
                                  g.drawString ("The Sum is :", 10, 75);
                                  g.drawString (s,100,75);

                       }
                 
                           public Boolean action (Event event, Object object)
                           {
                                         repaint ( );
                                         return true;
                            }
                      
}

W.A.P. to find Merge Sort using C++


 

Saturday 27 July 2013

W.A.P to Print Hello Word in C++

#include<iostream.h>
#include<conio.h>
int main()
{
           cout<<"Hello World:";
           getch();
            return 0;
}

Output:

HelloWorld:

Write a Program Bubble Sort using Sorting Algorithm in C++ Language

#include<iostream.h>
#include<conio.h>
int main()
{
           int arr[5],i,j,temp;
           cout<<"Enter the element of Array:";
           for(i=0;i<5;i++)
           {
                    cin>>arr[i];
           }

           cout<<"Array are Sorted:";
           for(i=0;i<5;i++)
           {
                      for(j=o;j<4-i;j++)
                      {
                                  if(arr[j]<arr[j+1)
                                  {
                                              temp=arr[j];
                                              arr[j]=arr[j+1];
                                              arr[j+1]=temp;
                                  }
                      }
                    cout<<arr[j];
            }

         getch();
         return 0;
}



Output : 

Enter the element of Array:2
8
9
4
6

Array are Sorted :24689

Followers