Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.188.91.223
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/assign7b.cpp
//      File name:      assign7b.cpp
//      Author:         Benjamin Freeman
//      Instructor:     Dr. John Wang
//      Due date:       Wed., Apr. 9, 2008
//      Compilation:    g++ assign7b.cpp -o assign7b.out
//      Execution:      ./assign7b.out
//
//      Goal: This program will allow the user to perform the following operations:
//	insert a string to the vector, delete the last string, sort the vector to ascending order, 
//	sort it to descending order, print the number of the strings in the vector, 
//	reverse the strings order in the vector, empty the vector.

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void menu ();
void process ( char);

int main()
{
	char ch;
	menu();
	cin >> ch;
	while ( tolower(ch) != 'h' )
	{
	
	string s1;
        vector<string> data;
        char dummy;
        switch ( tolower(ch) )
        {
                case 'a':
                        cout << "Input a word: ";
                        cin >> s1;
                        data.push_back(s1);
                        cout << "Size is: " << data.size() << endl;
                        cout << "The list is:\n";
                        for ( int k = 0; k < data.size(); k++ )
                                cout << data[k] << endl;
                        getchar();
                        break;
                        
                case 'b':
                        data.pop_back();
                        cout << "The list is now:\n";
                        for ( int k = 0;  k < data.size(); k++ )
                                cout << data[k] << endl;
                        getchar();  
                        break;
                case 'c':
                        sort(data.end(), data.begin(), greater<string>());
                        cout << "\nThe list in ascending order is:\n";
                        for ( int k = 0; k < data.size(); k++ )
                                cout << data[k] << endl;
                        getchar();
		 case 'd':
                        reverse(data.end(), data.begin());
                        cout << "\nThe list in descending order is:\n";
                        for ( int k = 0; k < data.size(); k++ )
                                cout << data[k] << endl;  
                        getchar();
                        break;
                case 'e':
                        cout << "The number of words in the list is: " <<
                        data.size();
                        cout << endl;
                        getchar();
                        break;
                case 'f':
                        reverse(data.begin(), data.end());
                        cout << "The list has been reversed, it is now:\n";
                        for ( int k = 0; k < data.size(); k++ )
                                cout << data[k] << endl;
                        getchar();
                        break;
                case 'g':
                        data.clear();
			cout << "The list is now empty\n";
                        getchar();
                        break;
                default: 
                        cout << "\nInvalid input.\n" ;
                        cout << "\n\nType any key to continue ..\n";
                        getchar();   
        }
 


		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 << "h: quit the program\n";
	cout << "\nChoose your operation: ";
}


		



	

Stv3n404 - 2023