Server IP : 172.16.15.8 / Your IP : 3.15.228.162 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/jljustice/cs212/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Author: Jared Justice // Instructor: Dr.Wang // Due Date: March 30, 2009 // File name: assign7.cpp // Goal: To create a word List by allowing the user to input // words, find a word,sort the words, print the words, and // quit. #include <iostream> using namespace std; const int MAX = 50; class List { int length; string data[MAX]; public: List() { length = 0; } int Length () const { return length; } bool IsFull () const { return (length == MAX); } bool IsEmpty () const { return (length == 0); } void Print () const { for( int k = 0; k < length; k++ ) cout << data[k] << ' '; cout << endl; } void Insert (string item) { data[length] = item; length ++; } bool IsPresent (string item) { bool done = false; for( int k = 0; k < length && ! done; k++) if( data[k] == item) done = true; return done; } void SelSort () { string temp; int passCount; int minIndex; for(passCount = 0; passCount < (length -1); passCount ++) minIndex = passCount; for(int k = (passCount +1); k < length; k++) if( data[minIndex] > data[k]) minIndex = k; temp = data[minIndex]; data[minIndex] = data[passCount]; data[passCount] = temp; } }; void menu (); void process (char, List& ); int main() { List myList; char ch; menu (); cin >> ch; while (tolower(ch) != 'q' ) { process(ch, myList); menu (); cin >> ch; } return 0; } void menu () { cout << endl; cout << "I Insert a word\n"; cout << "F Find a word\n"; cout << "P Print the list\n"; cout << "S Sort the list\n"; cout << "Q Quit the program\n"; cout << "\n\tSelect One\n"; cout << "------------------------------\n"; } void process (char ch, List& myList) { string datum; switch (tolower (ch) ) { case 'i': cout << "Input a word: "; cin >> datum; myList.Insert(datum); cout << "\nPlease make another selection: "; break; case 's': myList.SelSort(); cout << "\nPlease make another selection: "; break; case 'p': cout << "The List is: "; myList.Print(); cout << "\nPlease make another selection: "; break; case 'f': cout << "Input the word to be found: "; cin >> datum; if( myList.IsPresent(datum) ) cout << datum << "is in the list.\n"; else cout << datum << "isn't in the list.\n"; cout << "\nPlease make another selection: "; break; default: cout << "\nInvalid input.\n"; cout << "\nPlease make another selection: "; } return; }