Exemplo n.º 1
0
        //source for above http://stackoverflow.com/questions/6397235/write-bytes-to-file

        public static void menu()
        {
            Console.WriteLine("\n\n-------DICTIONARY MENU-------");
            Console.WriteLine("1. Encrypt");

            Console.WriteLine("2. Return to Bonus Feature menu");
            Console.Write("Menu Selector: ");

            ErrorHandling check = new ErrorHandling();

            int iProtectedMenu = check.Input("Menu Selector: ", 2);

            switch (iProtectedMenu)
            {
            case 1:


                Console.WriteLine("Enter in the data that you want to save from this program...");
                //Encrypt the data.
                byte[] secret = Encoding.UTF8.GetBytes(Console.ReadLine());

                //Encrypt the data.
                byte[] encryptedSecret = Encrypt.Protect(secret);

                Console.WriteLine("The encrypted byte array is:");
                Encrypt.PrintValues(encryptedSecret);

                ByteArrayToFile("C:\\Users\\Public\\Encryption\\encryption.txt", encryptedSecret);

                Console.Write("\nData is now encrypted\n\n");

                break;

            default:
                Console.Write("\nGoodbye!");
                break;
            }
        }
Exemplo n.º 2
0
        //giving access to jPAges
        public static void accessPages()
        {
            //information regarding the queue data structures
            string queueMan =
                "This class implements a queue as a circular array. Objects stored in a Queue are inserted at one end and removed from the other." +
                "Queues and stacks are useful when you need temporary storage for information; " +
                "that is, when you might want to discard an element after retrieving its value. " +
                "Use Queue if you need to access the information in the same order that it is stored in the collection. " +
                "Use Stack if you need to access the information in reverse order. Use ConcurrentQueue<T> or ConcurrentStack<T> " +
                "if you need to access the collection from multiple threads concurrently." +
                "Three main operations can be performed on a Queue and its elements:" +
                "Enqueue adds an element to the end of the Queue." +
                "Dequeue removes the oldest element from the start of the Queue." +
                "Peek returns the oldest element that is at the start of the Queue but does not remove it from the Queue." +
                "The capacity of a Queue is the number of elements the Queue can hold. As " +
                "elements are added to a Queue, the capacity is automatically " +
                "increased as required through reallocation. The capacity can be decreased by calling TrimToSize." +
                "The growth factor is the number by which the current capacity is multiplied" +
                " when a greater capacity is required. The growth factor is d" +
                "etermined when the Queue is constructed. The default growth factor is 2.0. " +
                "The capacity of the Queue will always increase by at least a minimum of four, " +
                "regardless of the growth factor. For example, a Queue with a growth factor of 1.0 will" +
                "always increase in capacity by four when a greater capacity is required." +
                "Queue accepts null as a valid value and allows duplicate elements.";

            //information regarding the stack
            string stackMan =
                "For the generic version of this collection, see System.Collections.Generic.Stack<T>." +
                "The capacity of a Stack is the number of elements the Stack can hold. As elements are added to a Stack, " +
                "the capacity is automatically increased as required through reallocation." +
                "If Count is less than the capacity of the stack, Push is an O(1) operation. If the capacity needs to be" +
                "increased to accommodate the new element, Push becomes an O(n) operation, where n is Count. " +
                "Pop is an O(1) operation." +
                "Stack accepts null as a valid value and allows duplicate elements.";

            //information the dictionary
            string dictionaryMan =
                "The Dictionary<TKey, TValue> generic class provides a mapping from a set of" +
                "keys to a set of values. Each addition to the dictionary consists of a value " +
                "and its associated key. Retrieving a value by using its key is very fast, " +
                "close to O(1), because the Dictionary<TKey, TValue> class is implemented as a hash table." +
                "System_CAPS_noteNote" +
                "The speed of retrieval depends on the quality of the hashing algorithm of the type specified for TKey." +
                "As long as an object is used as a key in the Dictionary<TKey, TValue>, it must not change in " +
                "any way that affects its hash value. Every key in a Dictionary<TKey, TValue> must be " +
                "unique according to the dictionary's equality comparer. A key cannot be null, but " +
                "a value can be, if the value type TValue is a reference type." +
                "Dictionary<TKey, TValue> requires an equality implementation to determine whether keys are equal. " +
                " You can specify an implementation of the IEqualityComparer<T> generic interface by using a " +
                "  constructor that accepts a comparer parameter; if you do not specify an implementation, " +
                "the default generic equality comparer EqualityComparer<T>.Default is used. If type " +
                " TKey implements the System.IEquatable<T> generic interface, the default equality comparer uses that implementation." +
                "System_CAPS_noteNote" +
                "For example, you can use the case-insensitive string comparers provided by the StringComparer" +
                "  class to create dictionaries with case-insensitive string keys." +
                "The capacity of a Dictionary<TKey, TValue> is the number of elements the Dictionary<TKey," +
                " TValue> can hold. As elements are added to a Dictionary<TKey, TValue>, the capacity" +
                "  is automatically increased as required by reallocating the internal array." +
                "For very large Dictionary<TKey, TValue> objects, you can increase the maximum capacity to 2" +
                "  billion elements on a 64-bit system by setting the enabled attribute of the " +
                "   configuration element to true in the run-time environment." +
                "For purposes of enumeration, each item in the dictionary is treated as a KeyValuePair<TKey," +
                " TValue> structure representing a value and its key. The order in which the items are " +
                "  returned is undefined." +
                "The foreach statement of the C# language (for each in C++, For Each in Visual Basic) returns" +
                " an object of the type of the elements in the collection. Since the Dictionary<TKey, TValue> " +
                " is a collection of keys and values, the element type is not the type of the key or" +
                "the type of the value. Instead, the element type is a KeyValuePair<TKey, TValue> of " +
                " the key type and the value type.";


            //giving the menu
            Console.Write("\n");
            Console.WriteLine("-------MAN PAGES MENU-------");
            Console.WriteLine("1.    Stack Page");
            Console.WriteLine("2.    Queue Page");
            Console.WriteLine("3.    Dictionary Page");
            Console.WriteLine("4.    Return to Bonus Features");
            Console.WriteLine("-------All info can be found on Microsoft's website------");
            Console.Write("Menu Selector: ");

            ErrorHandling check = new ErrorHandling();

            int iManMenu = check.Input("Menu Selector: ", 4);


            //all of the different optionns they can choose from
            switch (iManMenu)
            {
            case 1:
                Console.WriteLine(stackMan);
                break;

            case 2:
                Console.WriteLine(queueMan);
                break;

            case 3:
                Console.WriteLine(dictionaryMan);
                break;

            case 4:
                break;
            }

            Console.WriteLine("\n\n");
        }
