Monday, 16 September 2013

Representation of Queue in JAVA wit GUI

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Queue extends JFrame implements ActionListener {
                     
                        JLabel welcom=new JLabel("Welcome to Graphical Represention of Queues Press Enter to Continue");
                        Font fnt=new Font("Arial",Font.ITALIC,20);
                        JButton entr=new JButton("Enter");
                        JPanel panel_for_Label=new JPanel();
                        JPanel panel_for_Button=new JPanel();
                       
                       
      public Queue()
      {
            super("Graphical Representation of Queues");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(1000,600);
            setLocation(150,100);
            setLayout(new GridLayout(2,1));
            panel_for_Label.setLayout(new FlowLayout(FlowLayout.CENTER));// Lay out for Welcome Label Panel
            panel_for_Button.setLayout(new FlowLayout(FlowLayout.CENTER));//Layout for Enter Button Panel
            welcom.setFont(fnt);
             panel_for_Label.add(welcom);
                                            entr.addActionListener(this);
             panel_for_Button.add(entr);
             add(panel_for_Label);
             add(panel_for_Button);
            setVisible(true);
      }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==entr)
        {
              setVisible(false);
             
            Paint_window obj= new Paint_window();
         
        }
    }
   
   
   
    public static void main(String[] args) {
        new Queue();
    }
}
    class Paint_window extends JFrame implements ActionListener
    {
                  int count=0;
                  JFrame f=new JFrame("Queue");
                  JLabel ent_data=new JLabel("Enter Data");
                  JTextField tf=new JTextField(10);
                  JButton ent=new JButton("Enter");
                  JButton rtrv=new JButton("Retrieve");
                  JButton ad=new JButton("Add");
                  JLabel dta[]=new JLabel[100];
                  String str[]=new String [100];
                  JLabel l=new JLabel("Faraz);");
                  JPanel que_panel=new JPanel();
                  JPanel btn_panel=new JPanel();
       Paint_window()
       {
          super("Graphical Representation of Queue");
          setSize(600,300);
          setLocation(150,100);
         
          setLayout(new GridLayout(2,1));
          que_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
          btn_panel.setLayout(new FlowLayout(FlowLayout.CENTER));
          add(que_panel);
          ad.setEnabled(false);
          btn_panel.add(ad);
          add(btn_panel);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setVisible(true);
       
         
                                    // Data for 2nd Frame
                                    {
                                        f.setSize(500,250);
                                        f.setLocation(800,400);
                                        f.setDefaultCloseOperation(EXIT_ON_CLOSE);
                                        f.setLayout(new FlowLayout(FlowLayout.LEFT));
                                        f.add(ent_data);
                                        f.add(tf);
                                        f.add(ent);
                                        f.add(rtrv);
                                                    ent.addActionListener(this);
                                                    rtrv.addActionListener(this);
                                                    ad.addActionListener(this);
                                                         
                                        f.setVisible(true);
                                       
                                    }
       }
               
         
       public void actionPerformed(ActionEvent e)
       {
          if(e.getSource()==ent)
          {
              {dta[count]=new JLabel(str[count]);
              que_panel.add(dta[count]);
              }
              str[count]=tf.getText();
              //JOptionPane.showMessageDialog(null,count);
             
             
             
             
             
             
              ent.setEnabled(false);
              ad.setEnabled(true);
              f.setAutoRequestFocus(false);
             
              tf.setText("");
         
             
          }
          if(e.getSource()==ad)
          {
              //que_panel.add(dta[count-1]);
             
              dta[count].setText(str[count]);
              count++;
              ent.setEnabled(true);
              ad.setEnabled(false);
              f.setAutoRequestFocus(true);
          }
          if(e.getSource()==rtrv)
          {  
               if(count>0)
              {
                   for(int i=0;i<count;i++)
                   {
                    dta[i].setText(str[i+1]);
           
                   }
                       for(int i=0;i<count;i++)
                       {
                          str[i]=str[i+1];
                       }
                    count--;
              }
               else
               {
                JOptionPane.showMessageDialog(null,"    Queue is Empty\n               or\nAll the Data Has Retrieved");
               }
          }
         
       }
    }


 

