Monday, December 5, 2011

A BAD news to all...

Our Head Of the Department(Information Technology), Prof.P.Duraiswamy was expired today(5-12-11) noon.....



"Our hearts are saddened by your loss and our thoughts and prayers are with you"



"Lets Pray for him at this time of sorrow"......

Tuesday, January 18, 2011

O.S->WAIT SYSTEM CALL

WAIT  SYSTEM  CALL


 AIM:

            To write a c program to implement wait system calls.

 ALGORITHM:

     STEP 1:  Start the program.
     STEP 2:  Include the header files.
     STEP 3:  Declare the variable pid and assign i=0,pid=fork( ).
     STEP 4:  If pid=0 then child starts.
     STEP 5:  For i=0,i less than 10 print the value of i.
     STEP 6:  Child process ends.
     STEP 7:  Else child ends now in parent process.
     STEP 8:  Stop the program.






















PROGRAM:

  #include<stdio.h>
  #include<sys/wait.h>
  int main()
  {
    int pid,i=0;
    printf("\n ready to fork");
    pid=fork();
    if(pid==0)
     {
       printf("\n child starts\n");
       for(i=0;i<10;i++)
       printf("\n%d\n",i);
       printf("child ends\n");
       exit(0);
     }
    else
     {
       wait(0);
       printf("child ends now in parent process");
       printf("exist status");
     }
  }

OUTPUT:

$./a.out
 Ready to fork
 Child starts
 0
 1
 2
 3
 4
 5
 6
 7
 8
 9
 Child ends
 Ready to fork child ends now in parent process
 exit status

Saturday, January 15, 2011

OS-> STAT SYSTEM CALL


STAT SYSTEM CALL



 AIM:

           To write a c-program to implement stat system call.

 ALGORITHM:

    STEP 1:  Start the program.
    STEP 2:  Include the header file as <sys/stat.h>
    STEP 3:  In main have three arguments such as i,avge,argv.
    STEP 4:  Declare sbuffs as structure variable that structure have stat.
    STEP 5:  To display the filename,node1,user id,group id,mode of the
                    corresponding system.
    STEP 6:  Stop the program.





















PROGRAM:

 #include<stdio.h>
 #include<sys/stat.h>
 main(int i,int avge,char**argv)
  {
    struct stat sbuff;
    if(!stat(argv[i],&sbuff)==-1)
    printf("could not stat file",1);
    printf("\n file name:%s",argv[i]);
    printf("\n inode no:%i",sbuff.st_ino);
    printf("\n user id:%u",sbuff.st_uid);
    printf("\n groupid:%g",sbuff.st_gid);
    printf("\n mode:%f",sbuff.st_mode):
    printf("\n size of flie:%d",sbuff.st_size);
    exit(0);
  }



OUTPUT:

 $ cc stat.c
 $./a.out
 File name: HOSTNAME=net64
 inode no: 0
 User id: 24641422
 Groupid:-1.79259
 Mode:-1.792591
 Size of the file:0



OS-> I/O SYSTEM CALL

I/O SYSTEM CALL

AIM:

          To write a c program using i/o system call to open, read and write a file.

ALGORITHM:

        STEP 1: start the program.
        STEP 2: include the header file as<fcntl.h> and <sys/stat.h>
        STEP 3: create the buffer variable with size of 50.
        STEP 4: create a new file using cat and write the data into the file.
        STEP 5: open a file in read only mode and read the content of file and place                                                                                                                 
                       it in buffer.    
        STEP 6: write the buffer content to a file which is opened in write
                       only mode.
        STEP 7: close the files.
        STEP 8: stop the program.




















PROGRAM:

 #include<stdio.h>
 #include<fcntl.h>
 #include<sys/stat.h>
 #include<sys/type.h>
 int main()
  {
   int fp1,fp2,n;
   char buff[50];
   fp1=open("a.txt",O_RDONLY);
   fp2=open(“b.txt”,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR);  
   while(n=read(fp1,buff,50)>0)
   write(fp2,&buff,50);
   close(fp1);
   close(fp2);
   exit(0);
  }





OUTPUT:

  $ cc ios.c
  $./a.out
  $ cat b.txt
  hai
  hello


OS-> LISTING OF FILES USING UNIX COMMAND

LISTING OF FILES USING UNIX COMMAND


AIM:
      
        To write a c program to list the files using UNIX commands.

ALGORITHM:
      
        STEP 1: Start the program
        STEP 2: Create the new child process using the fork ( ) in UNIX
        STEP 3: List the files available in specified directory using execl function.
        STEP 4: The list of available files are displayed in the terminal.
        STEP 5: Stop the program.


















PROGRAM:

 #include<stdio.h>
 #include<unistd.h>
 main()
  {
    int pid;
    pid=fork();
    if(pid==0)
    {
      printf("execution starts\n");
      execl("/bin/ls","ls","-1",(char*)0);
      printf("execution did not work\n");
    }
    else
    {
      wait(0);
      printf("parent:is completed in child");
    }
  }


OUTPUT:

$cc list.c
$./a.out
Execution starts
a.c
child.c
tharu.sh
sam.sh
y.tab.h
parent is completed in child

OS-> GETPID SYSTEM CALL

GETPID SYSTEM CALL


AIM:
   
            To write a c program to implement getpid system call.

ALGORITHM:

    STEP 1:  Start the program.
    STEP 2:  Include the header file.
    STEP 3:  Declare the variable pid.
    STEP 4:  Assign pid=fork().
    STEP 5:  If pid is greater than zero display the parent and child before
                    fork.
    STEP 6:  Else if pid==0 display parent and child on executing
    STEP 7:  Else display fork error.
    STEP 8:  Stop the program.



















PROGRAM:

#include<stdio.h>
int main()
 {
   int pid;
   printf("before fork\n");
   pid=fork();
   if(pid>0)
    {
      sleep(1);
      printf("parent%d,\nchild%d",getpid(),pid);
    }
   elseif(pid==0)
    {
      printf("parent%d,\nchild%d",getppid(),getpid());
    }
   else
    {
      printf("\nfork error");
      exit(1);
    }
   printf("both executing\n");
   exit(0);
 }


OUTPUT:

 $ cc getpid.c
 $./a.out
 Before fork
 Parent 3406
 Child 3407 both executing
 Parent 3406
 Child 3407 both executing

OS->FORK SYSTEM CALL

FORK SYSTEM CALL


 AIM:

                To write a c-program to implement fork system call.

 ALGORITHM:

      STEP 1:  Start the program
    STEP 2:  Include the header file.
    STEP 3:  Declare the variable pid.
    STEP 4:  If pid=fork() is less than zero print "fork error".
    STEP 5:  Else if pid=0 print "child process" otherwise print "parent  
                   Process.                    
    STEP 6:  Display the output.
    STEP 7:  Stop the program.


















PROGRAM:
   
     #include<stdio.h>
     main()
     {
       int pid;
       if((pid=fork())<0)
         {
           printf("fork error\n");
           exit(1);
         }
       else if(pid==0)
         {
           printf("child process\n");
         }
       else
         {
            printf("parent process\n");
            wait(0);
         }
     }



    OUTPUT:

    $ cc fork.c
    $./a.out
    Child process
    Parent process








Wednesday, October 6, 2010

PROGRAM USING IMPLEMENTATION OF TYPE CONVERSION

Ex No.2b PROGRAM USING IMPLEMENTATION OF TYPE CONVERSION
18-8-10

AIM:
To write a c++ program to perform type conversion from basic type to class type and class type to basic type.

ALGORTHIM:
Step 1: Start the program.
Step 2: Use constructor to convert basic type to class type.
Step 3: Use conversion function to convert class type to basic type.
Step 4: Display the result.
Step 5: Stop the program.

PROGRAM:
#include<iostream.h>
#include<conio.h>
class complex
{
int x,y;
double a,b;
public:
complex(int real,int imag)
{
x=real;y=imag;
cout&lt;&lt;"\n int to class type:"&lt;<x<<"+j"<<y;
}
complex(double real1,double imag1)
{
a=real1;b=imag1;
cout&lt;&lt;"\n class type to double:"&lt;<a<<"+j"<<b;
}
operator double()
{
cout&lt;&lt;"\n class type to double:"&lt;<a+b;
return 0;
}
};
void main()
{
clrscr();
complex c(3.5);
complex c1(5.5,6.3);
double num =c1;
getch();
}

RESULT:
Thus a c++ program for performing type conversion is wrritten,executed and output verified successfully.

Tuesday, October 5, 2010

PROGRAM USING OPERATOR OVERLOADING

Ex No.2a PROGRAM USING OPERATOR OVERLOADING
7-8-10

AIM:
To write a c++ program to perform arithmetic operations like addition, subraction, multiplication and division of two complex no.s using operator overloading,
ALGORTHIM:
Step 1:Start the program.
Step 2:In order to perform the basic arithmetic operation like addition, subraction, multiplication and division of two complex no.s using operator overloading function.
Step 3:Call the operator overloading function '+','-','*','/' operators to perform addition,subraction,multiplication and division of two complex no.s and display the results respectively.
Step 4:Stop the program.

PROGRAM:
#include<iostream.h>
#include<conio.h>
class complex
{
float x;float y;
public:
complex(){}
complex(float real,float imag)
{x=real;y=imag}
complex operator+(complex c);
complex operator-(complex c);
complex operator*(complex c2);
complex operator/(complex c2);
void display(void);
};
void complex::display(void)
{
cout&lt;<x<<"+j"<<y;
};
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return temp;
}
complex complex::operator-(complex c)
{
complex temp;
temp.x=x-c.x;
temp.y=y-c.y;
return temp;
}
complex complex::operator*(complex c2)
{
complex temp;
temp.x=x*2.x-y*c2.y;
temp.y=x*2.y+y*c2.x;
return temp;
}
complex complex::operator/(complex c2)
{
complex temp;
float d;
d=c2.x*c2.x+c2.y*c2.y;
temp.x=(x*c2.y+y*c2.y)/d;
temp.y=(y*c2.x-x*c2.y)/d;
return temp;
}
int main()
{
complex c1,c2,c3;
c1=complex(3.1,5.1);
c2=complex(6.2,7.1);
clrscr();
cout&lt;&lt;"c1:";c1.display();
cout&lt;&lt;"c2:";c2.display();
c3=c1+c2;cout&lt;&lt;"\n sum:"c3.display();
c3=c1-c2;cout&lt;&lt;"\n difference:";c3.display();
c3=c1*c2;cout&lt;&lt;"\n product:";c3.display();
c3=c1/c2;cout&lt;&lt;"\n division:";c3.display();
getch();
return 0;
}

RESULT:Thus a c++ program for performing arithmetic operation of two complex no. using operator overloading is executed and verified successfully.

PROGRAM USING FRIEND FUNCTION

Ex No.1b PROGRAM USING FRIEND FUNCTION
4-8-10

AIM:To add two complex numbers using c++.

ALGORTHIM:
Step 1: Start the program.
Step 2: The operation of sum is declared as friend function.
Step 3: Call the functions from the main functions.
Step 4: As the function has arguments, the value are given in main function itself.
Step 5: The sum of two complex no.is calculated.
Step 6: End the program.


PROGRAM:
#include<iostream.h>
#include<conio.h>.
class complex
{
float x; float y;
public:
void input(float real,float image)
{
x=read;y=image;
}
friend complex sum(complex,complex);
void show(complex);
};
complex sum(complex c1,complex c2)
{
complex c3;
c3.x=c1.x+c2.x;
c3.y=c1.y+c2.y;
return c3;
}
void complex::show(complex c)
{
cout&lt;<c.x<<"+j"<<c.y;
}
int main()
{
clrscr();
complex A,B,C;
A.input(3.1,5.5);
B.input(2.7,1.2);
C=sum(A,B);
cout&lt;&lt;"\n A=";A.show(A);
cout&lt;&lt;"\n B=";B.show(B);
cout&lt;&lt;"\n C=";C.show(C);
getch();
return 0;
}


RESULT:
Thus the c++ program to find the sum of two complex number using friend function us executed and output is verified successfully.

DISPLAYING OF STUDENT DETAILS USING STATIC FUNCTION

Ex N0.:1c              DISPLAYING OF STUDENT DETAILS USING STATIC FUNCTIONS
4-8-10
AIM:
To display a no.of student details using static functions.
ALGORTHIM:
Step 1: Start the program.
Step 2: Get the no. of students from the user.
Step 3: Get the name and roll no.
Step 4: Enter the no. of subjects required.
Step 5: Get the marks.
Step 6: The total and average are displayed
Step 7: The step 3 to step 6 is repeated for the given no. of students.
Step 8: End the program.
PROGRAM:
#include<iostream.h>
#include<conio.h>
class stud
{
int i,n,roll no.;
char a[20];
int marks[50],total;
float avg;
public:
int k;
int j;
static int count;
void getdetails()
{
cout<<”\nEnter the name and roll no,”;
cin>>a;
cin>>roll no.;
cout<<”\n Enter the number of subjects”;
cin>>n;
total=0;
for(i=0;i<n;i++)
{
cin>>marks[i];
cout<<endl;
total+=marks[i];
}
avg=(total n);
}
void display()
{
cout<<”STUDENT”<<cout<<endl;
cout<<”NAME”<<a<<endl<<”ROLL NO.”<<roll no<<endl<<endl;
for(i=0;i<n;i++)
{
cout<<”MARK”<<i+1<<”:”<<marks[i]<<endl;
}
cout<<”TOTAL”<<total;
cout<<”AVERAGE”<<avg;
}
static void showcount(void)
{
count++;
cout<<endl<<”      STUDENT     “<<count<<end;
}
};
int student::count;
void main()
{
clrscr();
student 5;
cout<<”\nEnter the number of students”;
cin>>s.j;
for(s.k=0;s.k<s.j;s.k++)
{
student::showcount();
s.getdetails();
s.display();
}
getch();
}

RESULT:
Thus a no. of student details are obtained using static members and the output is verified successfully.
Ex No.1                                  PROGRAM USING DEFAULT ARGUMENTS
28-7-10
   

AIM:
To write a program using c++ to find the amount for tax percentage using default arguments.

ALGORTHIM:
Step 1:Start the program.

Step 2:Read the amount to calculate the tax percent.

Step 3:Read the tax percent

Step 4: Calculate tax amount for default tax percent

Step 5:Display the value

Step 6:Calculate tax amount for given tax amount

Step 7:Display the value

Step 8:Stop the program


PROGRAM:
 
#include<iostream.h>
#include<conio.h>
class tax
{
int t;
public:
int cal(int a,int b=2)
{
t=(a*b)/100;
cout<<t<<endl;
return t;
}
};
void main();
{
int  x,y;
clrscr();
tax s;
cout<<”\n Enter the amount to calculate tax amount <<”endl;
cin>>x;
cout<<”\nEnter the percentage of tax for the given amount “<<endl;
cin>>y;
cout<<”\nTax amount for default percent 2”<<s.cal(x)<<endl;
cout<<”\nTax amount for given amount of the given percent”<<s.cal(x,y);
getch();
}



RESULT:
Thus the c++ program to calculate tax amount using default argument has been executed and the output is verified successfully. 

Wednesday, September 29, 2010

(OOPS)Sorting Algorithm Using Templates

EX NO.                               SORTING ALGORITHM USING TEMPLATES

AIM: To create a c++ program to implement sorting algorithm using templates.

ALGORITHM:
Step 1:Start the program.
Step 2: Define the functions for bubble sort,insertion sort,selection sort and merge sort.
Step 3:Call the respective functions to perform the sorting operations.
Step 4:Display the results.
Step 5:Stop the program.

PROGRAM: 


#include<iostream.h>
#include<conio.h>
template<class T>
class sort
{
 public:
 T a[20];
 int n;
 sort()
  {
  }
 void display(T*a,int n)
  {
   for(int i=0;i<n;i++)
   {
    cout<<a[i]<<"\t";
   }
   cout<<endl;
  }
 void bubble(T*a,int n)
  {
   T tmp;
   for(int i=0;i<n-i;i++)
   {
    for(intj=i+1;j<n;j++)
    {
     if(a[i]>a[j])
     {
      tmp=a[i];
      a[i]=a[j];
      a[j]=tmp;
     }
    }
   }
  }
 void insertion(T*a,int n)
  {
   for(int p=1,p<n;p++)
   {
    T tmp=a[p];
    for(int j=p;j>0&&tmp<a[j-1];j--)
    a[j]=a[j-1]
    a[j]=tmp;
   }
  }
 void selection(T*a,int n)
  {
   T tmp,min;
   for(int i=0,i<n-1;i++)
   {
    min=i;
    for(int j=i+1;j<w,j++)
    {
     if(a[min]>a[j])
     min=j;
    }
    tmp=a[min];
    a[min]=a[i];
    a[i]=tmp;
   }
  }
 void merge(T*a,int n)
 {
  T.tmp array[20];
  merge(a,tmparray,0,n-1);
 }
 void merg(T*a,T*tmparray,int left,int right)
 {
  if(left<right)
  {
   int centre=(left+right)/2
   merge(a,tmparray,left,center);
   merge(a,tmparray,centre+1,right);
   {
    merge1(a,tmparray,left,center+1,right);
   }
  }

 void merge1(T*a,T*tmparray,int left pos,int right pos,int right end)
 {
  int left end=right pos-1;
  int tmppos=leftpos;
  int numelement=right end-left pos+1;
  while(leftpos<=leftend&&rightpos<=right end)
  {
   if(a[leftpos]<=a[right pos])
   tmparray[tmppos++]=a[leftpos++];
   else
   tmparray[tmpos++]=a[rightpos++];
  }
  while(leftpos<=leftend)
  tmparray[tmppos++]=a[leftpos++];
  while(rightpos<=rightend)
  tmparray[tmppos++]=a[rightpos++];
  for(int i=0;i<numelement;i++;rightend--)
  a[rightend]=tmparray[rightend];
 }
 };
 void main()
 {
  sort<int>s;
  inth.a[20],choice,b[20],c[10],d[20],e[20],f[20],g[20],dec;
  clrscr();
  cout<<"Enter the no: of elements:"<<endl;
  cin>>n;
  for(int i=0;i<n;i++)
  {
   cin>>a[i];
   b[i]=a[i];
   c[i]=a[i];
   d[i]=a[i];
   e[i]=a[i];
  }
  do
  {
   clrscr();
   cout<<"\t\t\t***MENU***\n";
   cout<<"1.bubble\n2.insertion\n3.selection\n4.merge\n"<<endl;
   cout<<"\t\t\tenter your choice:";
   cin>>choice;
   switch(choice)
   {
    case 1:
       cout<<"\n element before sorting:\n"<<endl;
       s.display(a,n);
       s.bubble(a,n);
       cout<<"\n elements after sorting:\n"<<endl;
       s.display(a,n);
       getch();
       break;
    case 2:
       cout<<"elements before sorting:\n"<<endl;
       s.display(b,n);
       s.insertion(b,n);
       cout<<"\nelement after sorting:\n"<<endl;
       display(b,n);
       getch();
       break;
    case 3:
       cout<<"\n element before sorting:\n"<<endl;
       s.display(c,n);
       s.selection(c,n);
       cout<<"elements after sorting:\n"<<endl;
       s.display(c,n);
       getch();
       break;
    case 4:
       cout<<"elements before sorting:\n"<<endl;
       s.display(d,n);
       s.mergesort(d,n);
       cout<<"\n Element after sorting:\n"<<endl;
       s.displsy(d,n);
       getch();
       break;
   }
  }
 while(choice<4);
 getch();
}

RESULT :
       Thus the c++ program to perform various sorting operations using templates has been executed and the output is verified successfully.