Server IP : 172.16.15.8 / Your IP : 3.149.253.73 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 (0705) : /home/mrlong/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Miles Long // Instructor: Dr. Wang // 2/2/08 // filename: assignment6.cpp // Program that allows you to insert, sort, find, and print names. // #include <iostream> #include <fstream> #include <iomanip> using namespace std; const int MAX=100; class List { int length; string data[MAX]; public: List() // empty { length = 0; } int Length() const { return length; } bool IsFull() const { return ( length == MAX ); } bool IsEmpty() const { return ( length == 0 ); } void Print() const // as an array { for ( int k=0; k<length; k++ ) cout << data[k] << '\n'; cout << endl; } void Insert ( string item ) // to the last { data[ length ] = item; length ++; } bool IsPresent ( string item ) const { bool done = false; for ( int k=0; k<length && ! done; k++ ) if ( data[k] == item ) done = true; return done; } void SelSort ( ); }; // implementation void List :: SelSort ( ) { string temp; // for swapping int passCount; int minIndex; // hold the index of the minimum // total (length - 1) passes for ( passCount=0; passCount<length-1; passCount ++ ) { // search the smallest from present location minIndex = passCount; // compare from next item for ( int k=passCount+1; k<length; k++ ) { if ( data[minIndex].compare(data[k]) > 0 ) minIndex = k; } // find the minIndex, then swap it with the starting index temp.assign( data[minIndex]); data[minIndex].assign(data[passCount]); data[passCount].assign(temp); } } // function prototypes void menu (); void process ( char, List& ); int main() { List myList; //empty object char menu_int; string garbage; menu(); // read first data cin >> menu_int; // ch: 1, 2, 3, 4, 5 // get rid of the newline character in the buffer getline( cin, garbage ); while ( menu_int != '5' ) { process(menu_int, myList); menu(); // read next data cin >> menu_int; // ch: 1, 2, 3, 4 getline( cin, garbage ); // get rid of the newline } cout << "Press any key to exit the program. " << endl; getchar(); system("clear"); return 0; } void menu () { system("clear"); cout << "\n\nName Recorder!!!\n"; cout << "-=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-"; cout << "\nPress 1 to insert a name.\n"; cout << "Press 2 to find a name.\n"; cout << "Press 3 to print your names.\n"; cout << "Press 4 to sort the list of names.\n"; cout << "Press 5 to quit the operation.\n"; cout << "-=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-"; cout << "\n\nChoose a number: "; } void process ( char menu_int, List& myList ) { string input_string; switch ( menu_int ) { case '1': cout <<"\n\nEnter Name( Ex.First M Last ): "; getline(cin, input_string); myList.Insert(input_string); // for debug cout << "\n\nThe list is: "; myList.Print(); cout << "\n\nType any key to continue .."; getchar(); system("clear"); break; case '4': myList.SelSort(); // for debug cout << "\n\nThe list is: "; myList.Print(); cout << "\n\nType any key to continue .."; getchar(); system("clear"); break; case '3': cout << "\n\nThe list is: "; myList.Print(); cout << "\n\nType any key to continue .."; getchar(); system("clear"); break; case '2': cout << "\n\nInput name to be found (Ex. First M Last): "; getline(cin, input_string); if ( myList.IsPresent(input_string) ) cout << input_string << " is in the list.\n"; else cout << input_string << " \n\nIsn't in the list.\n"; cout << "\n\nType any key to continue .."; getchar(); system("clear"); break; default: cout << "\nInvalid input.\n" ; cout << "\n\nType any key to continue .."; getchar(); system("clear"); } return; }