From abe9b46ef1515a3ec9e3e9be2a706cca55a774aa Mon Sep 17 00:00:00 2001 From: Fred3267 <231194fck@gmail.com> Date: Sat, 24 Sep 2016 15:20:03 -0600 Subject: [PATCH 1/6] Alternative complete program This is doing exactly the same, but with a method taking care of the sub menu. Please let me know if there is anything I can improve. --- Program.cs | 427 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 311 insertions(+), 116 deletions(-) diff --git a/Program.cs b/Program.cs index d565f4d..2f97c66 100644 --- a/Program.cs +++ b/Program.cs @@ -1,93 +1,122 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConsoleApplication2 +namespace Group_Data_Structure { class Program { - static void Main(string[] args) + public static int subMenu(int mainMenuPick) { - //declare varibles - Boolean again; - Boolean again2 = true; - int iNum; - string sNum; - Stack staSta = new Stack(); - Stack staSta2 = new Stack(); - - //Loop until user wants to exit - while (again2 == true) - { - Console.WriteLine("Enter your Option\n"); - Console.WriteLine("1. Stack"); - Console.WriteLine("2. Queue"); - Console.WriteLine("3. Dictionary"); - Console.WriteLine("4. Exit\n"); - - sNum = Console.ReadLine(); + int iMenu; + bool bFirstTime = true; + string sMainMenu = ""; + string sSubMenuPick; - /*while (Int32.TryParse(sNum, out iNum) == true && Int32.Parse(sNum) <= 4 && Int32.Parse(sNum) >= 1) + if (mainMenuPick == 1) + { + sMainMenu = "Stack"; + } + else if (mainMenuPick == 2) + { + sMainMenu = "Queue"; + } + else if (mainMenuPick == 3) + { + sMainMenu = "Dictionary"; + } + do //this loop will make sure that the user inputs a number between (and including) 1 and 7. + { + do //this loop will make sure that the user is actually inputting an int. { - Console.WriteLine("Error. Please enter a Number 1-4"); - sNum = Console.ReadLine(); - }*/ - - iNum = Int32.Parse(sNum); + if (bFirstTime == false) //this will execute if the user fails to enter a valid entry the first time. + { + Console.WriteLine("Please Enter a number between 1-7"); //instructional error message. + } //this is the menu. + Console.WriteLine("Enter your Options\n"); + Console.WriteLine("1. Add one item to " + sMainMenu); + Console.WriteLine("2. Add Huge List of Items to " + sMainMenu); + Console.WriteLine("3. Display " + sMainMenu); + Console.WriteLine("4. Delete from " + sMainMenu); + Console.WriteLine("5. Clear " + sMainMenu); + Console.WriteLine("6. Search " + sMainMenu); + Console.WriteLine("7. Return to Main Menu"); + sSubMenuPick = Console.ReadLine(); //here's where the user inputs option + bFirstTime = false; //this changes the bool to false so that if the loop happens, it will give the error message. + } while (Int32.TryParse(sSubMenuPick, out iMenu) == false); + iMenu = Convert.ToInt32(sSubMenuPick); //this will convert the input to an int. + } while (iMenu < 1 || iMenu > 7); + return iMenu; + } + static void Main(string[] args) + { + Stack staSta = new Stack(); + Queue qItems = new Queue(); + Dictionary dictDictionary = new Dictionary(); + System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();//creates stopwatch item to time the search. - //for stack - if (iNum == 1) + bool bFirstTime = true; //this boolean will help facilitate giving an error message if the user inputs an invalid option + int iGenMenu; + string sGenMenu; + do + { + bFirstTime = true; + do { - //loop until the user wants to exit - while (again = true) + do { - Console.WriteLine("Enter your Option\n"); - Console.WriteLine("1. Add one time to Stack"); - Console.WriteLine("2. Add a Huge List of Items to Stack"); - Console.WriteLine("3. Display Stack"); - Console.WriteLine("4. Delete from Stack"); - Console.WriteLine("5. Clear Stack"); - Console.WriteLine("6. Search Stack"); - Console.WriteLine("7. Return to Main Menu\n"); - - sNum = Console.ReadLine(); - - /*while (Int32.TryParse(sNum, out iNum) == true && Int32.Parse(sNum) <= 7 && Int32.Parse(sNum) >= 1) + if (bFirstTime == false) { - Console.WriteLine("Error. Please enter a Number 1-7"); - sNum = Console.ReadLine(); - }*/ + Console.WriteLine("Please Enter a number between 1-4"); + } + Console.WriteLine("Enter your Options\n"); + Console.WriteLine("1. Stack"); + Console.WriteLine("2. Queue"); + Console.WriteLine("3. Dictionary"); + Console.WriteLine("4. Exit\n"); + sGenMenu = Console.ReadLine(); + bFirstTime = false; + } while (Int32.TryParse(sGenMenu, out iGenMenu) == false); + iGenMenu = Convert.ToInt32(sGenMenu); + } while (iGenMenu < 1 || iGenMenu > 4); + bFirstTime = true; + if (iGenMenu == 1) + { + int iStaMenu; + string sStaMenu; + int iStaValue; + string sStaValue; + string sStaKey; - again = true; - iNum = Int32.Parse(sNum); + do + { + bFirstTime = true; + iStaMenu = subMenu(iGenMenu); - //for add - if (iNum == 1) + if (iStaMenu == 1) { Console.WriteLine("What do you want to add?\n"); staSta.Push(Console.ReadLine()); Console.WriteLine("Added Successful\n"); } - //to add 2000 entries - else if (iNum == 2) + else if (iStaMenu == 2) { staSta.Clear(); int counter = 1; - while (counter<= 2000) + while (staSta.Count() <= 2000) { staSta.Push("New Entry" + counter); counter++; } - + Console.WriteLine("Stack cleared\n"); } - - //display all items - else if (iNum == 3) + + else if (iStaMenu == 3) { foreach (string item in staSta) { @@ -97,72 +126,45 @@ static void Main(string[] args) Console.WriteLine("\n"); } - //delete a specific item - else if (iNum == 4) + else if (iStaMenu == 4) { - - - Console.WriteLine("What do you want to Delete?"); - sNum = Console.ReadLine(); - - if (staSta.Contains(sNum)) + foreach (string item in staSta) { - foreach (string item in staSta) - { + Console.WriteLine("What do you want to Delete?"); + sStaValue = Console.ReadLine(); - if (staSta.Peek() != sNum) - { - //holds items that user does not want to delte - staSta2.Push(staSta.Pop()); - } - - else - { - //deletes the item - staSta.Pop(); - Console.WriteLine("Item Deleted"); - - } + if (staSta.Peek().Equals(sStaValue)) + { + staSta.Pop(); + Console.WriteLine("Item Deleted"); } - - int iCounter = staSta2.Count(); - - //gives the item back to the orginal stack - for (int iCount = 0; iCount < iCounter; iCount++) + else { - staSta.Push(staSta2.Pop()); + Console.WriteLine("Item not found"); } } - - else - { - Console.WriteLine("Item Not Found"); - } } - - - //clears stack - else if (iNum == 5) + + else if (iStaMenu == 5) { staSta.Clear(); - Console.WriteLine("Stack cleared\n"); } - - //searchs stack - else if (iNum == 6) + + else if (iStaMenu == 6) { - System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); + foreach (string item in staSta) + { Console.WriteLine("What do you want to search for?"); - sNum = Console.ReadLine(); + sStaValue = Console.ReadLine(); sw.Start(); - if (staSta.Contains(sNum)) + if (staSta.Peek().Equals(sStaValue)) { sw.Stop(); Console.WriteLine("Found It! Time to find: " + sw.Elapsed); - sw.Reset(); + sw.Stop(); } else @@ -170,27 +172,220 @@ static void Main(string[] args) Console.WriteLine("Not found"); sw.Reset(); } + + + } } - else + } while (iStaMenu != 7); + } + else if (iGenMenu == 2) + { + int iQMenu; + string sQMenu; + int iQValue; + string sQValue; + string sQKey; + + do + { + bFirstTime = true; + iQMenu = subMenu(iGenMenu); + if (iQMenu == 1) { - again = false; + Console.WriteLine("Please enter a string"); + qItems.Enqueue(Console.ReadLine()); //Add item to the queue } - } - } - else if (iNum == 2) - { } - else if (iNum == 3) - { } + else if (iQMenu == 2) + { + qItems.Clear(); //Clear the queue + int counter = 1; + while (qItems.Count() <= 2000) + { + qItems.Enqueue("New Entry" + counter); //Add item to the queue + counter++; //count how many entries have been made + } + } - else - { - again2 = false; + else if (iQMenu == 3) + { + //Display all items + foreach (string item in qItems) + { + Console.WriteLine(item); + } + } + + else if (iQMenu == 4) + { + string input = ""; + Console.Write("Which item do you want to delete?"); + input = Console.ReadLine(); + + } + + else if (iQMenu == 5) + { + //Clear the queue + qItems.Clear(); + Console.WriteLine("All items removed"); + } + + else if (iQMenu == 6) + { + string input = ""; + Console.Write("Enter Search field: "); + input = Console.ReadLine(); + //Start the timer + sw.Start(); + if (qItems.Contains(input)) + { + //Stop the timer + sw.Stop(); + Console.WriteLine("Found It! Time to find: " + sw.Elapsed); + //Reset the timer + sw.Reset(); + } + else + { + Console.WriteLine("Not found"); + sw.Reset(); + } + } + + } while (iQMenu != 7); } + else if (iGenMenu == 3) + { + int iDictMenu; + string sDictMenu; + int iDictValue; + string sDictValue; + string sDictKey; - } + do //this do loop will make sure that the dictionary code is run until the user chooses to exit + { + bFirstTime = true; + iDictMenu = subMenu(iGenMenu); + Console.WriteLine(); + Console.WriteLine();//two blank lines. + + + + + + + + + if (iDictMenu == 1) //option 1 is selected: Adding one item to dictionary. + { + Console.Write("Add one item to Dictionary \nPlease input the key: "); + sDictKey = Console.ReadLine(); //this will become the dictionary key + Console.Write("Please input the value: "); + do //this loop will make sure that the user has input an integer before it will exit the loop. + { + sDictValue = Console.ReadLine(); + if (Int32.TryParse(sDictValue, out iDictValue) == false) //this if statement will display an error message if user input a non-int + { + Console.WriteLine("Please enter a valid number."); + } + } while (Int32.TryParse(sDictValue, out iDictValue) == false); + iDictValue = Convert.ToInt32(sDictValue); //converts from string to integer for dictionary value. + dictDictionary.Add(sDictKey, iDictValue); //add the item to the dictionary using the two obtained value + Console.WriteLine("Item successfully added!"); + } + + + else if (iDictMenu == 2) //option 2: add huge list of items to the dictionary. + { + dictDictionary.Clear(); //clears the current dictionary. + int i = 1; + while (i <= 2000) //this count will create 2000 items in the form of "New Entry 1, New Entry 2,..." + { + sDictKey = "New Entry " + i; + dictDictionary.Add(sDictKey, i); + i++; + } + Console.WriteLine("2000 new entries successfully added!"); //confirmation to the user. + } + + + + else if (iDictMenu == 3) //option 3: displaying the items currently in the dictionary. + { + + if (!dictDictionary.Count.Equals(0)) + { + string k = "Key"; //this will help facilitate header padding. + string dashes = "--------"; + Console.WriteLine(k.PadRight(25, ' ') + "Value\n" + dashes.PadRight(25, ' ') + "-----"); //this is the header + + foreach (var input in dictDictionary)//for each item in the dictionary we will print out what is in there + { + Console.WriteLine(input.Key.PadRight(25, ' ') + input.Value); + } + Console.WriteLine("\nPrint Complete!"); //confirmation to the user. + } + else + { + Console.WriteLine("* Your dictionary is currently empty *"); //this line will tell the user that the dictionary is empty + } + + + + } + + else if (iDictMenu == 4) //option 4: Delete from Dictionary + { + Console.Write("What do you want to delete: ");//prompt the user to enter then key name of the item they want to delete. + string sDictSearch = Console.ReadLine(); //stores string value the user enters. + if (dictDictionary.ContainsKey(sDictSearch) == true) //this will execute if the dictionary contains the user value. + { + dictDictionary.Remove(sDictSearch);//will remove the item. + Console.WriteLine("\nRecord for " + sDictSearch + " successfully removed."); //confirmation to the user. + } + else if (dictDictionary.ContainsKey(sDictSearch) == false) //this is what executes if no match is found + { + Console.WriteLine("The requested key does not exist!"); //message to user. + } + } + + else if (iDictMenu == 5) //option 5: clear all items from the dictionar + { + dictDictionary.Clear(); //this line clears the dictionary. + Console.WriteLine("Dictionary successfully cleared!"); //confirmation to user. + } + + else if (iDictMenu == 6) //option 6: search the dictionary + { + Console.Write("What are you searching for: "); //user prompt + + string sDictSearch = Console.ReadLine();//this will store the string the user inputs. + sw.Start(); //this starts the stopwatch to time the search. + if (dictDictionary.ContainsKey(sDictSearch) == true) //this is if the the value is found. + { + sw.Stop(); + + Console.WriteLine("\nItem found\n----------"); //information to the user + Console.WriteLine(sDictSearch.PadRight(25, ' ') + dictDictionary[sDictSearch]); //display the found item + Console.WriteLine("Time to find: " + sw.Elapsed); //display the time it took to find + + sw.Reset();//reset the stopwatch + } + else + { + Console.WriteLine("No results found."); //this informs the user that nothing was found + sw.Stop();//stops the stopwatch + sw.Reset();//resets the stopwatch + } + + } + + } while (iDictMenu != 7); //this line will exit that menu once 7 is selected. + + } + } while (iGenMenu != 4); } } } - From 0f2d25ece24557755349c7b6ca799970280ea083 Mon Sep 17 00:00:00 2001 From: nshawcroft Date: Sun, 25 Sep 2016 20:25:26 -0600 Subject: [PATCH 2/6] Fixed the queue's huge list --- Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 2f97c66..d711fa5 100644 --- a/Program.cs +++ b/Program.cs @@ -201,7 +201,7 @@ static void Main(string[] args) { qItems.Clear(); //Clear the queue int counter = 1; - while (qItems.Count() <= 2000) + while (qItems.Count() < 2000) { qItems.Enqueue("New Entry" + counter); //Add item to the queue counter++; //count how many entries have been made From 3d4029875d91e89dcef6cdd02ff8e4cdb407f6d7 Mon Sep 17 00:00:00 2001 From: nshawcroft Date: Sun, 25 Sep 2016 21:08:45 -0600 Subject: [PATCH 3/6] Got the queue's delete item done --- Program.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index d711fa5..239e208 100644 --- a/Program.cs +++ b/Program.cs @@ -222,7 +222,31 @@ static void Main(string[] args) string input = ""; Console.Write("Which item do you want to delete?"); input = Console.ReadLine(); - + Queue tempQueue = new Queue(); //Temporary queue to move non-deleted items to + if (qItems.Contains(input)) + { + while (qItems.Count > 0) + { + string currentItem = qItems.Dequeue().ToString(); //Remove and look at the first item in the queue + if (currentItem != input) + { + tempQueue.Enqueue(currentItem); //Don't delete it, add to the temporary queue + } + else + { + //Do nothing, this is the one to delete + } + } + while (tempQueue.Count > 0) + { + qItems.Enqueue(tempQueue.Dequeue()); //Add back the items in the temporary queue to the original queue + } + Console.WriteLine("Item Deleted!"); + } + else + { + Console.WriteLine("Item not found"); //Report that the item to delete isn't in the queue + } } else if (iQMenu == 5) From 108edf02e7714f35afdfa9292fc82cb0a4a419c6 Mon Sep 17 00:00:00 2001 From: batchelb Date: Mon, 26 Sep 2016 10:04:25 -0600 Subject: [PATCH 4/6] Add files via upload --- Program.cs | 85 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/Program.cs b/Program.cs index 239e208..c5d3b2e 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -95,6 +95,7 @@ static void Main(string[] args) bFirstTime = true; iStaMenu = subMenu(iGenMenu); + //adds item to stack if (iStaMenu == 1) { Console.WriteLine("What do you want to add?\n"); @@ -102,20 +103,25 @@ static void Main(string[] args) Console.WriteLine("Added Successful\n"); } + //add 2000 entries to the stack else if (iStaMenu == 2) { staSta.Clear(); int counter = 1; - while (staSta.Count() <= 2000) + Console.WriteLine("Stack cleared\n"); + + while (staSta.Count() < 2000) { staSta.Push("New Entry" + counter); counter++; } - Console.WriteLine("Stack cleared\n"); + Console.WriteLine("2000 new entries have been added"); + } + //displays the stack else if (iStaMenu == 3) { foreach (string item in staSta) @@ -126,54 +132,66 @@ static void Main(string[] args) Console.WriteLine("\n"); } + ///Delete specific item from stack else if (iStaMenu == 4) { - foreach (string item in staSta) + string input; + Console.Write("Which item do you want to delete?\n"); + input = Console.ReadLine(); + Stack tempStack = new Stack(); //Temporary stack to move non-deleted items to + if (staSta.Contains(input)) { - Console.WriteLine("What do you want to Delete?"); - sStaValue = Console.ReadLine(); - - if (staSta.Peek().Equals(sStaValue)) + while (staSta.Count > 0) { - staSta.Pop(); - Console.WriteLine("Item Deleted"); + string currentItem = staSta.Pop().ToString(); //Remove and look at the first item in the stack + if (currentItem != input) + { + tempStack.Push(currentItem); //Don't delete it, add to the temporary stack + } + else + { + //Do nothing, this is the one to delete + } } - - else + while (tempStack.Count > 0) { - Console.WriteLine("Item not found"); + staSta.Push(tempStack.Pop()); //Add back the items in the temporary stack to the original queue } + Console.WriteLine("Item Deleted!"); + } + else + { + Console.WriteLine("Item not found"); //Report that the item to delete isn't in the stack } } + //clears stack else if (iStaMenu == 5) { staSta.Clear(); } + //searchs stack for specific item else if (iStaMenu == 6) { - foreach (string item in staSta) + string input; + Console.Write("Enter Search field: "); + input = Console.ReadLine(); + //Start the timer + sw.Start(); + if (staSta.Contains(input)) { - Console.WriteLine("What do you want to search for?"); - sStaValue = Console.ReadLine(); - - sw.Start(); - if (staSta.Peek().Equals(sStaValue)) - { - sw.Stop(); - Console.WriteLine("Found It! Time to find: " + sw.Elapsed); - sw.Stop(); - } - - else - { - Console.WriteLine("Not found"); - sw.Reset(); - } - - + //Stop the timer + sw.Stop(); + Console.WriteLine("Found It! Time to find: " + sw.Elapsed); + //Reset the timer + sw.Reset(); + } + else + { + Console.WriteLine("Not found"); + sw.Reset(); } } @@ -232,7 +250,7 @@ static void Main(string[] args) { tempQueue.Enqueue(currentItem); //Don't delete it, add to the temporary queue } - else + else { //Do nothing, this is the one to delete } @@ -413,3 +431,4 @@ static void Main(string[] args) } } } + From 1c83309b1bed7095f000eaac4ba98c948ce25dcb Mon Sep 17 00:00:00 2001 From: Fred3267 <231194fck@gmail.com> Date: Mon, 26 Sep 2016 20:36:30 -0600 Subject: [PATCH 5/6] fix of uppercase problems I made it so that all queue and stack input start with a uppercase. Furthermore I made it an option in the dictionary, and it made it so that when you try to look up or delete a record it suggest the uppercase version if there is no lowercase version --- Program.cs | 98 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/Program.cs b/Program.cs index c5d3b2e..265765f 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,6 +8,16 @@ namespace Group_Data_Structure { class Program { + static string UppercaseFirst(string s) + { + // Check for empty string. + if (string.IsNullOrEmpty(s)) + { + return string.Empty; + } + // Return char and concat substring. + return char.ToUpper(s[0]) + s.Substring(1); + } public static int subMenu(int mainMenuPick) { int iMenu; @@ -31,6 +41,7 @@ public static int subMenu(int mainMenuPick) { do //this loop will make sure that the user is actually inputting an int. { + Console.WriteLine("\n".PadRight(50,'-') + "\n"); if (bFirstTime == false) //this will execute if the user fails to enter a valid entry the first time. { Console.WriteLine("Please Enter a number between 1-7"); //instructional error message. @@ -42,11 +53,12 @@ public static int subMenu(int mainMenuPick) Console.WriteLine("4. Delete from " + sMainMenu); Console.WriteLine("5. Clear " + sMainMenu); Console.WriteLine("6. Search " + sMainMenu); - Console.WriteLine("7. Return to Main Menu"); + Console.WriteLine("7. Return to Main Menu\n"); sSubMenuPick = Console.ReadLine(); //here's where the user inputs option bFirstTime = false; //this changes the bool to false so that if the loop happens, it will give the error message. } while (Int32.TryParse(sSubMenuPick, out iMenu) == false); iMenu = Convert.ToInt32(sSubMenuPick); //this will convert the input to an int. + Console.WriteLine("\n"); } while (iMenu < 1 || iMenu > 7); return iMenu; } @@ -85,59 +97,48 @@ static void Main(string[] args) if (iGenMenu == 1) { int iStaMenu; - string sStaMenu; - int iStaValue; string sStaValue; - string sStaKey; do { bFirstTime = true; iStaMenu = subMenu(iGenMenu); - //adds item to stack if (iStaMenu == 1) { Console.WriteLine("What do you want to add?\n"); - staSta.Push(Console.ReadLine()); - Console.WriteLine("Added Successful\n"); + + staSta.Push(UppercaseFirst(Console.ReadLine())); + Console.WriteLine("Added Successful"); } - //add 2000 entries to the stack else if (iStaMenu == 2) { staSta.Clear(); int counter = 1; - Console.WriteLine("Stack cleared\n"); - - while (staSta.Count() < 2000) + while (staSta.Count() <= 2000) { staSta.Push("New Entry" + counter); counter++; } - Console.WriteLine("2000 new entries have been added"); - + Console.WriteLine("Stack cleared"); } - //displays the stack else if (iStaMenu == 3) { foreach (string item in staSta) { Console.WriteLine(item); } - - Console.WriteLine("\n"); } - ///Delete specific item from stack else if (iStaMenu == 4) { string input; Console.Write("Which item do you want to delete?\n"); - input = Console.ReadLine(); + input = UppercaseFirst(Console.ReadLine()); Stack tempStack = new Stack(); //Temporary stack to move non-deleted items to if (staSta.Contains(input)) { @@ -165,19 +166,18 @@ static void Main(string[] args) } } - //clears stack + //clears stack else if (iStaMenu == 5) { staSta.Clear(); } - //searchs stack for specific item else if (iStaMenu == 6) { string input; Console.Write("Enter Search field: "); - input = Console.ReadLine(); + input = UppercaseFirst(Console.ReadLine()); //Start the timer sw.Start(); if (staSta.Contains(input)) @@ -200,11 +200,6 @@ static void Main(string[] args) else if (iGenMenu == 2) { int iQMenu; - string sQMenu; - int iQValue; - string sQValue; - string sQKey; - do { bFirstTime = true; @@ -212,14 +207,14 @@ static void Main(string[] args) if (iQMenu == 1) { Console.WriteLine("Please enter a string"); - qItems.Enqueue(Console.ReadLine()); //Add item to the queue + qItems.Enqueue(UppercaseFirst(Console.ReadLine())); //Add item to the queue } else if (iQMenu == 2) { qItems.Clear(); //Clear the queue int counter = 1; - while (qItems.Count() < 2000) + while (qItems.Count() <= 2000) { qItems.Enqueue("New Entry" + counter); //Add item to the queue counter++; //count how many entries have been made @@ -239,7 +234,7 @@ static void Main(string[] args) { string input = ""; Console.Write("Which item do you want to delete?"); - input = Console.ReadLine(); + input = UppercaseFirst(Console.ReadLine()); Queue tempQueue = new Queue(); //Temporary queue to move non-deleted items to if (qItems.Contains(input)) { @@ -266,7 +261,6 @@ static void Main(string[] args) Console.WriteLine("Item not found"); //Report that the item to delete isn't in the queue } } - else if (iQMenu == 5) { //Clear the queue @@ -278,7 +272,7 @@ static void Main(string[] args) { string input = ""; Console.Write("Enter Search field: "); - input = Console.ReadLine(); + input = UppercaseFirst(Console.ReadLine()); //Start the timer sw.Start(); if (qItems.Contains(input)) @@ -301,24 +295,15 @@ static void Main(string[] args) else if (iGenMenu == 3) { int iDictMenu; - string sDictMenu; int iDictValue; string sDictValue; string sDictKey; + string sYNAnswer; do //this do loop will make sure that the dictionary code is run until the user chooses to exit { bFirstTime = true; iDictMenu = subMenu(iGenMenu); - Console.WriteLine(); - Console.WriteLine();//two blank lines. - - - - - - - if (iDictMenu == 1) //option 1 is selected: Adding one item to dictionary. { @@ -334,6 +319,14 @@ static void Main(string[] args) } } while (Int32.TryParse(sDictValue, out iDictValue) == false); iDictValue = Convert.ToInt32(sDictValue); //converts from string to integer for dictionary value. + Console.Write("Do you wanna make sure the key is upper case? (Y/N): "); + sYNAnswer = Console.ReadLine(); + sYNAnswer = sYNAnswer.Substring(0, 1); + sYNAnswer = UppercaseFirst(sYNAnswer); + if (sYNAnswer == "Y") + { + sDictKey = UppercaseFirst(sDictKey); + } dictDictionary.Add(sDictKey, iDictValue); //add the item to the dictionary using the two obtained value Console.WriteLine("Item successfully added!"); } @@ -387,6 +380,19 @@ static void Main(string[] args) dictDictionary.Remove(sDictSearch);//will remove the item. Console.WriteLine("\nRecord for " + sDictSearch + " successfully removed."); //confirmation to the user. } + else if (dictDictionary.ContainsKey(UppercaseFirst(sDictSearch)) == true)// Check if the key exist with the first letter upper case + { + Console.Write("\nThe requested key does not exist, but we found this:\n\nItem found\n----------\n" + UppercaseFirst(sDictSearch).PadRight(25, ' ') + dictDictionary[UppercaseFirst(sDictSearch)]); + Console.Write("\n\nDo you wanna delete this record? (Y/N) "); + sYNAnswer = Console.ReadLine(); + sYNAnswer = sYNAnswer.Substring(0, 1); + sYNAnswer = UppercaseFirst(sYNAnswer); + if (sYNAnswer == "Y") + { + dictDictionary.Remove(UppercaseFirst(sDictSearch));//will remove the item. + Console.WriteLine("\nRecord for " + UppercaseFirst(sDictSearch) + " successfully removed."); //confirmation to the user. + } + } else if (dictDictionary.ContainsKey(sDictSearch) == false) //this is what executes if no match is found { Console.WriteLine("The requested key does not exist!"); //message to user. @@ -415,6 +421,13 @@ static void Main(string[] args) sw.Reset();//reset the stopwatch } + else if (dictDictionary.ContainsKey(UppercaseFirst(sDictSearch)) == true)// Check if the key exist with the first letter upper case + { + sw.Stop(); + + Console.Write("\nThe requested key does not exist, but we found this:\n" + "\nItem found\n----------\n" + UppercaseFirst(sDictSearch).PadRight(25, ' ') + dictDictionary[UppercaseFirst(sDictSearch)]); //display the found item with an upper case first letter + Console.WriteLine("\nTime to find: " + sw.Elapsed); //display the time it took to find + } else { Console.WriteLine("No results found."); //this informs the user that nothing was found @@ -431,4 +444,3 @@ static void Main(string[] args) } } } - From 7234c2328b86a8dcead546acf8ac3270a132f940 Mon Sep 17 00:00:00 2001 From: Kenyon2934 Date: Mon, 26 Sep 2016 20:56:08 -0600 Subject: [PATCH 6/6] Update Program.cs I just changed a couple of the text outputs. "Do you want to" instead of "do you wanna" and "Enter your selection." instead of "Enter your options" --- Program.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index 265765f..92f19a7 100644 --- a/Program.cs +++ b/Program.cs @@ -1,3 +1,4 @@ + using System; using System.Collections.Generic; using System.Linq; @@ -46,7 +47,7 @@ public static int subMenu(int mainMenuPick) { Console.WriteLine("Please Enter a number between 1-7"); //instructional error message. } //this is the menu. - Console.WriteLine("Enter your Options\n"); + Console.WriteLine("Enter your Selection\n"); Console.WriteLine("1. Add one item to " + sMainMenu); Console.WriteLine("2. Add Huge List of Items to " + sMainMenu); Console.WriteLine("3. Display " + sMainMenu); @@ -319,7 +320,7 @@ static void Main(string[] args) } } while (Int32.TryParse(sDictValue, out iDictValue) == false); iDictValue = Convert.ToInt32(sDictValue); //converts from string to integer for dictionary value. - Console.Write("Do you wanna make sure the key is upper case? (Y/N): "); + Console.Write("Do you want to make sure the key is upper case? (Y/N): "); sYNAnswer = Console.ReadLine(); sYNAnswer = sYNAnswer.Substring(0, 1); sYNAnswer = UppercaseFirst(sYNAnswer);