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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jcwhiley/cs2assign5.cpp
// CS212 CS 2 Assignment 5
// Due: Monday March 27, 2011
//
// File Name: cs2assign5.cpp
// Author: Jennifer Whiley
// Instuctor: Dr. Wang
//
// Compile: g++ cs2assign5.cpp
// Run: ./a.out
// Goal: The program will read strings on the keyboard
//       and will perform the actions on the list
//       operations (using vector class.)


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

using namespace std;

void Menu()
{
cout << "       List Operations\n";
cout << " ==================================\n";
cout << "I      Insert Item. \n";
cout << "F      Find Item. \n";
cout << "R      Remove Item. \n";
cout << "V	Reverse Order. \n";
cout << "S      Ascending Order. \n";
cout << "D      Descending Order. \n";
cout << "P      Print List. \n";
cout << "Q      Quit.\n";
cout << " ==================================\n";
cout << "Your option is: ";
}

int main()
{
	vector <string> x;
	string y;
	char op;

	Menu();
	cin >> op;
	while (toupper(op) != 'Q')
	{	
		if(toupper(op) == 'I')
		{	cout << "Insert string: ";
			cin >> y;
			x.push_back(y);
		
			cout << "List: "; 
                        for(int i=0; i < x.size(); i++)
                                cout << x[i] << " " ;
                        cout << "\n\n";
		}
		else if (toupper(op) == 'F')
		{
        		bool found = false;
        		string item;
        		cout << "Input the item to be found: ";
        		cin >> item;
        
        		for(int i=0; i < x.size() && !found; i++)
        		{
                	if (item == x[i] )
                        	found = true;   
        		}
        		if (found)	cout << item << " is in the List.\n\n";
      		  	else cout << item << " is not in List.\n\n";
		}
		else if (toupper(op) == 'R')
		{
			x.pop_back();
		}	
		else if (toupper(op) == 'V')
 		{	reverse(x.begin(), x.end() );
        		cout << "List after reversing: ";

                	for(int i=0; i < x.size(); i++)
                        	cout << x[i] << " " ;
                	cout << "\n\n";
		}
		else if (toupper(op) == 'S')
        	{	sort(x.begin(), x.end() );
			cout << "Ascending Order: ";

                        for(int i=0; i < x.size(); i++)
                                cout << x[i] << " " ;
                        cout << "\n\n";
		}
		else if (toupper(op) == 'D')
                {       sort(x.begin(), x.end(), greater<string>() );
                        cout << "Descending Order: ";
                        
                        for(int i=0; i < x.size(); i++)
                                cout << x[i] << " " ;
                        cout << "\n\n";
		}
	        else if (toupper(op) == 'P')
		{	cout << "Current List: ";
                        for(int i=0; i < x.size(); i++)
                                cout << x[i] << " " ;
                        cout << "\n\n";
                }
		Menu();
		cin >> op;
	}
	return 0;
	
}

Stv3n404 - 2023