Thursday, 31 January 2013

roots of quad eq; in c++ by Zafar iqbal lavi

include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,disc,root1,root2;
cout<<"enter a"<<endl;
cin>>a;
cout<<"enter b"<<endl;
cin>>b;
cout<<"enter c"<<endl;
cin>>c;
disc=(b*b)-(4*a*c);
root1=(-b+sqrt(disc))/(2*a);
root2=(-b-sqrt(disc))/(2*a);
cout<<"root1"<<root1<<endl;
cout<<"root2"<<root2<<endl;
getch();
}

ternary operator in c++ by Zafar iqbal lavi

#include<iostream.h>
#include<conio.h>
void main()
{
int n;
cout<<"enter an integer"<<endl;
cin>>n;

(n>19?cout<<"greater":cout<<"smaller");

getch();
}

power function in c++ by Zafar Iqbal Lavi

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

void main()
{     double x,y,p;
cout<<"enter base            ";
cin>>x;
cout<<"enter it's power        ";
cin>>y;
p=pow(x,y);
cout<<"\n\nPower of "<<x<<" to "<<y<<" is "<<p;
getch();
}

pointer in c++ by Zafar Iqbal lavi

include<iostream.h>
#include<conio.h>
void main()
{

int n,m;
int*ptr;
int*ppp;
cout<<"enter two integers"<<endl;
cin>>n>>m;
    ptr=&n;
    ppp=&m;

cout<<"the value of n     "<<n<<endl;
cout<<"the address of n   "<<ptr<<endl;
cout<<endl<<endl<<endl<<endl;
cout<<"the value of m      "<<m<<endl;
cout<<"the address of m    "<<ppp;

getch();
}

pointer in c++ by Zafar Iqbal lavi

#include<iostream.h>
#include<conio.h>
void main()
{

int n;
int*ptr;
cout<<"enter an integer"<<endl;
cin>>n;
ptr=&n;
cout<<" the value is   "<<n<<endl;
cout<<"  the address is n"<<ptr;


getch();
}      

structure in c++ by zafar iqbal

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

struct student{
int rollno;
int marks;
float avg;
char grade;};


void main()
{student s;
cout<<"enter roll no"<<endl;
cin>>s.rollno;
cout<<"enter marks"<<endl;
cin>>s.marks;
cout<<"enter average"<<endl;
cin>>s.avg;
cout<<"enter grade"<<endl;
cin>>s.grade;

cout<<s.rollno<<endl;
cout<<s.marks<<endl;
cout<<s.avg<<endl;
cout<<s.grade;

getch();
}

tabel of give no using function in c++

include<iostream.h>
#include<conio.h>
void table(int a);
void main()
{
int t;
cout<<"enter table"<<endl;
cin>>t;
table(t);
getch();
}

void table(int a)
{
for(int n=1;n<=10;n++)
cout<<a<<"*"<<n<<"="<<a*n<<endl;
}

transpose of a matrix in c++

#include<iostream.h>
#include<conio.h>
void main()
{

int r,c,i,j;
int matrix[12][12];
int transpose[12][12];

cout<<"enter no of rows of matrix      ";
cin>>r;
cout<<"enter no of columns of matrix   ";
cin>>c;

cout<<"\n\n";
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{cout<<"matrix["<<i<<"]["<<j<<"]"<<"    ";
cin>>matrix[i][j];}

   cout<<"\n\nMATARIX IS\n\n";
    cout<<"\n\n";
    for(i=0;i<r;i++)
    {for(j=0;j<c;j++)
    cout<<matrix[i][j]<<"\t";
    cout<<endl<<endl;}

   cout<<"TRANSPOSE IS\n\n";
    for(i=0;i<c;i++)
    {for(j=0;j<r;j++)
    cout<<matrix[j][i]<<"\t";
    cout<<endl<<endl;}


getch();
}

multiplication of two matrices in c++

#include<iostream.h>
#include<conio.h>
void main()
{

int r1,r2,c1,c2,i,j,k;
int ham[12][12];
int tum[12][12];
int mul[12][12]={0,0,0,0,0,0,0,0,0,0,0,0};

        cout<<"enter no of row of first matrix         ";
        cin>>r1;
        cout<<"enter no of columns of first matrix     ";
        cin>>c1;
        cout<<endl<<"enter no of row of 2nd  matrix          ";
        cin>>r2;
        cout<<"enter no of columns of 2nd matrix       ";
        cin>>c2;

if(c1==r2)
{
     cout<<"\n\n";
     for(i=0;i<r1;i++)
     for(j=0;j<c1;j++)
     {cout<<"ham["<<i<<"]["<<j<<"]"<<"\t" ;
     cin>>ham[i][j];}

     cout<<"\n\n";
     for(i=0;i<r2;i++)
     for(j=0;j<c2;j++)
     {cout<<"tum["<<i<<"]["<<j<<"]"<<"\t";
     cin>>tum[i][j];}

     cout<<"\n\n";
     cout<<"MULTIPLICATION OF THE MATRICES IS"<<endl<<endl;
             for(i=0;i<r1;i++)              //control no of rows
         {for(j=0;j<c2;j++)             //control no of columns
         {for(k=0;k<c1;k++)             //control two parts of each member
         mul[i][j]=mul[i][j]+ham[i][k]*tum[k][j];
         cout<<mul[i][j]<<"\t";}
         cout<<endl;}


     }                                                                          //end of if
else
     cout<<"matrices are not in order";




    getch();
}                                                                            //end of main body










