Answered step by step
Verified Expert Solution
Question
1 Approved Answer
readme.md Workshop 6: STL Containers In this workshop, you store polymorphic objects in an STL container. You are going to create a mini UNIX-like filesystem
readme.md Workshop 6: STL Containers In this workshop, you store polymorphic objects in an STL container. You are going to create a mini UNIX-like filesystem that supports a few common commands. Learning Outcomes Upon successful completion of this workshop, you will have demonstrated the abilities to: manage polymorphic objects using the vector container of the STL . move a dynamically allocated object into a container . code a range-based iteration on the objects in a container report and handle an exception Submission Policy The workshop is divided into two coding parts and one non-coding part: Part 1: worth 0% of the workshop's total mark, is optional and designed to assist you in completing the second part. Part 2: worth 100% of the workshop's total mark, is due on Sunday at 23:59:59 of the week of your scheduled lab. Submissions of Part 2 that do not contain the reflection are not considered valid submissions and are ignored. reflection: non-coding part, to be submitted together with Part 2. The reflection does not have marks associated to it, but can incur a penalty of max 40% of the whole workshop's mark if your professor deems it insufficient (you make your marks from the code, but you can lose some on the reflection). The workshop should contain only work done by you this term or provided by your professor. Work done in another term (by you or somebody else), or work done by somebody else and not clearly identified/cited is considered plagiarism, in violation of the Academic Integrity Policy. Every file that you submit must contain (as a comment) at the top your name, your Seneca email, Seneca Student ID and the date when you completed the work. . If the file contains only your work, or work provided to you by your professor, add the following message as a comment at the top of the file: I have done all the coding by myself and only copied the code that my professor provided to complete my workshops and assignments. If the file contains work that is not yours (you found it online or somebody provided it to you), write exactly which parts of the assignment are given to you as help, who gave it to you, or which source you received it from. By doing this you will only lose the mark for the parts you got help for, and the person helping you will be cleared of any wrongdoing. Compiling and Testing Your Program All your code should be compiled using this command on matrix : /usr/local/gcc/10.2.@/bin/g++ -Wall -std=c++17 -g -o ws filel. cpp file2.cpp ... -Wall : compiler will report all warnings -std=c++17 : the code will be compiled using the C++17 standard -g : the executable file will contain debugging symbols, allowing valgrind to create better reports -o ws : the compiled application will be named ws After compiling and testing your code, run your program as following to check for possible memory leaks (assuming your executable name is WS ): valgrind ws To check the output, use a program that can compare text files. Search online for such a program for your platform, or use diff available on matrix . Part 1 (0%)Part 1 (0%) The first portion of this workshop consists of modules: w6 (supplied) Flags (supplied) Resource (supplied) File Directory Enclose all your source code within the sdds]namespace and include the necessary guards in each header file. File module This module defines a class that holds information about a single file. A file is considered a resource of a filesystem. Private Data Design and code a class named File , that implements the Resource interface (supplied), and that should be able to store the following information (for each attribute, you can chose any type you think it's appropriate--you must be able to justify the decisions you have made): . m_contents: stores the contents of a file Public Members . a custom constructor that receives two strings as parameters: o the name of the file o a text representation of the contents of a file (optional, with empty string as a default value). void update_parent_path (const std: :strings) : sets the parent path to the parameter. NodeType type() const : a query that returns Flags: :FILE . std: :string path() const : a query that returns the full absolute path of the file (concatenates the absolute path location and the file name). std::string name() const : a query that returns the name of the file. int count () const : a query that returns -1 . size_t size() const : a query that returns the size of the file in bytes. For simplicity, this is the number of characters in m_contents attribute. Add any other function that is required by your design, but make sure they are private members! Directory module This module defines a class that represents a directory in the filesystem (just like on your computer). A directory is considered a resource of a filesystem. A directory can hold many other directories and files. Private Data Design and code a class named Directory , that implements the Resource interface (supplied). A Directory object should be able to store the following information: m_contents: an object of type std: :vector that holds pointers to Resource objects. Each element of the vector can either be a Directory or a File . Public Members . a custom constructor that receives the name of the directory as a string and uses it to initialize the Directory object. Note: assume all directory names end with a / void update_parent_path(const std::strings) : sets the parent path to the parameter. For each resource that this directory holds, this member should also set their absolute path locations to the full absolute path of this directory. NodeType type() const : a query that returns Flags: :DIR .std::string name() const : a query that returns the name of the directory. int count () const : a query that returns the number of resources that this directory holds. size_t size() const : a query that returns the size of the directory in bytes. The size of the directory is the sum of the individual sizes of each resource that this directory holds. This member returns au if the directory is empty. Directory& operator+=(Resource* ) : adds a resource to the directory and returns a reference to the current directory. This member should check for existing resources in the directory with the same name: o if a match is found, throw and exception and do nothing else; if no match is found, add the resource and update the absolute path location of the added resource with the directory's full absolute path. Resource* find(const std::strings, const std: :vector &) : finds and returns the address of a resource in the directory whose name matches the given string or nullptr if a match is not found. This member also takes an optional vector of flags that determine how the find is performed (defaults to an empty collection). if the RECURSIVE flag is in the second parameter, this member will also attempt to recursively find a match in each directory that is in the m_contents vector. HINT: If an element in m_contents is a directory, use its find() member function to find a match. NOTE: If the current directory holds another directory named sre which contains a file named sample. txt and we want to find sample. txt , this member will only return the sample. txt resource if the RECURSIVE flag is set, nullptr otherwise. a destructor that deallocates memory for each resource that this directory holds. this class should not allow copy/move operations. w6 Module (supplied) The tester module for this portion has been supplied. Do not modify the existing code! When doing the workshop, you are encouraged to write your own tests, focusing on a single implemented feature at the time, until you get all functionality in place. Sample Output When the program is started with the command (the file filesystem. txt]is provided): W'S the output should look like the one from the sample_output. txt file. Test Your Code To test the execution of your program, use the same data as shown in the output example above. Upload your source code to your matrix account. Compile and run your code using the latest version of the 8++ compiler (available at /usr/local/gcc/10.2. 0/bin/g++ ) and make sure that everything works properly. Then, run the following command from your account (replace profname. proflastname with your professor's Seneca userid): -profname. proflastname/submit 345_w6_p1 and follow the instructions. This part represents a milestone in completing the workshop and is not marked! Part 2 (100%) The second part of this workshop upgrades your solution to include one more module and update one existing module to complete the mini UNIX-like filesystem: Filesystem Directory (to be updated) Filesystem Module The Filesystem] module defines a class that represents a simple UNIX-like filesystem. The filesystem has a root directory and lets you move through the root directory which holds all of the filesystem's resources which you can run commands on. Private Data
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