The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Q3
By Guest on 23rd November 2022 07:31:05 PM | Syntax: TEXT | Views: 3



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #include<time.h>
  5. using namespace std;
  6. class Window
  7. {
  8.     public:
  9.     int f,w;
  10.     Window();
  11.     void correct(int);
  12.     void framelost(int);
  13.     void acklost(int);
  14.     void delay(int);
  15.     void resend(int);
  16.     void win(int);
  17.     int arr[50];
  18.     int s;
  19. };
  20. Window::Window()
  21. {
  22.     cout<<"Enter the number of frames: ";
  23.     cin>>f;
  24.     cout<<"Enter the size of windows: ";
  25.     cin>>w;
  26.     s=pow(2,w)-1;
  27.     arr[s];
  28.     cout<<"SENDER\t\t\t\t\t\t\tRECIEVER\n";
  29. }
  30. void Window::correct(int i)
  31. {
  32.     cout<<"\n\t\t\t\t\t\tRecieved frame f"<<i<<" successfully!\n";
  33.     cout<<"\t\t\t\t\t\tSending acknowledgement to sender!\n";
  34.     cout<<"\nRecieved acknowledgement from reciever!";
  35. }
  36. void Window::framelost(int i)
  37. {
  38.     cout<<"\n\t\t\tFrame lost!\n"<<"\t\t\tResend the frame!\n";
  39.     resend(i);
  40.     cout<<"\n\t\t\t\t\t\tRecieved frame f"<<i<<" successfully!\n";
  41.     cout<<"\t\t\t\t\t\tSending acknowledgement to sender!\n";
  42.     cout<<"\nRecieved acknowledgement from reciever!";
  43. }
  44. void Window::acklost(int i)
  45. {
  46.     cout<<"\n\t\t\t\t\t\tRecieved frame f"<<i<<" successfully!\n";
  47.     cout<<"\t\t\t\t\t\tSending acknowledgement to sender!\n";
  48.     cout<<"\t\t\tAcknowledgement lost!\n\t\t\tResend Frame!\n";
  49.     resend(i);
  50.     cout<<"\n\t\t\t\t\t\tRecieved frame f"<<i<<" successfully!\n";
  51.     cout<<"\t\t\t\t\t\tSending acknowledgement to sender!\n";
  52.     cout<<"\nRecieved acknowledgement from reciever!";
  53. }
  54. void Window::delay(int i)
  55. {
  56.     cout<<"\n\t\t\t\t\t\tRecieved frame f"<<i<<" successfully!\n";
  57.     cout<<"\t\t\t\t\t\tSending acknowledgement to sender!\n";
  58.     cout<<"\t\t\tDelay in acknowledgement of reciever!\n\t\t\tResend Frame!\n";
  59.     resend(i);
  60.     cout<<"\n\t\t\t\t\t\tRecieved frame f"<<i<<" successfully!\n";
  61.     cout<<"\t\t\t\t\t\tSending acknowledgement to sender!\n";
  62.     cout<<"\nRecieved acknowledgement from reciever!";
  63. }
  64. void Window::resend(int i)
  65. {
  66.     cout<<"\t\t\tResending the whole window again!\n";
  67.     cout<<"\t\t\tThe sequencing number is: ";
  68.     for(int j=0;j<s;j++)
  69.     {
  70.         if(i+j<=f)
  71.         {
  72.             arr[j]=i+j;
  73.             cout<<(arr[j]-1)%(s+1)<<" ";
  74.         }  
  75.     }
  76.     cout<<endl;
  77. }
  78. void Window::win(int i)
  79. {
  80.     for(int j=0;j<s;j++)
  81.     {
  82.         if(i+j<=f)
  83.         {
  84.             arr[j]=i+j;
  85.              if(i==1)
  86.             {
  87.                 cout<<"\nSending frame f"<<arr[j]<<endl;
  88.             }
  89.         }
  90.     }
  91.     if(i!=1&&i<=f-s+1)
  92.     {
  93.     cout<<"\nSending frame f"<<arr[s-1]<<endl;
  94.     }
  95.     cout<<"\t\t\tThe sequencing number is: ";
  96.     for(int j=0;j<s;j++)
  97.     {
  98.         if(i+j<=f)
  99.         {
  100.             arr[j]=i+j;
  101.             cout<<(arr[j]-1)%(s+1)<<" ";
  102.         }  
  103.     }
  104.     cout<<endl;
  105. }
  106. int main()
  107. {
  108.     Window obj;
  109.     srand(time(0));
  110.     for(int i=1;i<obj.f;i++)
  111.     {
  112.         int c=rand()%4;
  113.         obj.win(i);
  114.         switch(c)
  115.         {
  116.             case 1:
  117.             {
  118.                 obj.correct(i);
  119.                 break;
  120.             }
  121.             case 2:
  122.             {
  123.                 obj.acklost(i);
  124.                 break;
  125.             }
  126.             case 3:
  127.             {
  128.                 obj.delay(i);
  129.                 break;
  130.             }
  131.             default:
  132.             {
  133.                 obj.framelost(i);
  134.                 break;
  135.             }
  136.         }
  137.     }
  138.     cout<<"\nAll frames recieved successfully!";
  139.     return 0;
  140. }



  • Recent Pastes