THINK FIRST·CODE LATER

← All labs

How many programs keep the CPU busy? (multiprogramming model)

Problem

Use the multiprogramming model utilization = 1 − pⁿ to size an EdgeCampus server.

Input: lines p target maxN until the end of input, where p is the I/O-wait fraction (0 ≤ p < 1), target is the desired utilization in percent, and maxN the largest number of processes to consider.

For each line print a table of n = 1…maxN, then the answer:

p=0.80 target=90.0%
n=1 util=20.00%
n=2 util=36.00%
...
Minimum n: 11

(Print p with two decimals and target with one decimal; utilization with two decimals.) The minimum n is the smallest n with utilization ≥ target; if none of 1…maxN reaches it, print Minimum n: not reached within maxN. Print an empty line between two inputs.

Input:

0.5 90 5

Output:

p=0.50 target=90.0%
n=1 util=50.00%
n=2 util=75.00%
n=3 util=87.50%
n=4 util=93.75%
n=5 util=96.88%
Minimum n: 4

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os1-1-data-1.txt

0.5 90 5
What your program must print for os1-1-data-1.txt
p=0.50 target=90.0%
n=1 util=50.00%
n=2 util=75.00%
n=3 util=87.50%
n=4 util=93.75%
n=5 util=96.88%
Minimum n: 4

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os1-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content os1-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.