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();
}