Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Homework 6 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...

1 answer below »
Homework 6
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 – Mi
or 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
co
esponding 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 co
ectly formatted and the directory must exist (the program must check for this
and issue e
or 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 e
or 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
ytes. If no directory was selected an e
or 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 e
or message
must be displayed. If the directory does not contain the file specified by the user, another e
or 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
y 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 !!!):

XXXXXXXXXX1A XXXXXXXXXX22 0C XXXXXXXXXX
XXXXXXXXXXD XXXXXXXXXXCA 47 9D 13 4A 02 03
0B F XXXXXXXXXXA XXXXXXXXXXF7 2B XXXXXXXXXX0B 00
2C XXXXXXXXXX XXXXXXXXXX6D XXXXXXXXXX
XXXXXXXXXX2D 30 35 2D XXXXXXXXXX37 2E
33 34 2E XXXXXXXXXX4D 2E 6A XXXXXXXXXX0A 03 02
F4 FF 17 13 CB 65 D8 01 8E XXXXXXXXXX53
XXXXXXXXXXD4 D XXXXXXXXXX8C 20 D0 51
01 22 C0 EA 28 D XXXXXXXXXX XXXXXXXXXX
29 4A 28 8D XXXXXXXXXXAC XXXXXXXXXX0A 55
XXXXXXXXXX7A 08 0D 42 89 4A 28 A XXXXXXXXXX
XXXXXXXXXX BD 71 BD F5 BF 31 1D F7 DF
9C 79 DE FB E3 EF F5 F7 D1 B XXXXXXXXXX3A 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 D XXXXXXXXXX5B 16 CD XXXXXXXXXX
20 7F 25 E9 FD 5E XXXXXXXXXX2F A4 D0 F6 3C 7A
69 04 FF F3 4A 59 B5 05 0C DA 91 42 2A 7F E0 A2
DA A XXXXXXXXXXFF 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 e
or message must be displayed. If the directory does not contain the file
specified by the user, another e
or message must be displayed. The filename does not include any path,
it’s just the name of the file.

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

Note: Mi
or 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 mi
or 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 mi
or reflection
operation, they will be rea
anged 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 mi
or 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 co
ect directory name (path) and one screenshot for an
inco
ect directory name (path).
2. Option 2 requires one screenshot showing the e
or (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 e
ors (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 e
ors (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 e
ors (no directory was selected yet, file does not exist)
and others showing the hex view of the file before and after mi
oring (also, make sure the file size
emains the same).

Deliverables:
1. Source code (zipped)
2. A Test Report showing the program performing each of the menu actions co
ectly (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.
Answered 2 days After Feb 25, 2023

Solution

Baljit answered on Feb 25 2023
33 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here