Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction You will create a C++ program to add, remove and sort objects in a linked list. The purpose of this homework is to get

Introduction

You will create a C++ program to add, remove and sort objects in a linked list. The purpose of this homework is to get students familiar with Linked List and simple sorting techniques. Please name the folder on the server as "hw2".

Input, Command, Output and example files

Input File: The first line of the input file will tell you how to add data to your linked list.

a. Alphabetically: A-Z-a-z (capital letters count first, this is how c++ handles comparing strings anyways)

b. Length: Shortest length - longest length of string

c. Beginning: Add current string to the front of your list

d. End: Add current string to the end of your list

(Note: The rest of the file will contain a list of sentences. Don't add empty lines or duplicate sentences - case and space sensitive.)

Command File: Command file will be filled with 3 types of commands that will be in the order they appear.

a. Add (int location) [string sentence]: The add command will be followed by an integer inside parenthesis and then followed by a sentence inside brackets. If the location is bigger than the size of the list then don't add it. If the sentence is a duplicate don't add it. Example - Add (0) [this would add to the beginning of your list]. Example - Add(3) [example sentence]. This will be the added to the 3rd index meaning it will be the 4th thing in your list. Won't get added if your list is size 2 or less.

b. Remove [string sentence segment]: The remove function will be followed by a string inside brackets. Every sentence that contains that string in any part of the sentence will get removed. Example - Remove [a] This will remove every single sentence with the letter a in it.

c. Sort (alphabetically / length): The sort command will be followed by the word alphabetically or length inside of parenthesis. This will sort the entire list either alphabetically or by length. Example - sort (alphabetically).

Output file: The output file will contain every element of your list after it's been modified by the command file. Each element will be on it own line.

What it should look like:

1.

input21.txt:

Alphabetically for this example the command file will be empty that means you just need to sort this file alphabetically

don't add any empty lines test lines duplicate line there should only be one of this in the output duplicate line there should only be one of this in the output

extra sentence

command21.txt: (Empty)

ans21.txt:

don't add any empty lines duplicate line there should only be one of this in the output extra sentence for this example the command file will be empty test lines that means you just need to sort this file alphabetically

Linux Command: ./files "input=input21.txt;command=command21.txt;output=output21.txt"

2.

input22.txt:

Length

this file will be testing each of the different commands with your sentences test sentence number one another sentence longer sentence than another sentence most of the sentences have the word sentence in them last sentence of the input

command22.txt:

Add (15) [this sentence shouldn't be added because it's out of bounds] Sort (alphabetically) Add (6) [this sentence should be added to the end of the list] Remove [test] Add (0) [another sentence]

ans22.txt:

another sentence last sentence of the input longer sentence than another sentence most of the sentences have the word sentence in them this sentence should be added to the end of the list

Linux Command: ./files "input=input22.txt;command=command22.txt;output=output22.txt"

3.

input23.txt

Beginning here i go typing out a bunch of random sentences so that this assignment can have enough inputs I hope this assignment isn't too challenging but if you're having trouble with it don't give up just take a deep breath and you'll get it however this giant message is just going to be a random jumble of words in the output file

command23.txt:

Remove [us] Sort (length) Sort (alphabetically) Add (0) [this should go to the beginning until it gets sorted] Add (70) [this should not be added] Sort (length) Remove [a] Remove [e] Remove [i] Remove [o] Remove [u] Remove [y] Add (0) [first] Add (1) [second] Add (2) [third] Add (4) [Not added]

ans23.txt:

first second third

Linux Command: ./files "input=input23.txt;command=command23.txt;output23.txt"

NOTE: Must use argument manager.

ArgumentManager.h:

#include #include #include #include using namespace std;

// This is a class that can parse the commnad line arguments we use in COSC 2430 homework. class ArgumentManager { private: map m_argumentMap; public: ArgumentManager() { } ArgumentManager(int argc, char *argv[], char delimiter=';'); ArgumentManager(string rawArguments, char delimiter=';'); void parse(int argc, char *argv[], char delimiter=';'); void parse(string rawArguments, char delimiter=';'); string get(string argumentName); string toString(); friend ostream& operator << (ostream &out, ArgumentManager &am); };

void ArgumentManager::parse(string rawArguments, char delimiter) { stringstream currentArgumentName; stringstream currentArgumentValue; bool argumentNameFinished = false; for (unsigned int i=0; i<=rawArguments.length(); i++) { if (i == rawArguments.length() || rawArguments[i] == delimiter) { if (currentArgumentName.str() != "") { m_argumentMap[currentArgumentName.str()] = currentArgumentValue.str(); } // reset currentArgumentName.str(""); currentArgumentValue.str(""); argumentNameFinished = false; } else if (rawArguments[i] == '=') { argumentNameFinished = true; } else { if (argumentNameFinished) { currentArgumentValue << rawArguments[i]; } else { // ignore any spaces in argument names. if (rawArguments[i] == ' ') continue; currentArgumentName << rawArguments[i]; } } } }

void ArgumentManager::parse(int argc, char *argv[], char delimiter) { if (argc > 1) { for (int i=1; i

ArgumentManager::ArgumentManager(int argc, char *argv[], char delimiter) { parse(argc, argv, delimiter); }

ArgumentManager::ArgumentManager(string rawArguments, char delimiter) { parse(rawArguments, delimiter); }

string ArgumentManager::get(string argumentName) { map::iterator iter = m_argumentMap.find(argumentName);

//If the argument is not found, return a blank string. if (iter == m_argumentMap.end()) { return ""; } else { return iter->second; } }

string ArgumentManager::toString() { stringstream ss; for (map::iterator iter = m_argumentMap.begin(); iter != m_argumentMap.end(); iter++) { ss << "Argument name: " << iter->first << endl; ss << "Argument value: " << iter->second << endl; } return ss.str(); }

ostream& operator << (ostream &out, ArgumentManager &am) { out << am.toString(); return out; }

Please show all work and code.

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

Students also viewed these Databases questions

Question

What is the managers role in a responsibility center?

Answered: 1 week ago

Question

Trudy, when she first saw the bull pawing the ground, ran.

Answered: 1 week ago