additon in horizontal of matrices in c++

#include<iostream.h>
#include<conio.h>
void main()
{

int r1,r2,c1,c2,i,j;
int matrix1[12][12];
int matrix2[12][12];
int add[12][12];

        cout<<"enter no of rows of 1st matrix       ";
        cin>>r1;
        cout<<"enter no of col of 1st matrix        ";
        cin>>c1;
        cout<<"\nenter no of rows of 2nd matrix       ";
        cin>>r2;
        cout<<"enter no of col of 2nd matrix        ";
        cin>>c2;

if(r1==r2&&c1==c2)
{
   cout<<"\n\n";
    for(i=0;i<r1;i++)
    for(j=0;j<c1;j++)
    {cout<<"matrix1["<<i<<"]["<<j<<"]"<<"\t";
    cin>>matrix1[i][j];}


   cout<<"\n\n";
    for(i=0;i<r2;i++)
    for(j=0;j<c2;j++)
    {cout<<"matrix2["<<i<<"]["<<j<<"]"<<"\t";
    cin>>matrix2[i][j];}

      cout<<"\n\n";
      for(i=0;i<r1;i++)
        {for(j=0;j<c1;j++)
        cout<<matrix1[i][j]<<"\t";
      cout<<"  ";
      for(j=0;j<c2;j++)
      cout<<matrix2[i][j]<<"\t";
      cout<<"  ";
      for(j=0;j<c2;j++)
      {add[i][j]=matrix1[i][j]+matrix2[i][j];
      cout<<add[i][j]<<"\t";}
        cout<<endl<<endl;}


}                                                  //end of if
else
cout<<"\norder is not same\n";
getch();
}

Addition of matrices in c++

#include<iostream.h>
#include<conio.h>
void main()
{

int r1,r2,c1,c2,i,j;
int matrix1[12][12];
int matrix2[12][12];
int add[12][12];

        cout<<"enter no of rows of 1st matrix       ";
        cin>>r1;
        cout<<"enter no of col of 1st matrix        ";
        cin>>c1;
        cout<<"\nenter no of rows of 2nd matrix       ";
        cin>>r2;
        cout<<"enter no of col of 2nd matrix        ";
        cin>>c2;

if(r1==r2&&c1==c2)
{
   cout<<"\n\n";
    for(i=0;i<r1;i++)
    for(j=0;j<c1;j++)
    {cout<<"matrix1["<<i<<"]["<<j<<"]";
    cin>>matrix1[i][j];}


   cout<<"\n\n";
    for(i=0;i<r2;i++)
    for(j=0;j<c2;j++)
    {cout<<"matrix2["<<i<<"]["<<j<<"]";
    cin>>matrix2[i][j];}

      cout<<"\n\n";
      cout<<"the first matrix is";
      cout<<"\n\n";
        for(i=0;i<r1;i++)
        {for(j=0;j<c1;j++)
        cout<<matrix1[i][j]<<"\t";
        cout<<endl;}

      cout<<"the 2nd matrix is";
      cout<<"\n\n";
        for(i=0;i<r2;i++)
        {for(j=0;j<c2;j++)
        cout<<matrix2[i][j]<<"\t";
        cout<<endl;}

   cout<<"\nTHE RESULT OF ADDITION IS\n";
   for(i=0;i<r2;i++)
    {for(j=0;j<c2;j++)
   {add[i][j]=matrix1[i][j]+matrix2[i][j];
   cout<<add[i][j]<<"\t";}
   cout<<endl;}

}                                                  //end of if
else
cout<<"\norder is not same\n";
getch();
}

Actual and reverse in array in c++

#include<iostream.h>
#include<conio.h>
void main()
{
int ham[5],i;
for(i=1;i<=5;i++)
{cout<<"enter an integer"<<endl;
cin>>ham[i];}
cout<<"actual value"<<endl;
for(i=1;i<=5;i++)
cout<<ham[i]<<endl;
cout<<"reverse value"<<endl;
for(i=5;i>0;i--)
cout<<ham[i]<<endl;


getch();
}

factorial of give numvber in c++

include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main()

{
clrscr();
int no;
long fact=1;
cout<<"enter no whose factorial is required"<<endl;
cin>>no;
for(int j=no; j>0;j--)
fact*=j;
cout<<"factorial is"<<setw(6)<<fact<<endl;

getch();
return 0;}

Wednesday, 30 January 2013

sum of five number