Exemplo n.º 3
0
        static public int dataMenu(string choice)
        {
            int iMainMenu;


            bool bMainMenu = true;

            while (bMainMenu)
            {
                //Test change
                Console.Write("\n");
                Console.WriteLine("-------MENU-------");
                Console.WriteLine("1.    Stack");
                Console.WriteLine("2.    Queue");
                Console.WriteLine("3.    Dictionary");
                Console.WriteLine("4.    Return to Bonus Features");
                Console.Write("Menu Selector: ");

                ErrorHandling check = new ErrorHandling();

                iMainMenu = check.Input("Menu Selector: ", 4);

                switch (iMainMenu)
                //goign through eachd of the case scenarios that we need to check
                {
                case 1:
                    manageStack.menuDisplay();

                    ErrorHandling checking = new ErrorHandling();

                    //checcking the information

                    int iStackMenu = checking.Input("Menu Selector: ", 7);

                    switch (iStackMenu)
                    {
                    case 1:
                        manageStack.addOne();
                        break;

                    case 2:
                        manageStack.addList();
                        break;

                    case 3:
                        manageStack.display();
                        break;



                    case 4:
                        manageStack.delete();
                        break;

                    case 5:
                        manageStack.clear();
                        break;

                    case 6:
                        manageStack.search();
                        break;

                    case 7:

                        Console.WriteLine("\n");
                        break;

                    default:
                        Console.WriteLine("Please enter a valid menu option");
                        break;
                    }
                    break;

                case 2:
                    Queue.menu();

                    break;

                case 3:
                    Dictionary.menu();
                    break;

                case 4:
                    return(0);

                    break;

                default:
                    Console.Write("Please enter a valid menu option");
                    break;
                }



                //end of second while
            } // end of while
            Console.ReadLine();
            return(0);
        } // end of dataStrucures
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            /*typerWriter("Welcome to this program. We are excited to have you join us today!");
             * typerWriter("We like to get to know our customers. What is your perferred name?");
             * Console.Write("\nEnter name: ");
             * string name = Console.ReadLine();
             * typerWriter("\nGlad to have you join us " + name + ". We have a couple of options for you today.\n");*/

            //random number to enter loop
            while (true)
            {
                Console.WriteLine("-------ABOVE AND BEYOND-------");
                Console.WriteLine("1.    Get Guided Tour");
                Console.WriteLine("2.    View Man Pages");
                Console.WriteLine("3.    Save Data");
                Console.WriteLine("4.    Data Structures");
                Console.WriteLine("5.    Exit");

                Console.Write("Menu Selector: ");

                ErrorHandling check = new ErrorHandling();

                int orginalInput = check.Input("Menu Selector: ", 5);


                switch (orginalInput)
                {
                case 1:
                    Console.WriteLine("\n\n");
                    GuidedTour.guide();
                    break;

                case 2:
                    ManPages.accessPages();
                    break;

                case 3:

                    ProtectedMenu.menu();

                    break;

                case 4:
                    dataMenu("normal");
                    break;

                case 5:
                    System.Environment.Exit(1);
                    break;

                default:

                    break;
                }
            }



            // var goOnce = dataMenu("watch");
            Console.ReadKey();
        } //end of main