Sunday, 15 September 2013

Finding the alphabet in the String and Pointing that where that lie.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
char str[50],chr;
int len,count=0;
cout<<"Enter Any String:";
gets(str);
cout<<"Enter Character to find in \""<<str<<"\" String:";
cin>>chr;
clrscr();
cout<<str<<endl;
len=strlen(str);
int i=0;
      while(i<len)
      {
if(str[i]==chr)
{
  cout<<"^";
}
else
{
  cout<<" ";
  count++;
}
       i++;
      }
    if(count==len)
    {
      cout<<"\""<<chr<<"\" not found in \""<<str<<"\"";
    }
getch();
}

Arranging Even Numbers in Ascending Order and Odd Numbers in Descending Order and Displaying them Vertically

#include<iostream.h>
#include<conio.h>


void main()
{
clrscr();
int ar[10],temp;
    for(int i=0;i<5;i++)
    {
      cout<<"Enter Number:";
      cin>>ar[i];
    }

     for(i=1;i<=2;i++)
     {
for(int j=0;j<5;j++)
{
  if(i==1)
  {
    /* if(ar[j]%2==0)
     {
cout<<ar[j]<<endl;
     }*/
for(int k=0;k<5;k++)
{
  for(int l=k+1;l<5;l++)
  {
    if(ar[k]>ar[l])
    {
      temp=ar[k];
      ar[k]=ar[l];
      ar[l]=temp;
    }
  }
}
      if(ar[j]%2==0)
      {
cout<<ar[j]<<endl;
      }
  }
  else if(i==2)
  {
      /*if(ar[j]%2!=0)
      {
cout<<ar[j]<<endl;
      } */
for(int k=0;k<5;k++)
{
  for(int l=k+1;l<5;l++)
  {
    if(ar[k]<ar[l])
    {
      temp=ar[k];
      ar[k]=ar[l];
      ar[l]=temp;
    }
  }
}
      if(ar[j]%2!=0)
      {
cout<<ar[j]<<endl;
      }
  }

}
     }
getch();
}

Sample Output:
If we've array 4,1,13,6,16,7,5,23,1,3 , Output will be like following
4
6
16
23
7
5
3
1 

Sunday, 14 July 2013

Decimal to Binary Converstion

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
int num,bin[100],count=0,init=0,fin,temp;
cout<<"Enter the Number:";
cin>>num;
  while(num>0)
  {
    bin[count]=num%2;
    num=num/2;
    count++;
  }
fin=count-1;
   for(int i=0;i<count/2;i++)         // Reversing of Array
   {
      temp=bin[i];
      bin[i]=bin[fin];
      bin[fin]=temp;
      fin--;
   }

  cout<<"\nGiven Number in Binary is\n";
   for(i=0;i<count;i++)
   {
     cout<<bin[i];
   }
getch();
}

Saturday, 13 July 2013

Linked List (Creating nodes & Displaying Data)

About Program:
 "start"  is having the address of 1st node. Means "start" is pointing the 1st node as shown in figure in buttom of the page.