include<iostream.h>
#include<conio.h>
void main()
{int c,sum;
c=1;
sum=0;
while(c<=5)
{cout<<"number is:"<<c<<endl;
sum=sum+c;
c=c+1;}
cout<<"sum:"<<sum<<endl;
getch();
}

gander in c++

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char p;
cout<<"are yoiu male or female"<<endl;
cin>>p;
if(p=='m'||p=='M')
cout<<"you are male"<<endl;
else
if(p=='f'||p=='F')
cout<<"your are female"<<endl;
getch();
}

table of given number in c++

/PROG 33
#include<iostream.h>
#include<conio.h>
void main()
{
int table,length,c;
cout<<"enter table"<<endl;
cin>>table;
cout<<"enter length"<<endl;
cin>>length;
for(c=1;c<=length;c++)
cout<<table<<"*"<<c<<"="<<table*c<<endl;
getch();
}

vowel or not in c++

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char n;
cout<<"enter the alphabet"<<endl;
cin>>n;
switch(n)
{case 'a':
case 'A':
cout<<"vowel";
break;
case 'e':
case 'E':
cout<<"vowel";
break;
case 'i':
case 'I':
cout<<"vowel";
break;
case 'o':
case 'O':
cout<<"vowel";
break;
case 'u':
case 'U':
cout<<"vowel";
break;
default:
cout<<"not vowel";
break;}
getch();}

Average greater than give %age show cong...in c++

include<iostream.h>
#include<conio.h>
void main()
{
int e,u,m,avg;
cout<<"enter marks of eng"<<endl;
cin>>e;
cout<<"enter marks of urd"<<endl;
cin>>u;
cout<<"enter marks of math"<<endl;
cin>>m;
avg=(e+u+m)/3;
if(avg>80)
{cout<<"you are above standard"<<endl;
cout<<"admission granted"<<endl;}
getch();
}

Area and circumference in c++

include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
const float pi=3.14159;
float radius,area,circum;
//read radius of a circle
cout<<"enter r"<<endl;
cin>>radius;
//compute area
area=pi*radius*radius;
cout<<"the area"<<area<<endl;
//comput circumference
circum=2*pi*radius;
cout<<"circum"<<circum<<endl;
getch();
}

sum using char in c++

#include<iostream.h>
#include<conio.h>
void main()
{char a,b,c;
a='2';
b='6';
c=a+b;
cout<<c<<endl;
getch();
}

Tuesday, 29 January 2013

single,complete,average link clustring using Matlab


x=input('x=');
y=input('Y=');
subplot(4,1,1);
plot(x,y,'r*');
xlabel('x-Values')
ylabel('Y-Values')
n=length(x);
j=1;
i=1;
k=1;
  while j<n
    for i=i:n-1
       e_dis=sqrt(((x(i+1)-x(j)).^2)+((y(i+1)-y(j)).^2));
       d(k)=e_dis; %#ok<AGROW>
      k= k+1;
    end
    j=j+1;
    i=j;
  end
  display(d);
   m=min(d);
   display('Minimum Distance is');
   display(m)
   subplot(4,1,2)
       Y = pdist(x,'cityblock');
       Z = linkage(d,'complete');
       [H, T] = dendrogram(Z);
       xlabel(' complete_link Dendrogram');
 subplot(4,1,3)
 Y = pdist(x,'cityblock');
       Z = linkage(d,'Average');
       [H, T] = dendrogram(Z);
       xlabel('Average Link_Dendrogram');
       subplot(4,1,4)
       Y = pdist(x,'cityblock');
       Z = linkage(d,'single');
       [H, T] = dendrogram(Z);
       xlabel(' Single Link_Dendrogram');

Average_Link Clustring Using Matlab


x=input('x=');
y=input('Y=');
subplot(2,1,1);
plot(x,y,'r*');
xlabel('x-Values')
ylabel('Y-Values')
n=length(x);
j=1;
i=1;
k=1;
  while j<n
    for i=i:n-1
       e_dis=sqrt(((x(i+1)-x(j)).^2)+((y(i+1)-y(j)).^2));
       d(k)=e_dis; %#ok<AGROW>
      k= k+1;
display(e_dis);

    end
    j=j+1;
    i=j;
  end
   m=min(d);
   display('Minimum Distance is');
   display(m)
   subplot(2,1,2)
       Y = pdist(x,'cityblock');
       Z = linkage(d,'Average');
       [H, T] = dendrogram(Z);
       xlabel('Dendrogram');

complete_link clustring Using Matlab


x=input('x=');
y=input('Y=');
subplot(4,1,1);
plot(x,y,'r*');
xlabel('x-Values')
ylabel('Y-Values')
n=length(x);
j=1;
i=1;
k=1;
  while j<n
    for i=i:n-1
       e_dis=sqrt(((x(i+1)-x(j)).^2)+((y(i+1)-y(j)).^2));
       d(k)=e_dis; %#ok<AGROW>
      k= k+1;
    end
    j=j+1;
    i=j;
  end
  display(d);
   m=min(d);
   display('Minimum Distance is');
   display(m)
   subplot(4,1,2)
       Y = pdist(x,'cityblock');
       Z = linkage(d,'complete');
       [H, T] = dendrogram(Z);
       xlabel(' complete_link Dendrogram');