Exemplo n.º 5
0
        static public int menu()
        {
            Queue <string> myQueue = new Queue <string>();

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();



            int iSelect = 3; //random number to get in the while loop

            while (iSelect != 7)
            {
                displayMenu();

                ErrorHandling check = new ErrorHandling();

                iSelect = check.Input("Menu Selector: ", 7);

                #region addOne
                if (iSelect == 1)
                {
                    Console.Write("\nEnter a string: ");
                    string sEntry;
                    try
                    {
                        sEntry = Console.ReadLine();
                        if (sEntry != "")
                        {
                            myQueue.Enqueue(sEntry);
                            //Display status
                            Console.WriteLine("\n\"" + myQueue.Peek() + "\" has been added to stack.");
                        }
                        else
                        {
                            throw new InvalidOperationException("No input detected");
                        }
                    }
                    catch
                    {
                        Console.WriteLine("\nERROR: No input or invalid input detected. Please enter valid input.");
                    }
                }
                #endregion

                #region addList
                else if (iSelect == 2)
                {
                    //Cycle through and input 2000 new entries
                    myQueue.Clear();
                    for (int iCount = 1; iCount <= 2000; iCount++)
                    {
                        myQueue.Enqueue("New Entry " + iCount);
                    }
                }
                #endregion

                #region Display
                else if (iSelect == 3)
                {
                    foreach (String s in myQueue)
                    {
                        Console.WriteLine(s);
                    }
                }
                #endregion

                #region Delete
                else if (iSelect == 4)
                {
                    int iDelete = 0;

                    Console.WriteLine("\nWhich entry do you want to delete?");
                    try
                    {
                        iDelete = Convert.ToInt32(Console.ReadLine());
                    }
                    //Catch invalid inputs
                    catch
                    {
                        Console.WriteLine("\nERROR: Selection invalid or does not exist. Please input valid selection.");
                    }

                    //find and delete selected entry
                    int            iNum     = myQueue.Count;
                    Queue <string> myQueue2 = new Queue <string>();
                    for (int iCount2 = 0; iCount2 < iNum; iCount2++)
                    {
                        if (iCount2 == iDelete - 1)
                        {
                            myQueue.Dequeue();
                        }
                        else
                        {
                            myQueue2.Enqueue(myQueue.Dequeue());
                        }
                    }
                    myQueue = myQueue2; //restore queue without condemned entry
                }
                #endregion

                else if (iSelect == 5)
                {
                    myQueue.Clear();
                    Console.WriteLine("\nQueue has been cleared");
                }
                else if (iSelect == 6)
                {
                    Console.WriteLine("\nWhat entry do you want to search for?");
                    string sSearch = Console.ReadLine();
                    stopwatch.Start();

                    /*for (int iCount2 = 0; iCount2 < iSearch; iCount2++)
                     * {
                     *  myQueue.Peek();
                     *  if (iCount2 == iSearch)
                     *  {
                     *      Console.WriteLine(myQueue.Peek());
                     *  }
                     * }
                     * */

                    if (myQueue.Contains(sSearch))
                    {
                        Console.WriteLine("\nItem found!");
                        stopwatch.Stop();
                        Console.WriteLine("\nTime elapsed: {0}", stopwatch.Elapsed);
                    }
                    else
                    {
                        Console.WriteLine("\nItem not found.");
                        stopwatch.Stop();
                        Console.WriteLine("\nTime elapsed: {0}", stopwatch.Elapsed);
                    }
                }
                else if (iSelect == 7)
                {
                    return(0);
                }//Return to main Menu
            }

            return(0);
        }
        static public int menu()
        {
            int iDictionaryMenu = 0;
            Dictionary <string, int> myDictionary = new Dictionary <string, int>();

            while (iDictionaryMenu != 7)
            {
                //////////ENTER CODE FOR A MENU OF A DICTIONARY
                Console.WriteLine("\n\n-------DICTIONARY MENU-------");
                Console.WriteLine("1. Add one time to Dictionary");
                Console.WriteLine("2. Add Huge List of Items to Dictionary");
                Console.WriteLine("3. Display Dictionary");
                Console.WriteLine("4. Delete from Dictionary");
                Console.WriteLine("5. Clear Dictionary");
                Console.WriteLine("6. Search Dictionary");
                Console.WriteLine("7. Return to Main Menu");
                Console.Write("Menu Selector: ");
                ErrorHandling check = new ErrorHandling();

                iDictionaryMenu = check.Input("Menu Selector: ", 7);



                string sDictionaryString;
                int    iDictionaryCount;



                #region addOne
                if (iDictionaryMenu == 1)
                {
                    try
                    {
                        //ManageDictionary.addOne
                        //Add one string to the dicitonary
                        Console.Write("\nEnter a string into the data structure: ");
                        sDictionaryString = Console.ReadLine();
                        if (sDictionaryString != "")
                        {
                            myDictionary.Add(sDictionaryString, myDictionary.Count + 1);
                        }
                        else
                        {
                            throw new InvalidOperationException("No input detected");
                        }
                    }
                    catch
                    {
                        Console.WriteLine("\nERROR: No input or invalid input detected. Please enter valid input.");
                    }
                    #endregion

                    #region addList
                }//Dictionary Menu 1 One
                else if (iDictionaryMenu == 2)
                {
                    //ManageDictionary.AddList
                    myDictionary.Clear();
                    for (iDictionaryCount = 1; iDictionaryCount <= 2000; iDictionaryCount++)
                    {
                        myDictionary.Add("New entry " + (iDictionaryCount), iDictionaryCount);
                    }
                }//DictionaryMenu 2 list
                #endregion

                #region display

                else if (iDictionaryMenu == 3)
                {
                    //ManageDictionary.Display
                    foreach (KeyValuePair <string, int> s in myDictionary)
                    {
                        Console.WriteLine(s.Key + " ");
                        //Console.WriteLine(s.Value);
                    }
                }//Dictionary Menu 3 Display

                #endregion



                else if (iDictionaryMenu == 4)
                {
                    //ManageDictionary.Delete
                    Console.WriteLine("\nWhat entry would you like to delete? ");
                    string sInput = Console.ReadLine();

                    if (myDictionary.ContainsKey(sInput))
                    {
                        myDictionary.Remove(sInput);
                    }//Delete Dictionary
                    else
                    {
                        Console.WriteLine("\nThe entry you would like to remove was not found. Please enter a valid entry.");
                    }
                }//Dictionary menu 4


                else if (iDictionaryMenu == 5)
                {
                    //ManageDictionary.Clear
                    myDictionary.Clear();
                }//Clear Dictionary Menu 5


                else if (iDictionaryMenu == 6)
                {
                    //ManageDictionary.Search

                    Console.WriteLine("\nEnter an item you would like to search for:\n");
                    string sSearchEntry = Console.ReadLine();

                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

                    sw.Start();

                    if (myDictionary.ContainsKey(sSearchEntry))
                    {
                        Console.WriteLine("\nValue for " + sSearchEntry + " is " + myDictionary[sSearchEntry]);
                        sw.Stop();
                    }
                    else
                    {
                        Console.WriteLine("\nItem not found.");
                    }

                    sw.Stop();
                    Console.WriteLine("\nTime elapsed: " + sw.Elapsed);
                }//Search Dictionary Menu 6


                else if (iDictionaryMenu == 7)
                {
                    //ManageDictionary.Return
                    Console.WriteLine("\n");
                    return(0);
                } //Return to main Menu
            }     //end of while loop

            return(0);
        }//end of menu