Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.117.192.64
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/acyurksaitis/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/acyurksaitis/hw6.cpp
// CS212 HW #6:  hw6.cpp
//
// Due:          April 2, 2008
//
// Author:       Amy Yurksaitis
//
// Instructor:   Dr. Wang
//
// Goal:         This program will allow the user to input a string,
//               find a string, print the string list, sort the list
//               to ascending order, and quit.
//
// Compile:      g++ hw6.cpp -o hw6.out
// Run:          ./hw6.out
/////////////////////////////////////////////////////////////////////////////


#include <iostream>
#include <string>


using namespace std;

const int MAX = 100;


class List
{ 	
	int length;
	string name[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; 
	void Insert ( string item ) 
	{ 	name[ length ] = item;
		length ++;
	}
	bool IsPresent ( string item ) const
	{
		bool done = false;
		for ( int k=0; k<length && ! done; k++ )
			if ( name[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(name[minIndex] > name[k])
                                        minIndex=k;
                        }
                        temp = name[minIndex];
                        
                        name[minIndex] = name[passCount];
                       
                        name[passCount] = temp;
                }
        }
                
};

void List:: Print() const
{       for(int k=0; k<length; k++)
                cout<< name[k]  << endl;
}

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;
	}
	getchar(); 
	return 0;
} 

void menu ()
{	
	cout << "\n\n==========================================\n\n" <<endl;	 
	cout << "  I   to insert name to list.\n";
	cout << "  F   to find a name on the list.\n";
	cout << "  P   to print the list.\n";
	cout << "  S   to sort the list in ascending order.\n";
	cout << "  Q   to quit the operation.\n";
	cout << " \nYou choose: ";
}
void process ( char ch, List& myList )
{
	string names;
	 
	switch ( tolower(ch) )
	{ 	case 'i':
			cout <<"Input full name: ";
			cin.ignore ();
                       	getline(cin, names);  
			myList.Insert(names);                        
                        //cout << "The list is:  " << endl;
                        //myList.Print();
                        cout << "\n\nType any key to continue .." <<endl;
                        getchar();
                        break;
		case 's':
			cout << "The list is: " << endl;
			myList.SelSort();
			myList.Print();
			cout << "\n\nType any key to continue .." <<endl;
                        getchar();
			break;
		case 'p':
			cout << "The list is: " <<endl;
			myList.Print();
			cout << "\n\nType any key to continue .." <<endl;
			getchar();
			break;
		case 'f':
			cout << "Input an item to be found: ";
			cin.ignore ();
			getline(cin,names);
			if ( myList.IsPresent(names) )
				cout << names << " is in the list.\n";
			else
				cout << names << " isn't in the list.\n";
			cout << "\n\nType any key to continue .." <<endl;
			getchar();
			break;
		default:
			cout << "\nInvalid input.\n" ;
			cout << "\n\nType any key to continue .." <<endl;
			getchar(); 	
	}
	
	return;
}

Stv3n404 - 2023