Question: Lab 9 - Looping ( Exercise 1 6 on p . 2 5 6 ) Create, compile, and run a class that keeps track of
Lab Looping Exercise on p
Create, compile, and run a class that keeps track of compressed files.
Imagine a program that compresses files by percent and stores them on storage media. Before the compressed file is stored, it must be divided into blocks of bytes each. Develop an algorithm for this program that first reads the number of blocks available on the storage media. Then, in a loop, read the uncompressed size of a file and determine whether the compressed file will fit in the space left on the storage media. If so the program should "compress" and "save" the file. It continues until it encounters a file that will exceed the available space on the media.
For example, suppose the media can hold blocks. A file of size bytes will compress to size and require blocks. The available space is now blocks. A file of size bytes will compress to size and require blocks. The available space is now
Sample dialog:
How many byte blocks are available on the storage device?
How big is the file in bytes?
The file will be compressed to bytes. That will take blocks. You have blocks available.
How big is the file in bytes?
The file will be compressed to bytes. That will take blocks. You have blocks available.
How big is the file in bytes?
The file will be compressed to bytes. That will take blocks. You have blocks available.
How big is the file in bytes?
The file will be compressed to bytes. That will take blocks. You have only blocks. The file cannot be compressed and stored.
The program stops here.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
