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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/bafreeman/assign7c.cpp
//      File name:      assign7c.cpp
//      Author:         Benjamin Freeman
//      Instructor:     Dr. John Wang
//      Due date:       Wed., Apr. 9, 2008
//      Compilation:    g++ assign7c.cpp -o assign7c.out
//      Execution:      ./assign7c.out
//
//      Goal: This program will allow the user to perform the following operations:
//      insert a string to the vector, delete the last string, sort the vector to ascending order,
//      sort it to descending order, print the number of the strings in the vector,
//      reverse the strings order in the vector, empty the vector.
        
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
                       
int main()
{
	vector<string> data;
	int index;
	int num;
	string s1;
	char go;

	cout << "-------------------------------------\n";
        cout << "Welcome to the word storage program\n";
        cout << "-------------------------------------\n";  

	cout << "How many words will you input: ";
	cin >> num;
	for(index = 0; index < num; index++)
	{
		cout << "Please input a word: ";
		cin >> s1;
		data.push_back(s1);
	}
	cout << "\nThe size is: " << data.size();
	cout << "\n---------------------------------------------\n";
	cout <<	"Would you like to delete the last word(y/n): ";
	cin >> go;
	if(go == 'y')
		data.pop_back();
		cout << "The list is now: " << endl;
		for( int i = 0; i < data.size(); i++ )
   			cout << data[i] << endl;
	
	cout << "\n------------------------------------------------------\n";
	cout << "Would you like to sort the list in descending order(y/n): ";
	cin >> go;
	if(go == 'y')
		sort(data.begin(), data.end(), greater<string>());
		cout << "The list is now: " << endl;
                for( int i = 0; i < data.size(); i++ )
                        cout << data[i] << endl;

	cout << "\n------------------------------------------------------\n";
        cout << "Would you like to sort the list in ascending order(y/n): ";
        cin >> go;
        if(go == 'y')
		reverse(data.begin(), data.end());
                cout << "The list is now: " << endl; 
                for( int i = 0; i < data.size(); i++ )
                        cout << data[i] << endl;

	cout << "\n---------------------------------------------------\n";
        cout << "Would you like to reverse the order of the list(y/n): ";
        cin >> go; 
        if(go == 'y')
                reverse(data.begin(), data.end());
                cout << "The List is now: " << endl;
                for( int i = 0; i < data.size(); i++ )
                        cout << data[i] << endl;

	cout << "\n--------------------------------------------------\n";
        cout << "Would you like to empty the list(y/n): ";
        cin >> go; 
        if(go == 'y')
                data.clear();

	cout << "\nThe list has " << data.size() << " words." << endl;
	cout << "\n----------------------------------" << endl;
        cout << "Thanks for using the program, bye" << endl;
        cout << "----------------------------------" << endl;

	return 0;
}

Stv3n404 - 2023