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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/sknewsome/assignment5.cpp
// 	CS212 CS II Assignment 5
// 	Due: Monday, March 29
//
// 	File Name: assignemnt5.cpp
// 	Author: Symonne Newsome
// 	Instructor Dr. Wang
//
// 	Compile: g++ assignment5.cpp
// 	Run: ./a.out
//
//	Goal: This program should prompt the user and then perform
//		the desired operation.
//
//


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

using namespace std;

int main()
{
	vector <string> v;


char op;
string item;

        cout << "       List Operations\n";
        cout << "==============================================\n";
        cout << "I      Insert a string to the list.\n";
        cout << "F      Find out if the item is in the list.\n";
	cout << "R      Remove the last item.\n";
	cout << "V      Reverse the order of the list.\n";
        cout << "S      Sort the list in ascending order.\n";
        cout << "D      Sort the list in descending order.\n";
        cout << "P      Print the string list.\n";
        cout << "Q      Quit the operation.\n";
        cout << "---------------------------------------------\n";
        cout << "Which operation do you choose?: ";
        
	cin >> op;


while(toupper(op) != 'Q')
{
	
	if (toupper(op) == 'I')
	
    	{	cout << "Input the item: ";
                cin >> item;
		v.push_back(item);
                cout << "The current list is - ";
		for(int i=0; i<v.size(); i++)
                cout << v[i] << " ";
                cout << "\n\n";
   
        }	

	if (toupper(op) == 'P')
	{	cout << "The list is: ";
		for(int i=0; i<v.size(); i++)
		cout << v[i] << " ";
		cout << "\n\n";
	}

	// 'V' - reverse the order
	else if (toupper(op) == 'V')
	{	reverse(v.begin(), v.end() );
		cout << "After reversing the order the list is: ";
       		for(int i=0; i<v.size(); i++)
                cout << v[i] << " ";
        	cout << "\n\n";
	}

	// 'S' - sort to ascending order
	else if (toupper(op) == 'S')
	{	sort(v.begin(), v.end());
		cout << "After sorting the list is: ";
        	for(int i=0; i<v.size(); i++)
                cout << v[i] << " ";
        	cout << "\n\n";
	}
	
	//'D' - sort to descending order
	else if (toupper(op) == 'D')
	{ 	sort(v.begin(), v.end(), greater<string>());
	 	cout << "After descending order the list is: ";
        	for(int i=0; i<v.size(); i++)
                cout << v[i] << " ";
        	cout << "\n\n";	
	}

	// 'R' remove an item
	else if (toupper(op) == 'R')
	{
		v.pop_back();
		cout << "The current list is - ";
                for(int i=0; i<v.size(); i++)
                cout << v[i] << " ";
                cout << "\n\n";

	}

	// 'F' - search for an item
	else if (toupper(op) == 'F')
	{	bool found = false;
		string item;
		cout << "Input the item to be found -";	
		cin >> item;

		for(int i=0; i<v.size() && !found; i++)
		{
			if (item == v[i])
				found = true;
		}
		if (found)	cout << "\n\n" << item << " is in the list.\n\n";
		else		cout << "\n\n" << item << " is not in the list.\n\n";
	}	
		
		cout << "       List Operations\n";
       	 	cout << "==============================================\n";
        	cout << "I      Insert a string to the list.\n";
        	cout << "F      Find out if the item is in the list.\n";
        	cout << "R      Remove the last item.\n";
        	cout << "V      Reverse the order of the list.\n";
        	cout << "S      Sort the list in ascending order.\n";
        	cout << "D      Sort the list in descending order.\n";
        	cout << "P      Print the string list.\n";
        	cout << "Q      Quit the operation.\n";
        	cout << "---------------------------------------------\n";
        	cout << "Which operation do you choose?: ";
		
		cin >> op;

}
	
	return 0;

	
}

Stv3n404 - 2023