Question: This Program needs to be done in C++ language. There is a solution available already. But I would really appreciate if I can get a

This Program needs to be done in C++ language. There is a solution available already. But I would really appreciate if I can get a new program. I have attached all files at the end of the program that are needed.

Use the provided itemType class and the specification for the unsorted class to implement a dynamically allocated list. You must create and complete the unsorted.cpp using the provided unsorted.h specification file.

Next, create a driver with a menu to read from an input file of commands to work with your list. The driver will create a new list, open input and output files, read and execute all commands from the list, produce an output file of the results, close files.

Specifically, the driver must do the following with your list:

-prompt user for the name of the input file to use

-prompt user for the name of the output file to use

-prompt user for the name of the test run

-open the input file, reading line by line, and execute the instructions

-display the result to the console and write the result to the output file

The input file can include the following commands:

GetLength

PutItem

PrintList

GetItem

IsFull

DeleteItem

PrintList

MakeEmpty

Quit

Any other commands should result in printing is not a valid command.

Each line of the input file will be a command to execute on your unsortedList instance. Use the attached input file, listData for your project.

Be sure to search the provided code for missing sections to complete. Provide the same functionality as the provided screenshots.

Provide source code, screenshots, and output files from your program running. Submit to Blackboard before the due date.

Itemtype.cpp is given below

// The following definitions go into file ItemType.cpp. #include  #include  #include "ItemType.h" ItemType::ItemType() { value = 0; } RelationType ItemType::ComparedTo(ItemType otherItem) const { if (value < otherItem.value) return LESS; else if (value > otherItem.value) return GREATER; else return EQUAL; } void ItemType::Initialize(int number) { value = number; } void ItemType::Print(std::ostream& out) const // pre: out has been opened. // post: value has been sent to the stream out. { out << value; }

Item.h

// The following declarations and definitions go into file // ItemType.h. #include  const int MAX_ITEMS = 5; enum RelationType {LESS, GREATER, EQUAL}; class ItemType { public: ItemType(); RelationType ComparedTo(ItemType) const; void Print(std::ostream&) const; void Initialize(int number); private: int value; }; 

Example_output

test Length is 0 5 is in list 7 is in list 6 is in list 9 is in list 9675 1 is in list 19675 4 not in list. 5 found in list. 9 found in list. 10 not in list. List is not full. 5 is deleted List is not full. 1 is deleted 6 is deleted 9 is deleted 7 

Unsorted.cpp

// This file contains the linked implementation of class // UnsortedType. #include "unsorted.h" struct NodeType { ItemType info; NodeType* next; }; UnsortedType::UnsortedType() // Class constructor { length = 0; listData = NULL; } //FINISH THIS IMPLEMENTATION

Unsorted.h

#include "ItemType.h" // File ItemType.h must be provided by the user of this class. // ItemType.h must contain the following definitions: // MAX_ITEMS: the maximum number of items on the list // ItemType: the definition of the objects on the list // RelationType: {LESS, GREATER, EQUAL} // Member function ComparedTo(ItemType item) which returns // LESS, if self "comes before" item // GREATER, if self "comes after" item // EQUAL, if self and item are the same struct NodeType; class UnsortedType { public: UnsortedType(); // Constructor ~UnsortedType(); // Destructor void MakeEmpty(); // Function: Returns the list to the empty state. // Post: List is empty. bool IsFull() const; // Function: Determines whether list is full. // Pre: List has been initialized. // Post: Function value = (list is full) int GetLength() const; // Function: Determines the number of elements in list. // Pre: List has been initialized. // Post: Function value = number of elements in list ItemType GetItem(ItemType& item, bool& found); // Function: Retrieves list element whose key matches item's key (if // present). // Pre: List has been initialized. // Key member of item is initialized. // Post: If there is an element someItem whose key matches // item's key, then found = true and someItem is returned; // otherwise found = false and item is returned. // List is unchanged. void PutItem(ItemType item); // Function: Adds item to list. // Pre: List has been initialized. // List is not full. // item is not in list. // Post: item is in list. void DeleteItem(ItemType item); // Function: Deletes the element whose key matches item's key. // Pre: List has been initialized. // Key member of item is initialized. // One and only one element in list has a key matching item's key. // Post: No element in list has a key matching item's key. void ResetList(); // Function: Initializes current position for an iteration through the list. // Pre: List has been initialized. // Post: Current position is prior to list. ItemType GetNextItem(); // Function: Gets the next element in list. // Pre: List has been initialized and has not been changed since last call. // Current position is defined. // Element at current position is not last in list. // // Post: Current position is updated to next position. // item is a copy of element at current position. private: NodeType* listData; int length; NodeType* currentPos; }; 

ListDriver.cpp

// Test driver #include  #include  #include  #include  #include  #include "unsorted.h" using namespace std; void PrintList(ofstream& outFile, UnsortedType& list); int main() { ifstream inFile; // file containing operations ofstream outFile; // file containing output string inFileName; // input file external name string outFileName; // output file external name string outputLabel; string command; // operation to be executed int number; ItemType item; UnsortedType list; bool found; int numCommands; // Prompt for file names, read file names, and prepare files cout << "Enter name of input command file; press return." << endl; cin >> inFileName; inFile.open(inFileName.c_str()); cout << "Enter name of output file; press return." << endl; cin >> outFileName; outFile.open(outFileName.c_str()); cout << "Enter name of test run; press return." << endl; cin >> outputLabel; outFile << outputLabel << endl; if (!inFile) { cout << "file not found" << endl; exit(2); } inFile >> command; numCommands = 0; while (command != "Quit") { //FINISH MENU HERE cout << " Command number " << numCommands << " completed." << endl; inFile >> command; }; cout << "Testing completed." << endl; inFile.close(); outFile.close(); return 0; } void PrintList(ofstream& dataFile, UnsortedType& list) // Pre: list has been initialized. // dataFile is open for writing. // Post: Each component in list has been written to dataFile. // dataFile is still open. { //FINISH PRINTLIST } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!