Question
OBJECTIVE: We need practice in using loops, using sentinels in processing input, comparing data, summing data, using counters, and documenting a program using comments and
OBJECTIVE: We need practice in using loops, using sentinels in processing input, comparing data, summing data, using counters, and documenting a program using comments and we don't have much time. Thus this is a short assignment.
PROBLEM BACKGROUND: Write a program that reads and processes sets of data, from standard input (stdin), until a sentinel value of a negative number. A set is three numbers (a triplet) where: the first number in a set is a room number, the second is the room's capacity, and the third is the size of the class scheduled to meet in that room. For each triplet set, print an output line showing the classroom number, capacity, number of seats filled, number of seats available, and a message ("FULL" or "OPEN") indicating whether the classroom is filled or not. These must be printed in columns formatted exactly as shown in the sample output below. (You must also print a heading over the columns; again, refer to the sample output for the precise format.) After all classrooms have been processed, a summary is to be printed. The form and content of the summary are explained in the sample output section.
SAMPLE OUTPUT: If your input file contained the following data (just the numbers):
Room | Capacity | Class Size |
426 | 25 | 25 |
327 | 18 | 14 |
420 | 20 | 15 |
317 | 100 | 90 |
-1 | -1 | -1 |
your program must produce the following output (spaced, labeled, punctuated, and formatted exactly as shown):
Room Capacity Size Empty Seats Status 426 25 25 0 FULL 327 18 14 4 OPEN 420 20 15 5 OPEN 317 100 90 10 OPEN ***************************************** Rooms: 4 Overall Capacity: 163 Total Enrollment: 144 Number of Open Rooms Remaining: 3 *****************************************
where the number for Rooms is simply how many rooms where processed (i.e., how many triplets); where Overall Capacity is just the total of the capacities; where Total Enrollment is the sum of the class sizes; and where Number of Open Rooms Remaining is a count of how many rooms were not filled. (Be sure to print the two 41-asterisks-long separator lines.) As is standard for numbers, the first four columns are right-justified. The Formatting Numbers and Strings handout is a useful reference in getting the spacing and formatting correct.
TEST DATA: There are three sample data files you should use in testing your program,semester1.dat, semester2.dat. and semester3.dat. These can be copied from $PUB. Note: semester3.dat is an "empty" file in that it contains just a sentinel value (of three negative integers) and is designed to test what happens when your program encounters such a file. This program does not use file objects, rather a data file is read from standard input via UNIX input file redirection (<). See examples of how this is done in the "REQUIRED" section below. Although you will edit your source code using IDLE, you will need to execute your program in a terminal window from the command-line using the python3 command.
IMPLEMENTATION NOTES: Use as your source file name "classrooms.py"; a starter file is available at $PUB/classrooms.py.
REQUIRED: You are to electronically submit the source program, a source program listing, and the execution results obtained from running your program against all three sample inputs (see above). Once you have a working program, the following UNIX commands will do what is required:
$ script ola107.log $ cat -n classrooms.py $ python3 classrooms.py < semester1.dat $ python3 classrooms.py < semester2.dat $ python3 classrooms.py < semester3.dat $ exit $ handin "ola107" classrooms.py ola107.log
(Be sure to exit the script session before trying to handin the log!)
GRADING: As always, the grader may ask you to run your program against some additional (and unknown to you) data. Your program must work properly for any valid input to be considered correct.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started