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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/bafreeman/assign6.cpp
//      File name:      assign6.cpp
//      Author:         Benjamin Freeman
//      Instructor:     Dr. John Wang
//      Due date:       Wed., Apr. 2, 2008
//      Compilation:    g++ assign6.cpp -o assign6.out
//      Execution:      ./assign6.out
//
//      Goal: This program will allow the user to perform the following operations:
//	insert a name, find a name, print the name list, sort the list, and quit the program.

#include <iostream>
using namespace std;
const int MAX = 100;

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] << endl;
	}
	void Insert ( string item )
	{ 
		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 Sort ( );
};


void List :: Sort ( )
{ 
	string temp; 
	int pC;
	int mI;
	
	for ( pC=0; pC<length-1; pC ++ )
	{ 
		mI = pC;
		for ( int k=pC+1; k<length; k++ )
		{ 
			if ( data[mI] > data[k] )
				mI = k;
		}
	
		temp = data[mI];
		data[mI] = data[pC];
		data[pC] = 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;
	}
	cout << "\n----------------------------------" << endl;
	cout << "Thanks for using the program, bye" << endl;
	cout << "----------------------------------" << endl;
	getchar();
	return 0;
}

void menu ()
{
	cout << "-------------------------------------\n";
	cout << "Welcome to the name storage program\n";
	cout << "-------------------------------------\n";
	cout << "i: insert a name\n";
	cout << "f: find a name\n";
	cout << "p: print the name list\n";
	cout << "s: sort the name list\n";
	cout << "q: quit the program\n";
	cout << "\nChoose your operation: ";
}

void process ( char ch, List& myList )
{
	string s1;
	char dummy;
	switch ( tolower(ch) )
	{ 
		case 'i':
			cout << "Input a name (first, middle initial, last): ";
			cin.get(dummy);
			getline(cin, s1);
			cout << "The name has been stored.\n";
			myList.Insert(s1);
			getchar();
			break;

		case 's':
			myList.Sort();
			cout << "The list has been sorted.\n";
			getchar();
			break;
		case 'p':
			cout << "\nThe list is: " << endl;
			myList.Print();
			getchar();
			break;
		case 'f':
			cout << "Input what name you want to find: ";
			cin.get(dummy);
			getline(cin, s1);
			if ( myList.IsPresent(s1) )
				cout << s1 << " is in the list.\n";
			else
				cout << s1 << " isn't in the list.\n";
			getchar();
			break;
		default:
			cout << "\nInvalid input.\n" ;
			cout << "\n\nType any key to continue ..\n";
			getchar();
	}
	return;
}


Stv3n404 - 2023