Single Link clustering using matlab


%Single Link_Clustring
x=input('x=');
y=input('Y=');
subplot(2,1,1);
plot(x,y,'r*');
xlabel('x-Values')
ylabel('Y-Values')
n=length(x);
j=1;
i=1;
k=1;
  while j<n
    for i=i:n-1
       e_dis=sqrt(((x(i+1)-x(j)).^2)+((y(i+1)-y(j)).^2));
       d(k)=e_dis; %#ok<AGROW>
      k= k+1;
display(e_dis);

    end
    j=j+1;
    i=j;
  end
   m=min(d);
   display('Minimum Distance is');
   display(m)
   subplot(2,1,2)
       Y = pdist(x,'cityblock');
       Z = linkage(d,'single');
       [H, T] = dendrogram(Z);
       xlabel('Single link clustring Dendrogram');

Friday, 25 January 2013

pointer and array in c++


            #include <iostream>
            #include <conio>


             void main()

             {
              int arr[44],*ptr,i;
              cout<<"Enter element into Array\n";
              for(i=0;i<5;i++)
              {
               cin>>arr[i];
              }
              ptr=arr;
              for(i=0;i<5;i++)

              {
               cout<<"arr["<<i<<"]"<<"=\t"<<arr[i]<<endl;
              }
              cout<<"For pointer\n";
              for(i=0;i<5;i++)

              {
               cout<<"arr["<<i<<"]"<<"=\t"<<*(ptr++)<<endl;
              }


              getch();
             }

pointer and for loop in c++

#include <iostream>
            #include <conio>


             void main()

             {
              int arr[44],*ptr,i;
              cout<<"Enter element into Array\n";
              for(i=0;i<5;i++)
              {
               cin>>arr[i];
              }
              ptr=&arr[0];
              for(i=0;i<5;i++)

              {
               cout<<"arr["<<i<<"]"<<"=\t"<<arr[i]<<endl;
              }
              cout<<"For pointer\n";
              for(i=0;i<5;i++)

              {
               cout<<"arr["<<i<<"]"<<"=\t"<<*(ptr+i)<<endl;
              }


              getch();
             }

check size of int,char,float,double

 #include <iostream>
        #include <conio>
        #include <stdio>

             void main()

             {

               cout<<"Size of char\t"<<sizeof(char )<<endl;
               cout<<"Size of float\t"<<sizeof(float)<<endl;
               cout<<"Size of doubel\t"<<sizeof(double)<<endl;
             getch();}

pointer in c++ #1

 #include <iostream>
        #include <conio>
        #include <stdio>

             void main()

             {

               cout<<"Size of short\t"<<sizeof(short)<<endl;
               cout<<"Size of int\t"<<sizeof(int)<<endl;
               cout<<"Size of long\t"<<sizeof(long)<<endl;
             getch();}

Name space in using c++

#include <iostream>
#include <conio>

 namespace  geo
{
const double pi=3.14159;
double circumf(double radius)
{
 return 2*pi*radius;
}
}


  void main()
  {

       using namespace geo;
  double d=circumf(10.2);
  cout<<d<<endl;
   getch();
   }

Name space in c++

#include <iostream>
#include <conio>

 namespace  geo
{
const double pi=3.14159;
double circumf(double radius)
{
 return 2*pi*radius;
}
}


  void main()
  {


  double d=geo::circumf(10.2);
  cout<<d<<endl;
   getch();
   }

Derivative using c++



           #include <iostream>
           #include <conio>
           #include <stdlib>
           char   ch;


           int d[33],a[55],i,c,j,p,n,q,k;
           void main()

           {


           while(1)
           {
            clrscr();
           cout<<"Enter the highest  power of  X \t";cin>>n;
           cout<<"Enter the coefficient of x^n(x^0,x^1,x^2,........x^n) and constant term\n";
           for(i=0;i<=n;i++)
           {
            cin>>a[i];
           }

              q=n;
           for(i=0;i<n;i++)
           {

            j=q;
            d[i]=j*a[i];
            q--;
           }

           cout<<"Your desire derivative is\ndy/dx=\t";
           k=n;
           for(i=0;i<k;i++)
           {
              p=0;
           p=n-1;
            if(i==0)
            {
             cout<<d[i]<<"X^"<<p;
            }

            else
            cout<<"+"<<d[i]<<"x^"<<p;
            n--;
           }


           getch();

                     }

                     }


