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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/tasantos/hw6.cpp
//Due Date:	2 April 2008
//File Name:	hw6.cpp
//Author: 	Tara Santos
//Instructor:	Dr. Wang
//Execution:	g++ hw6.cpp
//Goal:		Write a C++ program that includes a name 
//		(first name, middle initial, and last) list class and 
//		its driver. The program will perform the following operations 
//		(use a loop so the user can run the code continuously): 
//		1) insert a string; 2) find a string; 3) print the string list;
//		4) sort the list to ascending order; 5) quit.

#include<iostream>
#include<iomanip>

using namespace std;

const int MAX = 100;

class List
{
        int length;
        string name[MAX];

public:
        List ()
        {       length = 0;     }
        int Length () const
        {       return length;  }
        bool isFull () const
        {       return (length == MAX); }
        bool isEmpty () const
        {       return (length == 0);   }
        void Print () const
	{	cout << endl;
		for (int k=0; k<length; k++ )
		 	cout << name[k] << '\n';
		cout << endl;
	}
        void Insert(string aName)
        {
                name[length] = aName;
                length++;
        }
        bool isPresent (string item) const
        {
                bool done = false;
  		for (int k=0; k<length && ! done; k++)
                        if(name[k] == item)
                                done = true;
                return done;
        }
        void SelSort ();
};

void List :: SelSort ()
{       string temp;
        int passCount;
        int minIndex;
        for (passCount = 0; passCount<length-1; passCount ++)
        {       minIndex = passCount;
                for(int k=passCount+1; k<length; k++)
                {       if(name[minIndex] > name[k])
                                minIndex = k;
                }
                temp = name[minIndex];
                name[minIndex] = name[passCount];
                name[passCount]= temp;
                }
        }

void menu ();
void process ( char, List& );

int main()
{
        List myList;
	char ch;

        menu();	
	cin >> ch;
	while ( tolower(ch) != 'q' )
        {
                process(ch, myList);
                menu();
                cin >> ch;
        }

 	return 0;
}

void menu ()
{
	
	cout << "************************************************" << endl;
        cout << " i ---> insert a string\n";
        cout << " f ---> find a string\n";
        cout << " p ---> print the string\n";
        cout << " s ---> sort the list to ascending order\n";
        cout << " q ---> quit the operation\n";
        cout << "************************************************";
	cout << "\nYou Chose: ";
}

void process (char ch, List& myList)
{
        string name;
	string dummy;
        switch (tolower(ch))
        {       case 'i':
                        cout << "Input a string: ";
                        getline(cin, dummy);
			getline(cin, name);
                        myList.Insert(name);
                        cout << "The List is: ";
                        myList.Print();
                        cout << "Type any key to continue..";
                        getchar();
			break;
                case 's':
                        myList.SelSort();
                        cout << "The List: ";
                        myList.Print();
                        cout << "\n\nType any key to continue..";
                        getchar();
                        break;
                case 'p':
                        cout << "The List: ";
                        myList.Print();
                        cout << "\n\nType any key to continue..";
                        getchar();
                        break;
                case'f':
                        cout << "Input an item to be found: ";
                        getline(cin, dummy);
			getline(cin, name);
                        if (myList.isPresent(name) )
                                cout << '"' << name  << '"' << " is in the list.\n";
                        else
                                cout << name << " is not in the list.\n";
                        cout << endl;
			cout << "\n\nType any key to continue..";
                        getchar();
                        break;
                default:
                        cout << "\nInvalid input.\n";
                        cout << "\nType any key to continue..";
        
                }
                return;
}
                                                         

Stv3n404 - 2023