CMSC412 – Homework 6 Solved

$ 24.99
Category:

Description

Write a Java or C/C++ (the choice is yours) program for file/directory processing according to the following rules. The program requested for this homework must have a text menu like this:

0 – Exit
1 – Select directory
2 – List directory content
3 – Display file (hexadecimal view)
4 – Delete file
5 – Mirror reflect file (byte level) Select option:

The menu is displayed and the user must select an option (a number between 0 and 5). The action corresponding to the selection is performed, then the menu is displayed again and the user can choose another option. This cycle is repeated until the user selects 0, which exits the loop and ends the program execution.

The options are:
0 – Exit
This options ends the program execution. This option should always work.

1 – Select directory
The user is prompted for an [absolute] directory name (path). This is the first options that must be selected by the user. All the options below are working on the directory selected here. The directory name (path) must be correctly formatted and the directory must exist (the program must check for this and issue error messages if necessary).
After performing several operations on the selected directory, the user can select another directory and work with it. If a user (by mistake or otherwise) selects any other option from the menu before selecting this one, an error message must be displayed instructing the user to select a directory first.

2 – List directory content
This option displays the content of the directory (previously selected by option 1) on the screen. All the files and sub-directories from the first level ONLY must be displayed (files and directories should be listed separately one item per line, directories first). For each file, its size must also be displayed, in bytes. If no directory was selected an error message must be displayed.

3 – Display file (hexadecimal view)
This option prompts the user for a filename (from the directory selected by option 1) and displays the content of that file on the screen, in hexadecimal view. If no directory was selected an error message must be displayed. If the directory does not contain the file specified by the user, another error message must be displayed. The filename does not include any path, it’s just the name of the file.

Note: The hexadecimal view displays each byte of the file in hexadecimal, 16 bytes per line, separated by one white space; each byte must occupy two characters on the screen. It should look something like this (please note that the letters A to F must be in upper case !!!):

52 61 72 21 1A 07 01 00 96 45 15 22 0C 01 05 08
00 07 01 01 D3 94 89 80 00 CA 47 9D 13 4A 02 03
0B F3 93 09 04 95 A1 09 20 F7 2B 31 75 80 0B 00
2C 57 68 61 74 73 41 70 70 20 49 6D 61 67 65 20
32 30 32 32 2D 30 35 2D 31 31 20 61 74 20 37 2E
33 34 2E 31 34 20 50 4D 2E 6A 70 65 67 0A 03 02
F4 FF 17 13 CB 65 D8 01 8E 87 16 45 67 06 55 53
22 65 66 70 37 76 D4 D1 22 42 00 90 8C 20 D0 51
01 22 C0 EA 28 D0 34 02 03 01 04 08 28 49 10 58
29 4A 28 8D 02 88 88 95 AC 04 12 95 29 60 0A 55
01 12 85 7A 08 0D 42 89 4A 28 A5 30 10 51 51 51
51 29 45 45 20 22 08 BD 71 BD F5 BF 31 1D F7 DF
9C 79 DE FB E3 EF F5 F7 D1 B2 13 53 3A CD 5C F3
AC E7 38 CE 28 87 A6 71 F8 27 CC 63 39 E3 34 73
8F 4A FF 5E 6F EB D8 21 13 5B 16 CD 88 83 06 08 20 7F 25 E9 FD 5E 09 12 26 69 2F A4 D0 F6 3C 7A
69 04 FF F3 4A 59 B5 05 0C DA 91 42 2A 7F E0 A2
DA A6 79 53 FF 94 B6 B0 B8 B0 AC 97

4 – Delete file
This option prompts the user for a filename and deletes that file from the selected directory. If no directory was selected an error message must be displayed. If the directory does not contain the file specified by the user, another error message must be displayed. The filename does not include any path, it’s just the name of the file.

5 – Mirror reflect file (byte level)
This option prompts the user for a filename (from the selected directory) and performs an operation we will call ”mirror reflection” for every byte of that file. If no directory was selected an error message must be displayed. If the directory does not contain the file specified by the user, another error message must be displayed. The filename does not include any path, it’s just the name of the file.

Note: Mirror reflection for a certain byte (which, as we know, is a string of 8 bits) changes the order of its bits just like a real world mirror does for any image: what was on the left side will appear on the right side and vice versa.
More concretely, let’s denote the bits of a byte as b1b2b3b4b5b6b7b8. After the mirror reflection operation, they will be rearranged as b8b7b6b5b4b3b2b1.

Hints: The required actions are: read the whole file into a memory buffer (we assume the file is small enough), then perform the mirror reflection for every byte of the memory buffer, then we write back the buffer into the file (we overwrite the file) resulting a file with the same size in bytes.
No additional file must or should be used, as the initial file must be overwritten.
Clearly if we apply this operation twice, we must obtain again the initial file content.

Testing procedure:
0. Option 0 requires just one screenshot, for successful exit.
1. Option 1 requires one screenshot for a correct directory name (path) and one screenshot for an incorrect directory name (path).
2. Option 2 requires one screenshot showing the error (no directory was selected yet) and another one showing the content of the selected directory; make sure the directory you use contains at least three files and three subdirectories.
3. Option 3 requires screenshots showing the errors (no directory was selected yet, file does not exist) and another one showing the content of the selected file; make sure the display follows the required formatting.
4. Option 4 requires screenshots showing the errors (no directory was selected yet, file does not exist) and another one/two showing the content of the selected directory before and after deleting the file.
5. Option 5 requires screenshots showing the errors (no directory was selected yet, file does not exist) and others showing the hex view of the file before and after mirroring (also, make sure the file size remains the same).

Deliverables:
1. Source code (zipped)
2. A Test Report showing the program performing each of the menu actions correctly (use the testing procedure described above, include all the required screenshots). Use this file (Homework 6.pdf) as the input file for options 3 and 5.

Reviews

There are no reviews yet.

Be the first to review “CMSC412 – Homework 6 Solved”

Your email address will not be published. Required fields are marked *