Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the first is the main question the rest are how to implement the code question requirements test cases You are required to create a small

image text in transcribed

the first is the main question the rest are how to implement the code

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

question requirements

image text in transcribed

image text in transcribed

image text in transcribed

test cases

You are required to create a small C++ application that will mimic a computer file system, which can be accessed through a simulation of the command prompt. . The problem description can be found here . You are also provided with ample information about the test cases. Find the test case details here Here is a video that might help you understand better what is required. Starter code Copy these three files and follow then write your code in file SystemSim.cpp. The other two files NEED NOT BE MODIFIED AT ALL! when testing, put the three files in the same folder. tester.cpp // DO NOT MODIFY THIS FILE (tester.cpp) AT ALL SINCE THE MAIN FUNCTION USED TO TEST YOUR 77 CODE IS SIMILAR TO THIS ONE. IF YOU MODIFY THIS ONE YOU ARE ESSENTIALLY // DEVIATING FROM THE SPECIFICATION AND ARE BOUND TO BE WRONG // IN OTHER WORDS, ALL YOUR CODE SHOULD GO INTO fileSystemSim.cpp // User-defined files #include "utilities.cpp" #include "fileSystemSim.cpp" #include #include #include using namespace std; int main() { printWelcomeDisplay(); W/ Create the root. Directory * pwd = new Directory(); // pwd stands for present working directory 7 At the beginning the pwd is the root. It is the only directory created, so far. // Initialize some variables string input; vector args; Starter code Copy these three files and follow then write your code in fileSystemSim.cpp. The other two files NEED NOT BE MODIFIED AT ALLI when testing, put the three files in the same folder tester.cpp #include #include #include using namespace std; int main(){ printWelcomeDisplay(); // Create the root. Directory * pwd new Directory(); // pwd stands for present working directory 71 At the beginning the pwd is the root. It is the only directory created, so far. // Initialize some variables string input; vector args; // A loop that will run until 'exit' is typed while(true) { // Get a command from the user cout getPath() #include using namespace std; // DO NOT MODIFY THIS FILE // Utility function to split a string vector splitString(string input){ stringstream ss(input); //convert input into string stream vector args; string temp_str; ')){ //use space as delim for cutting string while(getline(ss, temp_str, args.push_back(temp_str); } return args; } // Print welcoming display void printWelcomeDisplay(){ cout // ADD ANY OTHER INCLUDES YOU DEEM NECESSARY using namespace std; // THE SKELETON BELOW HAS BEEN PROVIDED TO GIVE YOU IDEAS // YOU CAN ADD ANY OTHER COMPONENT YOU WISH TO ADD class File{ //YOUR CODE GOES HERE }; class Directory{ // YOUR CODE GOES HERE }; Directory * runCommand (Directory * pwd, vector args) { // YOUR CODE GOES HERE } Submission Instructions All your code should go into fileSystemSim.cpp. ONLY SUBMIT fileSystemSim.cpp. The other files are given to you just to help you test your code on your computer. Since the base code is not being submitted, the similarity between submissions should not exceed 50%. If you do your own work this will easily be the case. REQUIREMENT EXPLANATION You are required to create a small C++ application that will mimic a computer file system, which can be accessed through a simulation of the command prompt. Remember that in the command prompt (Terminal in Ubuntu or MS-DOS prompt in Windows), one can issue various commands and thus manipulate the directories (aka folders) and files therein. We will mimic the Ubuntu Terminal (NB: you can still build this small application even if you are using windows)." The structure of most file systems usually has a top level directory called the root and then there can be subdirectories upto many levels deep. Each directory can have other directories and/or files within it. Using the Terminal commands, one can navigate the file structure and modify it (add/delete file and directories, etc). In Ubuntu, the Terminal usually presents with a prompt that is as follows: fee231@EIE:/ $ fee231 represents the user, ElE represents the computer name. The $ sign marks the prompt where commands are to be entered. What appears between the colon and the $ represents the path to the present working directory. The first forward slash after the colon represents the root directory (the top level directory). So if one has change directory to a subdirectory called dir_b, which is within a directory called dir_a, which is under the root, the prompt will look as follows: fee231 @EIE: /dir_a/dir_b3 Commands to be simulated The small file system simulation you are to complete is limited to the following commands: 1 of 3 eX7jd9zemlZ2c3yX9vPiutaQlYhwPlh_R3Ecs/edit TY of NAI... Request edit access 1. ls: List the contents of a directory. No operands required First list the directories and then the files, ALL ON ONE LINE. Directories should be printed with "(d)" immediately after the name (without a space). E.g. if the root directory has two subdirectories called dir1 and dir2 as well as two files file 1 and file2, then the command and output would be as follows: fee 231 @EIE:) $ ls dirl(d) dir2 (d) filel file2 2. touch: Create an empty file in the present working directory (pwd). Let us assume that file names do not have spaces. Requires one or more operands separated by single spaces. The operands are the files to be created. 3. nano: Create a file with contents in the pwd. Names have no spaces. Requires 2 operands. The first operand is the file to be created, the second operand is the one-word content of the file. Our files can only contain one work as their content. 4. display Print out the contents of a file on the screen. Requires one operand (the filename) 5. mkdir Creates a subdirectory in the pwd. It requires one or more operands separated by single spaces. 6. cd Change from the present working directory to the directory specified. It requires one operand. The options should be: the one-word content of the file. Our files can only contain one work as their content. 4. display Print out the contents of a file on the screen. Requires one operand (the filename) 5. mkdir Creates a subdirectory in the pwd. It requires one or more operands separated by single spaces. 6. cd Change from the present working directory to the directory specified. It requires one operand. The options should be: a. cd dirname: change to the directory specified by dirname b. cd .. change to the parent directory of the present working directory c. cd / change the present working directory to be the root directory 7. sort Sort the contents of the present working directory It does not take any operands 8. delete Deletes the contents of a directory. It takes one operand, which is the file or directory to be deleted. If the wildcard * is given as the operand, all the contents of the directory are deleted. If an operand representing a file or directory that does not exist is given, an error is printed. Files provided You are provided with 3 files: tester.cpp file System Sim.cpp 2 of 3 est edit access Utilities.cpp tester.cpp is solely for testing your code, which SHOULD ALL GO INTO fileSystemSim.cpp. DO NOT modify tester.cpp NOR utilities.cpp. Put the three files in one folder and then write your code in file System Sim.cpp. When testing on your computer, compile and run tester.cpp, which will include your code through the appropriate #include statement. When submitting, ONLY submit fileSystem Sim.cpp. Study keenly the few functions being invoked in tester.cpp i.e their expected inputs and outputs because this will give you a clue of how to start on your own code in file System Sim.cpp. To test your code, there are a number of test cases that are being used. These can guide you as to how your own code should behave. You can find details of the test cases here. In the test cases, the verification method gives you an idea of how that functionality is being tested. NB: your code should not have cout statements except where you are required to print something; you can again tell this from the test cases, which are provided. See the column labeled "Print output". When you print you should be exact as per the test case specification since the marking script will strictly follow that. Also notice that some commands have print output (i.e. they involve cout) whereas others do not. Your print output should not have the quotes indicated in the print output column of the test cases. Other ideas and suggestions Think of appropriate data structures you can use to create the file system. You definitely should be able to represent directories and files and the fact that a directory can have zero or more subdirectories and zero or more files. You may want to think of using classes to define the Directories and Files. If you use a class, ask yourself what each Directory or File should have (i.e. what data members and what methods) and incorporate them into the class. A Directory should be able to determine its name, cat (Feb 2021) case Command issued or test performed Expected resulting action Expected print output Verification method Comments 1 pwd is a pinter that points to a Directory create a new Directory and call its By comparing the print object. A Directory object has a getPath a new Directory is created getPath() method "/" method which returns the path to the output win what is directory from the root. Every time the expected pwd is changed through the cd command) the path string should be changed. Confirm that runCommand function can be runCormand runs and returns a The output is "No such command! since "No such corumand!" successfully called pointer to a Directory when testing, a dummy command that is not in the list of our commands is used 2 3 19 4 touch 5 touch file a print directories then files, all separated by single spaces and List the contents of the pwd all on one line. By comparing the print (present working directory) Ensure there is no trailing space in the output wih what is Directories should line printed expected be suffixed with "{d)". Directories should precede files. No action, since no operand touch: operand By checking the is provided missing! printed output By running the command Verifying this needs 13 to be worlding file a is created in the pwd 13 and checking 103 wen. Note that there should be NO cout in output chis case. File_a and file b are created By running she command Veri yang this needs 3 to be working N/A 13 and checking 103 well. Note that there should be NO cout in in the pwd output this case. Nothing printed for first command: By running the command File c is created in the pwd, second command twice and checking for but the second attempt to Veri yang ches needs 13 to be working we prints "sale the required print create it should fail with that name output already exists!" The cons of the new be vevised creates a file called filed By running 13 to using the display command (cest case 18). in the pwd and its content is N/A verify that the file Note that there should be NO sous for the has been created eet to someContents OneWord" nano command. "mkdir: operand By checking the No action, since no operand missing! printed output 19 provided 6 touch file a file b touch file (same command twice) nano tile_d someContent Oneword

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions