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.