Fall 2002 CSCI 333 Quiz 5 Solution

Problem 1

Consider an old-fashioned unzoned disk drive with the following characteristics.

The questions

Answer the following questions regarding the disk drive described above.

  1. How many 512 byte sectors are on this disk drive?

    20GB / 512B or 40M

  2. How many total tracks (on all cylinders) are on this disk drive?

    2048 * 10 or 20480

  3. How many sectors are stored on each single track?

    40M / 20k or 2k

  4. How long, in msec, does it take this disk to rotate?

    1 min / 10,000 or 60,000 msec / 10,000 or 6 msec

  5. What is the average time, in msec, required to read a random sector of data from the disk?

    10 msec + (6 msec/2) or 13 msec

Problem 2

Write a C++ subroutine which is passed an istream that has been opened to this file. This routine should attempt to read an integer from the file. It should return -1, if the read request fails or reads a negative number. Otherwise, it should return the number it reads.

Here is a header for your function:

int ReadOne(istream NumS)
int ReadOne(istream NumS)
{
  int retMe = -1 ;
  NumS >> retMe ;
  if (NumS.fail() || retMe < 0)
    return -1 ;
  else
    return retMe ;
}