(it is a C++ CODE. pls give me some explainlation of how to u write the class, the main.cpp shouldn't only have the arg checker
rubric:
- 35pts Test mode
- You have several tests dedicated to verifying each method works.
- Your tests should check for safe values, corner cases, and invalid values (if they have parameters)
- I've given the GTAs full discretion on how you are assessed for this since many of you will likely have different tests
- 45pts Interactive Mode
- maintaining lists properly and allowing for interaction
- 10pts Memory leaks: There should be no memory leaks. Use valgrind ./YourProgramName to verify
- Any memory leaks will result in a loss of all 10 points!
- Your destructor will play a key role in preventing memory leaks
- 10pts Comments and documentation:
- We are going to use doxygen comment formatting in labs.
- @author, @file, @date, @brief (the author, file name, current date, and a brief description of a file) at the top of every file!
- @pre, @post, @return, (Pre conditions, Post conditions, Return descriptions) in header files. Not required for cpp files
- NOTE you don't need to comment the Makefile
Remember, if we type "make" into the console and your program fails to compile, we do not grade it.
Overview This lab will focus on constructing a Linked List and creating a test class to verify that it works. Requirements You will create a program that runs in one of two modes, interactive mode and test mode. The mode will determined by the command line, passing in a"-i flag for interactive or"t' for test mode. Require the user to pass in a flag. Make a selection: 1) Insert value at position 2) Remove at position 3) Replace value at position 4) Print length 5) Print list 6) Exit Choice: output from your test class automatically prints> LinkedList Header File *ifndef LINKED LIST H define LINKED LIST H #include "Node.h.. //Gone over in class include
//For runt.ime error class LinkedList private: Node* m_front; int m_length: public: LinkedList) LinkedList(const LinkedList& original) -LinkedList Linkedlist& operator-(const LinkedList& original); bool isEmpty const; int getLength) const void insert(int position, int entry) void remove(int position); void clear int getBntry(int position) const; Here s an example of a doxygen comment block. Do this for all methods * pre The position is between 1 and the list's length * post The entry at the given position is replaced with the new entry * @par position: Ics position (z length * Eparam newEntry: A new entry to put in the list * throw std::runtime_error if the position is invalid void replace(int position, int newEntry); end if Method Descriptions LinkedList0) Creates an empty list Copy Constructor Creates a deep copy LinkedList deletes all nodes (note, this could just call clear...) . isEmpty . Returns true if empty, false otherwise .getLength Returns the length insert . adds a node containing the entry at that position (so the number of nodes is increased by 1) positions range from 1 to length+1 NOTE: The reason for length+1 is to insert at the back of the list . if the position is out of range, it throws an exception remove deletes the node at that position (so the number of nodes is decreased by 1) positions range from 1 to length if the position is out of range, it throws an exception clear deletes all nodes in the list . getEntry Returns the entry at a given position positions range from 1 to length if the position is out of range, it throws an exception . replace replaces the entry at a given position The number of nodes is unchanged positions range from 1 to length . if the position is out of range, it throws an exception Notes . You may add private helper functions as you see fit, but their responsibility should be in line with that of a List Never expose private member to other scopes LinkedLists ARE NOT in charge of printing themselves Note: you'll also need to make a Node implementation LinkedListTester class Runs a battery of tests to verify that our Linked List is working Has a single entry point called runTests(0) Each test prints what test is currently running and if the List Passed or failed Each test method should work in a vacuum, meaning each test Sample LinkedListTester.h class LinkedListTester public: LinkedlistTester); //This will call all your test methods void runTests() private: * @brief Creates an empty list and verifies isEmpty() returns true void test01 *ebrief Creates an empty list adds 1 value, verifies isEmpty) returns false void test02 * ebrief Creates an empty list and verifies getLength) returns 0 void test03) //more test methods as needed k t Tests lam provided you with some starter tests that you must implement. You will also be required to add new tests for methods not mentioned here Each test should be ran in isolation, meaning the tests could be run in any order and they don't share any objects/data Size tests 1. size of empty list is zero 2. size returns correct value after inserting at front of list 3. size returns correct value after inserting at back of list 4. size returns correct value after inserting in middle of list 5. size returns correct value after adds and removing from front of list 6. size returns correct value after adds and removing from back of list 7. size returns correct value after adds and removing from middle of list Insert tests 1. insert throws exception if given an invalid position Sample Test Output Test #1: size of empty list is zero PASSED Test 2: size returns correct value after inserting at front of list addFront PASSED Test #3: size returns correct value after inserting at back of list FAILED Checking for Memory Leaks An easy way to check for memory leaks is to use a program called valgrind. It's a program that you can hand your lab off to and it will run your lab and tell if you have any memory leaks. valgrind -leak-check-ful1./YourProgram It will tell you if any leaks occurred. Make sure you have the -g flag in your Makefile and you'll get the added bonus of see what lines of code created an object that was never deleted. Science! Issues with Valgrind Recently, valgrind began reporting on a buffer that automatically allocated then deallocated after our main ends. This would look like youre doing something wrong. But be aware if you run a program with an empty main, you'll see the following ==23799== HEAP SUMMARY: -23799-_ -23799-- total heap usage: 1 aocs, 0 frees, 72,704 bytes allocated in use at exit: 72,704 bytes in 1 blocks 6 -23799-- 23799LEAK SUMMARY: 23799definitely lost: 0 bytes in 0 blocks --23799-- indirectly lost: 0 bytes in 0 block:s possibly lost: 0 bytes in 0 blocks 23799-- -23799still reachable: 72,704 bytes in 1 blocks --23799-- suppressed: 0 bytes in 0 blocks 8 23799-= 2 3 7 99== Reachable blocks (those to which a pointer To see them, rerun with: --leak-check-full was found) are not shown. --show-leak-kinds-all -23799-= 23799== For counts of detected and suppressed errors, rerun with : -v -23799--ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Note the amount of allocations. My empty main didn't allocate anything, but valigrind is reporting everything it can see. There is a buffer being allocated that we don't control t is freed, but after our main ends, so Valgrind reports on it. Just make sure... your allocs are only off by 1 there are no memory error nothing is lost Rubric 35pts lest mode . You have several tests dedicated to verifying each method works. . Your tests should check for safe values, corner cases, and invalid values (if they have parameters) . I've given the GTAs full discretion on how you are assessed for this since many of you will likely have different tests .45pts Interactive Mode maintaining lists properly and allowing for interaction 10pts Memory leaks: There should be no memory leaks. Use valgrind YourProgramName to verify . Any memory leaks will result in a loss of all 10 points! . Your destructor will play a key role in preventing memory leaks 10pts Comments and documentation: We are going to use doxygen comment formatting in labs .@author, @file, @date, @brief (the author, file name, current date, and a brief description of a file) at the top of every file! @pre, @post, @return, (Pre conditions, Post conditions, Return descriptions) in header files. Not required for cpp files NOTE you don't need to comment the Makefile Remember, if we type "make" into the console and your program fails to compile, we do not grade it. Overview This lab will focus on constructing a Linked List and creating a test class to verify that it works. Requirements You will create a program that runs in one of two modes, interactive mode and test mode. The mode will determined by the command line, passing in a"-i flag for interactive or"t' for test mode. Require the user to pass in a flag. Make a selection: 1) Insert value at position 2) Remove at position 3) Replace value at position 4) Print length 5) Print list 6) Exit Choice: output from your test class automatically prints> LinkedList Header File *ifndef LINKED LIST H define LINKED LIST H #include "Node.h.. //Gone over in class include //For runt.ime error class LinkedList private: Node* m_front; int m_length: public: LinkedList) LinkedList(const LinkedList& original) -LinkedList Linkedlist& operator-(const LinkedList& original); bool isEmpty const; int getLength) const void insert(int position, int entry) void remove(int position); void clear int getBntry(int position) const; Here s an example of a doxygen comment block. Do this for all methods * pre The position is between 1 and the list's length * post The entry at the given position is replaced with the new entry * @par position: Ics position (z length * Eparam newEntry: A new entry to put in the list * throw std::runtime_error if the position is invalid void replace(int position, int newEntry); end if Method Descriptions LinkedList0) Creates an empty list Copy Constructor Creates a deep copy LinkedList deletes all nodes (note, this could just call clear...) . isEmpty . Returns true if empty, false otherwise .getLength Returns the length insert . adds a node containing the entry at that position (so the number of nodes is increased by 1) positions range from 1 to length+1 NOTE: The reason for length+1 is to insert at the back of the list . if the position is out of range, it throws an exception remove deletes the node at that position (so the number of nodes is decreased by 1) positions range from 1 to length if the position is out of range, it throws an exception clear deletes all nodes in the list . getEntry Returns the entry at a given position positions range from 1 to length if the position is out of range, it throws an exception . replace replaces the entry at a given position The number of nodes is unchanged positions range from 1 to length . if the position is out of range, it throws an exception Notes . You may add private helper functions as you see fit, but their responsibility should be in line with that of a List Never expose private member to other scopes LinkedLists ARE NOT in charge of printing themselves Note: you'll also need to make a Node implementation LinkedListTester class Runs a battery of tests to verify that our Linked List is working Has a single entry point called runTests(0) Each test prints what test is currently running and if the List Passed or failed Each test method should work in a vacuum, meaning each test Sample LinkedListTester.h class LinkedListTester public: LinkedlistTester); //This will call all your test methods void runTests() private: * @brief Creates an empty list and verifies isEmpty() returns true void test01 *ebrief Creates an empty list adds 1 value, verifies isEmpty) returns false void test02 * ebrief Creates an empty list and verifies getLength) returns 0 void test03) //more test methods as needed k t Tests lam provided you with some starter tests that you must implement. You will also be required to add new tests for methods not mentioned here Each test should be ran in isolation, meaning the tests could be run in any order and they don't share any objects/data Size tests 1. size of empty list is zero 2. size returns correct value after inserting at front of list 3. size returns correct value after inserting at back of list 4. size returns correct value after inserting in middle of list 5. size returns correct value after adds and removing from front of list 6. size returns correct value after adds and removing from back of list 7. size returns correct value after adds and removing from middle of list Insert tests 1. insert throws exception if given an invalid position Sample Test Output Test #1: size of empty list is zero PASSED Test 2: size returns correct value after inserting at front of list addFront PASSED Test #3: size returns correct value after inserting at back of list FAILED Checking for Memory Leaks An easy way to check for memory leaks is to use a program called valgrind. It's a program that you can hand your lab off to and it will run your lab and tell if you have any memory leaks. valgrind -leak-check-ful1./YourProgram It will tell you if any leaks occurred. Make sure you have the -g flag in your Makefile and you'll get the added bonus of see what lines of code created an object that was never deleted. Science! Issues with Valgrind Recently, valgrind began reporting on a buffer that automatically allocated then deallocated after our main ends. This would look like youre doing something wrong. But be aware if you run a program with an empty main, you'll see the following ==23799== HEAP SUMMARY: -23799-_ -23799-- total heap usage: 1 aocs, 0 frees, 72,704 bytes allocated in use at exit: 72,704 bytes in 1 blocks 6 -23799-- 23799LEAK SUMMARY: 23799definitely lost: 0 bytes in 0 blocks --23799-- indirectly lost: 0 bytes in 0 block:s possibly lost: 0 bytes in 0 blocks 23799-- -23799still reachable: 72,704 bytes in 1 blocks --23799-- suppressed: 0 bytes in 0 blocks 8 23799-= 2 3 7 99== Reachable blocks (those to which a pointer To see them, rerun with: --leak-check-full was found) are not shown. --show-leak-kinds-all -23799-= 23799== For counts of detected and suppressed errors, rerun with : -v -23799--ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Note the amount of allocations. My empty main didn't allocate anything, but valigrind is reporting everything it can see. There is a buffer being allocated that we don't control t is freed, but after our main ends, so Valgrind reports on it. Just make sure... your allocs are only off by 1 there are no memory error nothing is lost Rubric 35pts lest mode . You have several tests dedicated to verifying each method works. . Your tests should check for safe values, corner cases, and invalid values (if they have parameters) . I've given the GTAs full discretion on how you are assessed for this since many of you will likely have different tests .45pts Interactive Mode maintaining lists properly and allowing for interaction 10pts Memory leaks: There should be no memory leaks. Use valgrind YourProgramName to verify . Any memory leaks will result in a loss of all 10 points! . Your destructor will play a key role in preventing memory leaks 10pts Comments and documentation: We are going to use doxygen comment formatting in labs .@author, @file, @date, @brief (the author, file name, current date, and a brief description of a file) at the top of every file! @pre, @post, @return, (Pre conditions, Post conditions, Return descriptions) in header files. Not required for cpp files NOTE you don't need to comment the Makefile Remember, if we type "make" into the console and your program fails to compile, we do not grade it