"void creat_node()" function is to create new node. I called "creat_node" function 4 time in the "main" therefore it will create 4 nodes.
"void print()" function is to display the data , user inserted in the node at the time of creation of node.
In "void creat_node()" function I created a temporary node "temp" then 1st I checked that whether the node user is going to create is 1st node or not , using following check.
"if(start==NULL)" .
If this Check get true then its mean this indicates to program that we are going to create 1st node.
If the newly created node is not the 1st node then we will find the correct place where it should be inserted that is after the last node and for this purpose i created "trivers" that will traverse until the last node. And when program will find the last node following statement will place the newly created node"temp" at the last.
"trivers->next=temp;"

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct node
{
   int data;
   node *next;
}*start;
void creat_node();
void print();
void main()
{
clrscr();
start=NULL;
 for(int i=1;i<=4;i++)
 {
   creat_node();
 }
  print();
getch();
}
  void creat_node()
  {
      node *temp=new node();
      cout<<"Enter Data:";
      cin>>temp->data;
      temp->next=NULL;
      if(start==NULL)
      {
start=temp;
      }
      else
      {
node *trivers=start;
 while(trivers->next!=NULL)
 {
    trivers=trivers->next;
 }
 trivers->next=temp;
      }
  }
    void print()
    {
      cout<<endl<<"You Have Entered Following Data\n";
       node *tri=start;
       while(tri!=NULL)
       {
cout<<tri->data<<endl;
tri=tri->next;
       }
    }

Graphical Description:

Contact :

E-mail:
               faraz.aki007@gmail.com
               faraz.aki007@yahoo.com
Cel#
                   +92308-5875990
                   +92341-5222847

Wednesday, 10 July 2013

Simple Calculator Using Class in C++

About program:
        "nominator" ,"denominator" and "res" are the attributes of the class "Rational". And "getter_setter","print","add","multiply" and "div" are the member functions of the class "Rational".

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Rational
{
 public:
  float nominator,denominator,res;
  Rational()
  {
  // Constructor of the Class , automatically will be called when object will be created.
  }

  void getter_setter()
  {
    cout<<"Enter 1st Number:";
    cin>>nominator;
    cout<<"Enter 2nd Number:";
    cin>>denominator;
  }

  void print()
  {
   cout<<res;
  }
  void add()
  {
  clrscr();
   res=nominator+denominator;

  }
  void multiply()
  {
    clrscr();
   res=nominator*denominator;

  }
  void div()
  {
     clrscr();
   res=nominator/denominator;

  }
 };
void main()
{
 clrscr();
 int opt;
 Rational obj;
 obj.getter_setter();
 clrscr();
do
{
 cout<<"1.Addition\n2.Multiplication\n3.Division\n5.Exit\nYour Choice:";
 cin>>opt;
 switch(opt)
 {
  case 1:
  obj.add();
  obj.print();
  break;
  case 2:
  obj.multiply();
  obj.print();
  break;
  case 3:
  obj.div();
  obj.print();
  break;
 }
 getch();
 clrscr();
}
while(opt!=5);

getch();
}

Friday, 5 July 2013

Data Insertion in 2D Array + Demonstration that how that is stored in 2D Array

Features of Program:
                                   In following program it is taught that how we can insert data in 2D array, and how data is stored in 2D array .


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int ar[5][2];

 for(int row=0;row<5;row++)
 {
   for(int col=0;col<2;col++)
   {
     cout<<"Enter The Number for row# "<<row+1<<" & Column# "<<col+1<<":";
     cin>>ar[row][col];
   }
 }
   for(int i=1;i<=15;i++)
   {

     for(int k=1;k<=11;k++)
     {
if(i==1||i==15)
{
cout<<"*";
}
else if(i%3==0)
{
cout<<"*";
}
else if(k==1||k==11||k==6)
{
cout<<"*";
}
else
{
cout<<" ";
}
     }
     cout<<endl;
   }


     int x=3,y=11;//,count=0;
     for(row=0;row<5;row++)
     {
       for(int col=0;col<2;col++)
       {
gotoxy(x,y);
cout<<ar[row][col];
x+=5;
       }
       y+=3;
       x=3;
     }
getch();
}

Reversing Integer Array + Dynamic Memory Allocation

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<alloc.h>
void main()
{
clrscr();
int num,*ar,init=0,fin,temp;
  cout<<"Enter the Number of Elements for Array:";
  cin>>num;
  fin=num-1;
  ar=(int *)malloc(sizeof(int));  // Dynamic Memory Allocation
  for(int i=0;i<num;i++)
  {
    cout<<"Enter the number:";
    cin>>ar[i];
  }
 for( i=1;i<=num/2;i++)
 {
   temp=ar[init];
   ar[init]=ar[fin];
   ar[fin]=temp;
   init++;
   fin--;
 }
 cout<<"After Reversing\n";
 for( i=0;i<num;i++)
 {
  cout<<ar[i]<<" ";
 }
getch();
}

Friday, 28 June 2013

Constructor in JAVA

Definition:
Constructor is a Method of the class that has the same name as the class name in which it is.
We don't need to call the constructor instead whenever we make the object of the Class Constructor of
this class is automatically called.
In JAVA we use constructor as we use in C++ ( in Object Oriented Programming) . Following
example will demonstrate that how can we use Constructor.

Example Program:

 

public class Test {

       Test()                                             // Constructor
       {
           System.out.println("Faraz");
           System.out.println("Awan");
       }
    public static void main(String[] args) {

                new Test();
    }
}


Allocating Memory Dynamically in C++

To allocate the memory  dynamically we use the keyword "malloc".

Dynamical Memory Allocation Example:
 For example if you want to take array size from user, we allocate memory dynamically. If we adopt following way it will generate error!!
int mem;
cout<<"Enter Array Size:";
cin>>mem;
int ar[mem];        // Constant Expression Require (Error)

Solution:

To resolve this issue we use "malloc" key word.
Following Program will help you to understand this.

#include<iostream.h>
#include<stdio.h>
#include<alloc.h>

void main(void)
{
  clrscr();

       int mem,*p;
      cout<<"Enter Array Size:";
      cin>>mem;
p=(int *) malloc (sizeof (int));

  for(int i=0;i<mem;i++)
   {
     
      cout<<"Enter Data:";
      cin>>p[i];
   }
getch();
}

Wednesday, 26 June 2013

Square Diagram (For Loop) in C++:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();

   for(int i=1;i<=10;i++)
   {
     for(int k=1;k<=10;k++)
     {
 if(i==1||i==10)
 {
  cout<<"*";
 }
 else if(k==1||k==10)
 {
  cout<<"*";
 }
 else
 {
   cout<<" ";
 }
     }
     cout<<endl;
   }
getch();
}

Output:
**********
*          *
*          *
*          *
*          *
*          *
*          *
*          *
*          *
**********

Stair Design (For Loop) in C++:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
int sp1=10,sp2=0;
   for(int i=1;i<=10;i++)
   {
     for(int spac=1;spac<=sp1;spac++)
     {
       cout<<" ";
     }
      for(int k=1;k<=2;k++)
      {
cout<<"*";
for(int l=0;l<sp2;l++)
{
cout<<" ";
}
      }
      sp2++;
      sp1--;
      cout<<endl;
   }
getch();
}

Output:
          **
         * *
        *  *
       *   *
      *    *
     *     *
    *      *
   *       *
  *        *
*          *

Friday, 21 June 2013

GPA Calculator

You can Download GPA Calculator from Following Link.
Note: After installation , package will automatically start installing .NET Framework . If you already have installed .NET Framework quit that installation.
Download link:
GPA Calculator Download Link

About GPA Calculator:
Developed by: Faraz Awan
This Calculator is Valid for the students of COMSATS University of Science & Technology or for those who's Universities has Following Grades' Distribution.

        Marks                           Grades(GPA)
        >=90                                   4
       >= 85 &&<=89                   3.7
       >= 80 &&<=84                   3.3
       >= 75 &&<=79                    3
       >=70 &&<=74                    2.7
       >= 65 &&<=69                   2.3
       >= 60 &&<=64                    2
       >= 55 &&<=59                   1.7
       >= 50 &&<=54                   1.3

About blog:

This Blog is about Software solutions, Assignments e.t.c.
Tutorials of Programming Languages , e.g C, C++, Java, C# , will also available.
If you have any issue or problem regarding any Programming language you can contact via this blog to get help.