Assume the following: a. Disk spooling is NOT being used. b. The printer does NO
ID: 651336 • Letter: A
Question
Assume the following: a. Disk spooling is NOT being used. b. The printer does NOT have a hardware buffer to hold the output while the printer is printing (The theme music from Mission Impossible is playing faintly in the background). SIMULATE the following scenario A hypothetical program computes for three seconds then outputs a variable length record to be printed. The printer takes from 0.75 to 4.75 seconds (average time is 2.75 seconds) to print each output record. (Use a random number generator) The hypothetical program loops 500 times for each case of software buffers (0, 1, 2, 3, 4, 5, 10, 25, and 100 software output buffers). Calculate the AVERAGE time for the program to
Explanation / Answer
// PrinterBuffer.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
#include "cmath"
#include "time.h"
#include "conio.h"
using namespace std;
void main()
{
int buffer=0;
float min = 0.75;
float max=4.75;
float diff = 4.75-0.75;
float printtime;
float tottime=0;
srand(time(NULL));
while(buffer<=100)
{
for(int i=0;i<500;i++)
{
printtime = (((float) rand()/RAND_MAX) * diff) + 0.75 + 3;
tottime = tottime + printtime;
}
cout << "Average time to compute and print for buffer " << buffer << " : " << tottime/500 << " " ;
tottime=0;
buffer++;
if (buffer==26) buffer=100;
if (buffer==11) buffer=25;
if (buffer==6) buffer=10;
}
_getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.