Using array performing arthimatic operation in c++



 /********************************************/

        #include <iostream>
        #include <conio>


          class DS

        {

          private:
            int my_array[2],i,result;
            char opr;

            public:

              void input()

              {
               cout<<"Enter any two number\n";
               for(i=0;i<2;i++)
                cin>>my_array[i];

              }

              /********************/
              void show()
              {
                while(1)
                {

                cout<<"\t\tchoise any operator \n\t\t+\n\t\t-\n\t\t*\n\t\t/\t\t\n\t\tfor clear screen press C\n\t\tif you want to enter number again then press A\n";
                cin>>opr;
                switch(opr)

                {
                    case '+':

                   result=my_array[0]+my_array[1];
                   cout<<"Result=\t\t"<<result<<endl;

                   break;
                    case '-':

                   result=my_array[0]-my_array[1];
                   cout<<"Result=\t\t"<<result<<endl;
                   break;
                    case '*':

                   result=my_array[0]*my_array[1];
                   cout<<"Result=\t\t"<<result<<endl;
                   break;
                    case '/':

                   result=my_array[0]/my_array[1];
                   cout<<"Result=\t\t"<<result<<endl;
                   break;
                   case 'c':
                   case 'C':
                     clrscr();
                     break;

                   case 'A':
                   case 'a':
                     input();
                     break;
                   default:
                    cout<<"Invalid option\n\n";
                    break;
                }


            }
                 }


        };

        void main()

        {
                DS s;
                s.input();
                s.show();

        getch();}

Thursday, 24 January 2013

simple virus in c++

#include <iostream>
     #include <conio>

       void main()

       {
            int i;
       while(1)
       {
        cout<<"\a";
       }
       getch();}

simple database using c++





    #include <iostream>
    #include <stdio>
    #include <conio>
   class bank

   {

    private:
    static int ar;
    char name[44],id[33],acount_no[44];
    int save_b,m_i;


   public:
     bank()

     {

      ar;
     }


     void input()

     {

      cout<<"\t\tenter your id number\t";gets(id);
      cout<<"\t\tenter your name\t\t";gets(name);
      cout<<"\t\tenter your acount_no\t";gets(acount_no);
      cout<<"\t\thow many money do you want to deposit in your account\t";cin>>save_b;
     }
     void save()

     {
            cout<<"\t\tYour id is\t"<<id<<endl;
            cout<<"\t\tYour name is\t"<<name<<endl;
            cout<<"\t\tYour acount_no is\t"<<acount_no<<endl;
            cout<< "\t\tYour deposit money is\t"<<save_b<<endl;
     }






       void calculates()
       {

        m_i=save_b*ar/12;
        cout<<"Monthly interest rate is\t"<<m_i<<endl;


       }

         int getcount()
         {
          return ar++;
         }



   };

        int bank::ar=100000;
     void main()
     {

     bank k1,k2;
     k1.input();
     k1.save();
     k1.calculates();
   
     getch();}

finding character in string using array in c++


            #include <iostream>
            #include <conio>

              void main()

            {

            char arr[35],n;
            int i,loc;
                        cout<<"Enter characters\n";
            for(i=0;i<5;i++)
            {

            cin>>arr[i];}
                        cout<<"Enter any charter\t";cin>>n;
                        cout<<endl;
                  for(i=0;i<5;i++)

                  {
                    if(arr[i]==n)

                    {
                      loc=1;
                    }
                  }

                  if(loc==1)

                  cout<<"found character \t"<<n<<endl;

                         else
                         cout<<"Againg try\n";
           getch();
            }

Reverse string using array in c++

#include <iostream>
 #include <conio>


   void main()

  {

  char arr[5];

  cout<<"Enter charaterters\n";
  for(int i=0;i<5;i++)

  {
    cin>>arr[i];


  }
    cout<<"Reverse order is\n";
              for(int i=5;i>=0;i--)
  {
   cout<<arr[i]<<"  ";

  }

  getch();
  }

Reverse string in c++

#include <iostream>
                                                #include <stdio>
                                                #include <conio>
                                                #include <string>


                                       char str[55];


                                     void main(void)
                                     {
                                             cout<<"Enter any string\t";gets(str);
                                             cout<<endl;
                                             cout<<"Your desire string is\t"<<str<<endl;
                                             cout<<"Reverse of Your string is\t";
                                             cout<<strrev(str);
                                     getch();}

