Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# For this assignment, rewrite the CS8 Arrays to use a string typed Queue Download and expand the CS8 Queues Skeleton for your assignment Change

C# For this assignment, rewrite the CS8 Arrays to use a string typed Queue Download and expand the CS8 Queues Skeleton for your assignment Change the declaration of cstrName[] to Queue cstrName = new Queue( ); The variable cintNumberOfNames will not be needed because cstrName.Count can be used. In CS8Form_Load: Delete int i = 0; The if-else statement to check if the array size has been exceeded is not needed since lists can grow. Use the Enqueue method to load the names in the list, cstrName.Enqueue(nameStreamReader.ReadLine()); The names still need to be displayed in the listbox after the queue is loaded. In displayNames( ): Delete int i = 0; Use a foreach loop to reference the individual names in the queue: foreach (string strName in cstrName) { lstName.Items.Add(strName); } btnSortByName does NOT need to be implemented, because there isn't a sort method for queues. However if the student desires to implement the option consider the following: Copy the Queue into an an Array using ToArray or CopyTo. Sort the array as shown in CS Arrays Clear the existing Queue. Enqueue the items in the sorted array back into the Queue. Redisplayed after the sort and Enqueue. In btnSearchByName: Declare a varible to store the result of the search, int intIndex; The call to the sort method is not needed. Use an if statement with the Contains method to check if the name in the search box is in the queue. If Contains is true, initialize intIndex to zero and use a foreach to walk through queue, else display a message that the name is not in the list. If a match is found use intIndex to select the matching entry in listbox and display a message indicating the name was found. Be sure to increment intIndex each time through the loop. In btnDelete use the Dequeue method to delete the name at the top of the list. Before calling Dequeue, check that Count is greater than zero to avoid a run-time exception. The names have to be redisplayed after removing a name. The downloaded skeleton project includes a file with the list of names. here is the code i need to rearrange, using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; //Project: CS8 Queue Processing //Programmer: Your Name //Description: Declare and load a string Queue of names. // The user can sort the queue by name and search by name. // Names can be deleted from the top of the list. using System.IO; // FileStream and StreamReader namespace CS8 { public partial class CS8Form : Form { public CS8Form() { InitializeComponent(); } //Declare class-level Queue private void CS7Form_Load(object sender, EventArgs e) { //use a try catch to load the names from the file cs7.txt //display names in list box } void displayNames() { int i; //Listboxes need to be cleared because this procedure is also //called to redisplayed the data lstName.Items.Clear(); //Use a foreach statement to process the Queue //foreach (string strName in cstrName) //{ //lstName.Items.Add(strName); //} } private void btnSortByName_Click(object sender, EventArgs e) { txtSearchResults.Text = "Sort By Name not implemented."; /* btnSortByName does NOT need to be implemented, because there isn't a sort method for queues. However if the student desires to implement the option consider the following: Copy the Queue into an an Array using ToArray or CopyTo. Sort the array as shown in CS7 Arrays Clear the existing Queue. Enqueue the items in the sorted array back into the Queue. */ } private void btnSearchByName_Click(object sender, EventArgs e) { //delcare int variable to use as the index for the list box int intIndex; //Use an if statement with the Contains method to check if the name in the search box is in the queue //In the else display a message that the name is not in the list. //If Contains is true //Initialize intIndex to zero //Use foreach to walk through queue //Inside foreach, use an if statement to check if the item matches the name in the search box. //If a match is found use intIndex to select the matching entry in listbox and //display a message indicating the name was found. } private void btnDelete_Click(object sender, EventArgs e) { //If the Count is > 0 Dequeue the first item and redisplay names in list box } private void btnExit_Click(object sender, EventArgs e) { this.Close(); } }//end of class }//end of namespace

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions