Thursday 24 April 2014

WAP to show Leaky bucket problem

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
int main()
{
    int i,packets[10],content=0,newcontent,time,clk,bucketsize,operate;
    for(i=0;i<5;i++)
    {
                    packets[i]=rand()%10;
                    if(packets[i]==0)
                    --i;
    }
                    printf("\n enter the output rate of the bucket:\n");
                    scanf("%d",&operate);
                    printf("\n enter the bucket size\n");
                    scanf("%d",& bucketsize);
                    for(i=0;i<5;i++)
                    {
                                     if((packets[i]+content)>bucketsize)
                                     {
                                     if(packets[i]>bucketsize)
                                     printf("\n incoming packetsize %d greater than the size of the bucket\n",packets[i]);
                                     else
                                     printf("\n bucket size exceded\n");
                                     }
                                     else
                                     {
                                         newcontent=packets[i];
                                         content+=newcontent;
                                         printf("\n incoming packets:%d\n",newcontent);
                                         printf("\n transmission left:%d\n",content);
                                         time=rand()%10;
                                         printf("\n next packets will come out %d\n",time);
                                         for(clk=0;clk<time && content>0;++clk)
                                         {
                                                                             printf("\n left time%d",(time-clk));
                                                                             if(content)
                                                                             {
                                                                                        printf("\n transmitted\n");
                                                                                        if(content<operate)
                                                                                        content=0;
                                                                                        else
                                                                                        content=content-operate;
                                                                                        printf("\n bytes remaining:%d\n",content);
                                                                             }
                                                                                        else
                                                                                        printf("\n no packets to send\n");
                                        }
                                   }
                   }
   getch();

 }


No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2022