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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/mrlong/assignment7.cpp
//	Miles Long
//	Instructor: Dr. Wang
//	04/09/2008
//	Filename: assignment7.cpp
//
//	Program that allows you to insert a string into a vector then either
//	sort ascending/descending, count, or erase.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// function prototypes
void menu ();
void process(char);

vector<string> v;

int main()
{
	string input;
	char menu_int;
	string garbage;
 		
	menu(); // read first data
        cin >> menu_int; // ch: 1, 2, 3, 4, 5, 6 , 7, 8
        getline( cin, garbage );

	while ( menu_int != '8' )
        {
                process(menu_int);
                menu(); // read next data
                cin >> menu_int; // ch: 1, 2, 3, 4, 5, 6, 7, 8
                getline( cin, garbage ); // get rid of the newline
        }

        cout << "Press any key to exit the program. " << endl;
        getchar();
        return 0;

}

void menu ()
{
	system("clear");
        cout << "\n\nVector Menu\n";
        cout << "-=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-";
        cout << "\n1 Insert a string\n";
        cout << "2 Delete the last string\n";
        cout << "3 Sort to ascending order\n";
        cout << "4 Sort to descending order\n";
        cout << "5 Print the number of strings\n";
	cout <<	"6 Reverse the strings order\n";
	cout <<	"7 Empty the vector\n";
	cout << "8 Quit\n";
	cout << "-=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-";

        cout << "\nYou choose: ";
}


void process ( char menu_int )
{
	char dummy;
        string input_string;
        switch ( menu_int )
                {
                        case '1':	//Insert String
                        	cout <<"\nEnter string to insert: ";
                                cin >> input_string;
                                v.push_back(input_string);
                                cout << "The list is: ";
                                for( int i = 0; i < v.size(); i++ )
                                        cout << v[i] << ", ";
                                cout << "\n\nType any key to continue: ";
                                cin.get(dummy);
                                cin.get(dummy);
                                system("clear");
                                break;
			case '2':	//Delete last string
                                v.pop_back();
                                // for debug
                                cout << "\nThe list is: ";
                                for( int i = 0; i < v.size(); i++ )
                                        cout << v[i] << ", ";
                                cout << "\n\nType any key to continue ..";
                                getchar();
				system("clear");
				break;
			case '3':	//Sort ascending
                                sort( v.begin(), v.end() );
				cout << "\nThe list is: ";
                                for( int i = 0; i < v.size(); i++ )
                                        cout << v[i] << ", ";
                                cout << "\n\nType any key to continue ..";
                                getchar();
				system("clear");
                                break;
                        case '4':	//Sort descending
                                sort( v.begin(), v.end(), greater<string>() );
				cout << "\nThe list is: ";
                                for( int i = 0; i < v.size(); i++ )
                                        cout << v[i] << ", ";
				cout << "\n\nType any key to continue ..";
                                getchar();
				system("clear");
                                break;
                        case '5':	//Output size
				int num;
				num = v.size();
				cout << "\nThe size of vector is: " << num;
				cout << "\nThe list is: ";
                                for( int i = 0; i < v.size(); i++ )
                                        cout << v[i] << ", ";	
				cout << "\n\nType any key to continue ..";
                                getchar();
				system("clear");
                                break;
			case '6':	//Reverse order
				reverse(v.begin(), v.end());
				cout << "\nAfter reverse the order is: ";
				for( int i = 0; i < v.size(); i++ )
                			cout << v[i] << ", ";
				cout << "\n\nType any key to continue ..";
                                getchar();     
				system("clear");                          
				break;
			case '7':	//Empty vector
				v.clear();
				cout << "\nThe list is: ";
                                for( int i = 0; i < v.size(); i++ )
                                        cout << v[i] << ", ";
				cout << "\n\nType any key to continue ..";
                                getchar();
				system("clear");
                                break;
			
                        default:
                                cout << "\nInvalid input.\n" ;
                                cout << "\n\nType any key to continue ..";
                                getchar();
        }
        return;
}


	

Stv3n404 - 2023