AND ,OR gate in c++





          #include <iostream>
          #include <conio>


            void And();
            void oR();

            void main()

            {
             char y;
             while(1)

             {
              cout<<"\tPress A for And gate operation\n\tPress R for OR gate\n";
              cin>>y;
              if(y=='A')


               { And();   }
               else
               if(y=='R')

               {
                oR();
               }



             }

             getch();
            }


            /**********************************************/

              void And()

              {
              int a,b;
               cout<<"Enter first binary formated input\t";
               cin>>a;
               cout<<"Enter 2nd binary formated input  \t";
               cin>>b;

               if(a==0&&b==0||a==0&&b==1||a==1&&b==0)
   {cout<<"         -------\n";

   cout<<a<<"------|        \""<<"------0"<<endl;

   cout<<b<<"------|   AND  /\n";
   cout<<"          ------\n";    }
                else
                if(a==1&&b==1)
                {
   cout<<"         -------\n";

   cout<<a<<"------|        \""<<"------1"<<endl;

   cout<<b<<"------|   AND  /\n";
   cout<<"          ------\n";    }
              




              }


             /*******************************************/




              void oR()

              {  int a,b;
               cout<<"Enter first binary formated input\t";
               cin>>a;
               cout<<"Enter 2nd binary formated input  \t";
               cin>>b;
               if(a==1||b==1&&a==0||b==1&&a==1||b==1)
{  cout<<"         -------\n";
   cout<<"         -------\n";

   cout<<a<<"------|        \""<<"------1"<<endl;

   cout<<b<<"------|   AND  /\n";
   cout<<"          ------\n";
  cout<<"         -------\n";  }
               else
               if(a==0&&b==0)
{ cout<<"         -------\n";
   cout<<"         -------\n";

   cout<<a<<"------|        \""<<"------0"<<endl;

   cout<<b<<"------|   OR  /\n";
   cout<<"          ------/\n";
  cout<<"       -------/\n";

               }

              }





Wednesday, 23 January 2013

Insertion in Array


#include <iostream>
#include <conio>
void main()
{
int arr[6];
int a;
cout<<"Enter integer in arrays"<<endl;
for(int i=0;i<5;i++)
{
cin>>arr[i];
}
for(int i=0;i<5;i++)
{cout<<"["<<arr[i]<<"]"<<" ";
}cout<<endl;
  int s=6;
for(int i=0;i<=2;i++)
{
arr[s]=arr[s-1];
s--;}
cin>>arr[3];
for(int i=0;i<6;i++)
{cout<<"["<<arr[i]<<"]"<<" ";}

getch();
}

Binary to Decimal conversion using c++


#include <iostream.h>
#include <conio.h>
void main()
{
int n,b,d,arr[10],ar[10],a[10];
cout<<"enter how many no"<<endl;
cin>>n;
b=0;
n--;
for(int i=n;i>=0;i--)
{
cout<<"enter binary no"<<endl;
cin>>arr[i];
b++;
}

n=1;
for(int i=0;i<=b;i++)
{
ar[i]=n;
n=n*2;}
b--;
for(int j=0;j<=b;j++)
{
a[j]=arr[j]*ar[j];
d=0;
for(int j=0;j<=b;j++)
d=d+a[j];}
cout<<"conversion="<<d<<endl;
getch();
}

conversion of string to integer and integer into string


   #include <iostream>
   #include <stdio>
   #include <stdlib>
   #include <math>
   #include <conio>
   #include <ctype>

       int a,opt,n;
   char str[4443],c;
    void main ()
{



  while(1)

  {

  clrscr();
   cout<<"\t\tPress 1 for convert string into int\n\t\tPress 2 for convert int to string\n\t\tPress 3 for convert char into int\n\t\tPress 4 for convert int into char\n\t\tpress 5 for adding of two interger\n";
   cin>>opt;
   switch(opt)

   {

   case 1:

   cout<<"Enter any string\t";gets(str);
   a=atoi(str);
   cout<<"String convert into interget is\t"<<a<<endl;

     break;
     case 3:
       cout<<"Enter any charater\t";
       cin>>c;
       n=toascii(c);
       cout<<"The value in interger is\t"<<n<<endl;
       break;
       case 4:
       cout<<"Enter any integer\t";cin>>n;

       case 5:

       int d,f,g;
       cout<<"Enter any two number which do you want to Add\n";
       cin>>d>>f;

             g=d+f;
         cout<<"Sum of two interger\t"<<g<<endl;


         break;

   }



    system("pause");


}  }

Returning values from fuction and also passing value to the function in matlab



%--------------Returning values from fuction and also passing value to the functions-------%

a=input('Enter 1st num\n');
b=input('Enter 2nd num\n');
c=input('Enter 3rd num\n');
p=ret(a,b,c);
fprintf('the product of your 3 number is=%d\n',p);
%--------------===============================--------------------------------------------%


  function[z]=ret(a,b,c);
z=a*b*c;

basically in c,c++ we use this syntax as
z=a*b*c;
return z;
but here we return z as
function[z]=ret(a,b,c);
which mean that we return the value of z after calculation to the function ret(a,b,c)which
also contain 3 parameter variable%--------------------------------
 

Value return from function



%---------------------------
main file c is
p=show();
fprintf('cube=%d\n',p);
%--------------------------


 %here i use a program that tell us how value return from function %



function[z]=show();
x=input('Enter any number\n');

z=1;
z=x*x*x;


  in c++ we use this syntax as
%------------------------------
 
 z=x*x*x;
return z;

but here we return the variable in the above function as
syntax as


  function[z]=show();
% that's mean we return z after calculation to the function show() which use in c.m file

if else statement in Matlab




            /* if else in matlab*/



