Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.217.10.200
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/ex8.cpp
#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<< data[k]  << endl;
	}
};


int main()
{
	char ch;

	menu();
	cin >> ch;

	while (tolower(ch) != 'q')
	{
		switch(tolower(ch))
		{
			case 'i':	
				cout << "\tNow play the integer List-";
				process<int>();
				break;
			case 'c':
                                cout << "\tNow play the  character list: ";
                                process<char>();
                                break;
			case 's':
                                cout << "\tNow play the string list: ";
                                process<string>();
                                break;   
			default:
				cout << "\nInvalid, redo it\n";
		}
		menu();
		cin >> ch;
	}
	cout << "\n\nDone.\n";
	return 0;
}

//--------------------------------
template<class T>
void process()
{
	char selection;
	//cout << "\n\n\tProcess Here...\n\n";
	List<T> z;
	T item;
	menuForList();
	cin >> selection;
	while(tolower(selection) !='q')
	{
		switch (tolower(selection))
		{
			case 'i': 
				cout << "Input an item: ";
				cin >> item;
				z.Insert(item);
				break;
			case 'p':
				cout << "The list is: " << endl;
				z.Print();
				break;
			default:
				cout << "\n\nInvalid. Try again....\n\n";
	
		}
		menuForList();
	        cin >> selection;
	}
}


//---------------------------------

void menu()
{
	cout << "\n\n\t--- Welcome to the bigger game! ---\n";
	cout << "\t    =============================\n\n";
	cout << "\tI	Integers\n";
	cout << "\tC	Characters\n";
	cout << "\tS	Single String\n";
	cout << "\tQ	Quit\n";
	cout << "\t------------------------\n";
	cout << "\n\tYour choice: ";
}

void menuForList ()
{	
	cout << "\n\n==========================================\n\n" <<endl;	 
	cout << "  I   to insert item 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 << " \n\tYou choose: ";
}

Stv3n404 - 2023