#include<iostream>
//#include<dos>
#include<stdlib.h>
#define bucketSize 512
using namespace std;
void bktInput(int psize,int r) {
if(psize>bucketSize)
cout<<"\nBucket overflow"<<endl;
else {
sleep(5);
while(psize>r)
{
cout<<"\n"<<r <<"bytes sent.";
psize-=r;
sleep(5);
}
if(psize>0)
cout<<"\nRemaining "<<psize<<" bytes sent";
cout<<"\nBucket output successful"<<endl;
}
}
int main() {
int rate, pktSize;
cout<<"\t\tBUCKET SIZE = 512 bytes"<<endl;
cout<<"Enter output rate: ";
cin>>rate;
for(int i=1;i<=5;i++)
{
sleep(5);
pktSize=rand() % 600+1;
cout<<"\nPacket no "<<i<<"\tPacket size "<<pktSize;
bktInput(pktSize,rate);
}
return 0;
}
Credits : Saurabh Pakhare
//#include<dos>
#include<stdlib.h>
#define bucketSize 512
using namespace std;
void bktInput(int psize,int r) {
if(psize>bucketSize)
cout<<"\nBucket overflow"<<endl;
else {
sleep(5);
while(psize>r)
{
cout<<"\n"<<r <<"bytes sent.";
psize-=r;
sleep(5);
}
if(psize>0)
cout<<"\nRemaining "<<psize<<" bytes sent";
cout<<"\nBucket output successful"<<endl;
}
}
int main() {
int rate, pktSize;
cout<<"\t\tBUCKET SIZE = 512 bytes"<<endl;
cout<<"Enter output rate: ";
cin>>rate;
for(int i=1;i<=5;i++)
{
sleep(5);
pktSize=rand() % 600+1;
cout<<"\nPacket no "<<i<<"\tPacket size "<<pktSize;
bktInput(pktSize,rate);
}
return 0;
}
Credits : Saurabh Pakhare
Its Python Version
ReplyDeleteimport time
import random
bucketSize=512
def bktInput(psize,r):
if psize>bucketSize:
print '\nBucket Overflow'
return
else:
time.sleep(2)
while psize>r:
print '\n',r, ' bytes sent.'
psize-=r
time.sleep(2)
if psize>0:
print '\nRemaining ',psize,' bytes sent'
print '\nBucket output successful'
print '\tBUCKET CAPACITY = 512 bytes'
rate=input('Enter the rate: ')
for i in range(1,6):
time.sleep(2)
pktSize=random.randint(1,600)
print '\nPacket no: ',i,'\tPacket size: ',pktSize
bktInput(pktSize,rate)