Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CIS 361 Quiz 2: Randomly Selecting a Line from a File and Decoding an Unsigned Int, Quizzes of Computer Science

Instructions for quiz #2 in cis 361, which includes writing a c program to randomly select a line from a file and output the second field, as well as decoding an unsigned int using a specific bit scheme. The document also includes an example of encoding and decoding characters using this bit scheme.

Typology: Quizzes

2009/2010

Uploaded on 02/24/2010

koofers-user-fet
koofers-user-fet 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CIS 361
Name: Last, First March:30
Quiz #2
This classroom has enough seats for you to sit with no one laterally adjacent to you; please
do so.
During this test, you should not use any auxiliary materials or computational devices;
i.e. this test is ‘closed-book’ (and ‘closed-notes’ etc.). But if you can’t remember some little
detail, ask the instructor.
If your handwriting really is poorly legible, up to one point may be subtracted from your
score.
A. [128 points] Write a complete C program like what I’ve been using in lectures to
randomly choose people to call on. (Your program here does not need to do everything
like mine; in particular, your program does not need to modify any ‘count’ values in the
data file.) A data file for your program here would appear like the following:
count name
===== ====
13 BROWN,TERRY
14 JONES,SAM
12 LEE,CHRIS
13 SMITH,PAT
. .
. .
. .
Your program needs to skip over the header-material at the beginning of the file (through
the line beginning with =, which you explicitly need to check for because the number of
header lines can vary, not being just 2), randomly and fairly select one of the remaining
lines, and output the second field of the selected line LEE,CHRIS or BROWN,TERRY
or . . . (Don’t worry about finding a line containing a low value.) The number of lines in
the file needs to be determined by reading the file; it cannot be determined any other way.
And then after that, without opening the file again, you’ll need to return to the beginning
of it to re-find a selected line.(Do not try to store the entire contents of a file in memory.)
Error-check program-arguments and file-access as usual, using standard error output and
setting the exit-status value as appropriate. Also, use fgets() for reading, and use a
named constant for the size of your line-buffers.
Actually, as my program does, even without reopening the file, you can do the random, fair selection
without needing to return to the beginning of the file. If you figure out how to do this, fine; but otherwise,
you need to return to the beginning of the file.
page 1 of 4
pf3
pf4

Partial preview of the text

Download CIS 361 Quiz 2: Randomly Selecting a Line from a File and Decoding an Unsigned Int and more Quizzes Computer Science in PDF only on Docsity!

CIS 361

Name: Last, First March:

Quiz

  • This classroom has enough seats for you to sit with no one laterally adjacent to you; please do so.
  • During this test, you should not use any auxiliary materials or computational devices; i.e. this test is ‘closed-book’ (and ‘closed-notes’ etc.). But if you can’t remember some little detail, ask the instructor.
  • If your handwriting really is poorly legible, up to one point may be subtracted from your score.

A. [128 points] Write a complete C program like what I’ve been using in lectures to randomly choose people to call on. (Your program here does not need to do everything like mine; in particular, your program does not need to modify any ‘count’ values in the data file.) A data file for your program here would appear like the following:

count name ===== ==== 13 BROWN,TERRY 14 JONES,SAM 12 LEE,CHRIS 13 SMITH,PAT

.. .. ..

Your program needs to skip over the header-material at the beginning of the file (through the line beginning with “=”, which you explicitly need to check for because the number of header lines can vary, not being just 2), randomly and fairly select one of the remaining lines, and output the second field of the selected line — “LEE,CHRIS” or “BROWN,TERRY” or... (Don’t worry about finding a line containing a low value.) The number of lines in the file needs to be determined by reading the file; it cannot be determined any other way. And then after that, without opening the file again, you’ll need to return to the beginning of it to re-find a selected line.∗^ (Do not try to store the entire contents of a file in memory.) Error-check program-arguments and file-access as usual, using standard error output and setting the exit-status value as appropriate. Also, use fgets() for reading, and use a named constant for the size of your line-buffers.

∗Actually, as my program does, even without reopening the file, you can do the random, fair selection without needing to return to the beginning of the file. If you figure out how to do this, fine; but otherwise, you need to return to the beginning of the file.

  • Total Score: /