Question
Code is currently broken and I'm not sure what I did wrong. The error is on line 6. Please help with the error and any
Code is currently broken and I'm not sure what I did wrong. The error is on line 6. Please help with the error and any other errors you find and explain what you did, thanks! Also show sample of output.
Assignment instructions: Specify and implement an ADT character string by using a linked chain of characters. Include typical operations such as finding its length, appending one string to another, finding the index of the leftmost occurrence of a character in a string, and testing whether one string, and testing whether one string is a substring of another.
- Program must compile and run.
- Create an ADT character string as a class (LinkedChar is name I am using) that uses a linked list of each character.
- Do not use any STL container for the internal data structure.
- The LinkedChar class minimally has the methods in the UML diagram below. You can add more methods.
- Main function will have a menu of options.
- Enter new string and store as linked list of characters in an ADT LinkedChar class
- Get current length (number of characters stored) from the LinkedChar
- Find index of character in this LinkedChar
- Append another LinkedChar to this LinkedChar (no shallow copy)
- Test if another LinkedChar is submatch of this LinkedChar
- Quit
Current code charchain.cpp
#include
#include
#include
void AddList(LinkedList
{
for (int i = input.size()-1; i >=0; i--)
{
List.add(input[i]);
} // end for loop
} // end ListTester
bool ifSubString(LinkedList
{
std::string fromTheList = List.toString();
return (fromTheList.find(subString) != std::string::npos);
}
void AppendList(LinkedList
{
List.clear();
for (int i = input.size()-1; o >=0; i--)
{
List.add(input);
}
}
int main()
{
std::string userString, newstring, substring;
int choice;
char charInput;
LinkedList
std::cout << "Welcome to the linkedlist program " < std::cout << "Please Enter the string before we start: "; getline(std::cin, userString); AddList(listik, userString); std::cout << "The string \"" << userString << "\" has been added to the linked list. " << std::endl; std::cout << "Menu: " << std::endl; std::cout << "1. Find the length of your input." << std::endl; std::cout << "2. Add a new string to the current string." << std::endl; std::cout << "3. Find the index of the character." << std::endl; std::cout << "4. Find matches in the string." << std::endl; std::cout << "5. Quit and sleep" << std::endl; std::cin >> choice; std::cin.ignore(); while(choice!=5) { switch(choice) { case 1: std::cout << "The List " << listik.toString() << " contains " << listik.getCurrentSize() << " elements." << std::endl; std::cout << std::endl; break; case 2: std::cout << "Please type the string you'd like to append to the current list: "; getline(std::cin, newstring); Appendlist(listik, (userString+newstring)); std::cout << "The list is \"" << listik.toString() << "\"." << std::endl; //AppendList function contains add method std::cout << std::endl; break; case 3: std::cout << "Please type the character you'd like to have the index of: "; std::cin >> charInput; std::cout << "The index of \"" << charInput << "\" is " << listik.getFrequencyOf(charInput) << std::endl; std::cout << std::endl; break; case 4: std::cout << "Please type the string you'd like to find in the current list: "; getline(std::cin, subString); std::cout << "The string \"" << subString << "\" is"; if (ifSubString(listik, subString)==false) std::cout << " not"; std::cout << "found in \"" << listik.toString() << "\"." << std::endl; std::cout << std::endl; break; case 5: listik.clear(); exit(0); break; } } }
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