n=input('Enter a number\n');
if(mod(n,2)==0)
    for x=1:1:10
    fprintf('%d*%d=%d\n',n,x,n*x);
    end
   
    else
        for x=5:1:15
        fprintf('%d*%d=%d\n',n,x,n*x);
        end
        end



/*************************************Another syntax is*************************/



            n=input('Enter a number\n');
if(mod(n,2)==0)
    for x=1:1:10
    fprintf('%d*%d=%d\n',n,x,n*x);
    end  
else
        if(mod(n,2)==1)
        for x=5:1:15
        fprintf('%d*%d=%d\n',n,x,n*x);
        end
        end
end

Function in matlab



this m.file name and function name is always same minded
function[]=show(a);
x=a;
for i=1:1:10
    z=x*i;
    fprintf('%d*%d=%d\n',x,i,z);
end
end


another function 2nd m file

n=input('Enter any number\n');
show(n);

while loop and if statement in matlab


 


          /**************************************************/
             
  if and while loop in matlab
 


               %table %
i=1;
x=input('Enter any number\n');
if(x<10)
    while i<11
        z=x*i;
        fprintf('%d*%d=%d\n',x,i,z);
        i=i+1;
    end
    end

  for loop
 

            %table %
i=1;
x=input('Enter any number\n');
if(x<10)
    for i=1:1:10
        z=x*i;
        fprintf('%d*%d=%d\n',x,i,z);
       
    end
    end

Matlab programing tutorial


Built-in function
  Log();
  Sqrt();
  Area=pi*r^2
  Circumference=2pi*r
  Loops
1)FOR loop
           syntax
                      for i=initial value:increment:termination point
                      statement

                     like As
                     for i=0:1:10

                           statement

e.g.
                            sum=0;
                         for x=1:1:10
                          sum=sum+x;
              fprintf(‘Sum=’,sum);
end
  program
1)sum of all the even # from 0 to 20
  While loop
                                               Syntax
                                         
                                     While i<10
                                         Statement
                                       i=i+1;

            Conditional statement

                         1)If
                                            Syntax
                                                           If(x<10)
                                                          Statement
2)
         if else
                             if(x<10)

                                   statement
                         else
                                  statement
                             
end
end

  plot(x,y)
  x=0:10:1000;
  y=x.^2;
  y=x.^3
  x label(‘x-axis’);
  y label(‘y-axis’);
  title(‘Hello word’);
  Grid on; /*command for graphs*/
  Hold on;/*command for Graph*/
  Z=x^.3
  Plot(x,z);
  Hold off;

       Write a program which input one number if number is even then your program display table of that number but range of table must be o to 15 but if the input number is
And odd number then your program show table of that number which range is o to 10.
Best of luck
n =input(‘Enter a number \n’);
if(mod(n,2)= =0)
for x=0:1:15
fprintf(‘%d*%d=%d\n’,n,x,n*x);
else
for x:0:1:10
fprintf(‘%d*%d=%d\n’,n,x,n*x);
end

  Plot a Graph for specific Range

     Plot(x,a)
Y=[-100:20:100]
Plot(y)
Length(y)
Subplot(2,2,1)
Plot(z)
Subplot(2,2,2)
Plot(y)
Subplot(2,2,3)
  Roots
                                Y=[1 0 4 2 0 9 ]
                           root(y)











                       








           







Decimal to Binary conversion using array in c++

 #include <iostream>
             #include <conio>


              void main()

              {
                      int ar[44],n,count,i,j;
                      cout<<"Enter decimal number\t";cin>>n;
                      i=0;
                      while(n>=1)
                      {

                        ar[i]=n%2;
                        n=n/2;
                        i++;
                      }
                       i--;
                      cout<<"Binary conversion is\t";
                        for(j=i;j>=0;j--)

                        {
                         cout<<ar[j]<<" ";
                        }

              getch();}

Tuesday, 22 January 2013

constructer


#include<iostream.h>
#include<conio.h>
class student
{
private:
int marks;
char grade;
public:
student () //constructer
{
marks=80;
grade='A';
}
void show()
{
cout<<"\n marks is :"<<marks<<endl;
cout<<"\n the grade is :"<<grade<<endl;
}
};
void main()
{
student s1;
cout<<"record of s1";
s1.show();
getch();
}

Queu implementation UsinG Linked list


/**********************************************************/
               /*Queu implementation UsinG Linked list*/
                 /*Header files are!*/

                                                         #include <iostream>
                                                         #include <conio>
                                                         #include <stdlib>

         /*Define a class */


                    class cQueu
                 {
                   private:
   /*ABSTDT are!*/

                               struct node
                               { int data;
                                 node *link;
                               };
                        node    *front;
                        node    *rear;


                 public:

                   cQueu();
                   ~cQueu();
                   void insert();
                   void del();
                   void show();
            };    /*End of class */

                       /*Constructor is define*/
                        cQueu::cQueu()

                      {
                         front=rear=NULL;
                      }

                      /*Distructor is define*/


                        cQueu::~cQueu()

                       {
                         cout<<"Node are destoryed\n";

                       }


                /*insert() function define here*/

                      void cQueu::insert()

                    {
                         node *t;

                         t=new node;

                         if(t==NULL)

                           cout<<"Overflow\n";

                        else

                     {
                           cout<<"Enter element\t";
                           cin>>t->data;
                           t->link=NULL;

                         if(rear==NULL)

                            rear=front=t;

                        else

                      {
                        rear->link=t;
                      }



                     }

                    }                /*Defining delete function()*/




                     void  cQueu::del()

                    {
                      node *n;

                      if(front==NULL)


                      cout<<"Under flow\n";

                      else

                      {
                         cout<<front->data<<"\t:"<<"Has been deleted\n";

                         n=front;
                         front=front->link;
                         delete n;
                      }
                    }
                         /*Defining  show fun()*/
                       void cQueu::show()

                       {
                             if(front==NULL&& rear==NULL)
                             cout<<"Queu is empty\n";

                             else


                             {
                              while(rear!=NULL)

                                {cout<<rear->data<<"  ";
                                cout<<endl;
                                rear=rear->link;  }


                             }

                       }

                            /*Defining main function()*/
                                  void main()
                              {
                                  cQueu m;

                                  int opt;

                                  while(1)

                               {
                                 cout<<"Press 1 to enter element in the Queu:\n";
                                 cout<<"Press 2 to delete element in the Queu:\n";
                                 cout<<"Press 3 to show the element of the Queu:\n";
                                 cout<<"Press 4 to Exit the program from the main menu\n";


                                 cin>>opt;


                                 switch(opt)
                               {
                                 case 1:m.insert();break;
                                 case 2:m.del();break;
                                 case 3:m.show();break;
                                 case 4:exit(1);break;
                                 case 5:cout<<"\b";


                               }


                               }

                              getch();}

link list implementation


/*===================link list implementation=============*/
                   #include <iostream>
                   #include <conio>
                   #include <stdlib>
                   /***************/

      struct node
    {
       int data;

       node *link;
    };

           node *head=NULL;


     void main()
{
   void append();
   void display();
   void insert();
   void dele();
    int opt;
   while(1)
 {
    cout<<"*********************************************\n";
    cout<<"=============================================\n";
    cout<<"      MAIN MENU\n";
    cout<<"                    1:append                    \n";
    cout<<"                    2:Display                  \n";
     cout<<"                   3:Insert                  \n";
      cout<<"                  4:Delete                  \n";
      cout<<"                  5:EXIT                 \n";
    cout<<"=============================================\n";
    cout<<"**********************************************\n";
    cout<<endl;
    cin>>opt;
    switch(opt)
  {
    case 1:
    append();
    break;

    case 2:
    display();
   break;
   case 3:
     insert();
     break;

     case 4:

     dele();

     break;

     case 5:

     exit(0);

     break;
 }}                   getch();
                                }



             /**************************************/
                  void append()
                {
                   node *t,*n=head;
                 t=new node;

                    cout<<"               Enter element in link list\t\t";

                  cin>>t->data;
                  cout<<endl;

               t->link=NULL;

                 if(head==NULL)
                   head=t;

                   else
                 {

               while(n->link!=NULL)

                { n=n->link; }
                 n->link=t;

                   }
                           }
             /**************************************************/
                void display()
              {  node *t,*n=head;
                   if(n==NULL)

                 cout<<"link list is empty:";
              else
            {
              while(n!=NULL)

               { cout<<"    Value :                                 \t"<<n->data<<endl;
                n=n->link;}
            }

              }           void insert()
                  {
                     node *t,*n=head;
                    int num;

                    cout<<"Enter integer value:\t\t";
                    cin>>num;
                  cout<<endl;
                  while( (n->data!=num) && (n!=NULL) )

                   n=n->link;

                   if(n==NULL)

                cout<<"           Element not found                             \n\n ";


                else

              {
                         t=new node ;


                         cout<<"Enter element\t\t";
                         cin>>t->data;

                         cout<<endl;
                         t->link=n->link;
                         n->link=t;
               }                             }


                          /*================================================*/
                                     void dele()
                                  {
                                       node *t,*n=head;
                                       int num;
                                  if(head==NULL)
                                  {
                                    cout<<"List is Empty\n\n";
                                    return;
                                  }
                                        cout<<"        Enter element to be deleted \t\t";
                                        cin>>num;
                                        cout<<endl;
                                     while(n->data!=num)

                                     {
                                        t=n;
                                        n->link;

                                        if(n==NULL)
                                      {
                                         cout<<"            Element not found\n\n";

                                       }
                                          return ;}
                                                    if(n==head)
                                                  {
                                                     head=n->link;
                                                     delete n;
                                                   }

                                                         else

                                                     {
                                                        t->link=n->link;
                                                        delete n;
                                                     }

                                               }








Translate