42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <iomanip>
|
|
#include <fstream>
|
|
#include <math.h>
|
|
|
|
using namespace std;
|
|
|
|
void calculations(float alphaVal, string outputFileName);
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
// calculate part a
|
|
calculations(0.5, "P4A.txt");
|
|
calculations(0.8, "P4B.txt");
|
|
calculations(0.9, "P4C.txt");
|
|
|
|
}
|
|
|
|
void calculations(float alphaVal, string outputFileName)
|
|
{
|
|
ofstream outputFile;
|
|
outputFile.open(outputFileName.c_str());
|
|
float alpha = alphaVal;
|
|
outputFile << fixed << setprecision(4);
|
|
float estimatedRTT = 1.50, sampleRTT = 0.0;
|
|
float timeOut = 0.0;
|
|
outputFile << "Iteration #\t\tSampleRTT\t\tEstimatedRTT\t\tTimeOut\n";
|
|
for (int i = 1; i < 31; i++)
|
|
{
|
|
if((i % 6)==0)
|
|
{
|
|
sampleRTT = 5.0;
|
|
}
|
|
else sampleRTT = 1.0;
|
|
estimatedRTT = alpha * estimatedRTT + (1 - alpha) * sampleRTT;
|
|
timeOut = 2 * estimatedRTT;
|
|
outputFile << i << "\t\t\t\t" << setw(5) << setfill(' ') << sampleRTT << setw(10) << setfill(' ')
|
|
<< "\t\t" << estimatedRTT << setw(16) << setfill(' ') << timeOut << endl;
|
|
}
|
|
|
|
outputFile.close();
|
|
} |