Question
Use an array and a list (March 2015 visual basic book and visual studio) please provide all screen shots that are critical to the assignment
Use an array and a list
(March 2015 visual basic book and visual studio)
please provide all screen shots that are critical to the assignment
Perspective
In this chapter, youve learned how to use both arrays and collections for working with groups of related data. Youve also learned that the .NET Framework provides typed classes that offer useful properties and methods for working with collections. These include the List(), SortedList(), Queue(), and Stack() classes.
As you develop your own applications, you often need to decide between the use of an array or collection. Then, if you decide to use a collection, you need to choose the most appropriate type of collection. If you make the right decisions, your code will be easier to write, debug, and maintain.
Terms
array one-dimensional array element upper bound length size index For Each statement For Each loop rectangular array two-dimensional array jagged array array of arrays null-conditional operator collection
Exercise 8-1
typed collection generics untyped collection list
collection initializer sorted list key/value pair queue
stack first-in, first-out (FIFO) last-in, first-out (LIFO) array list boxing unboxing
Use an array and a list
This exercise will guide you through the process of adding an array and a list to the Invoice Total application that you saw in chapter 5.
Open the Invoice Total application
1. Open the application thats in the C:\VB 2015\Chapter 08\InvoiceTotal directory.
Use an array to store invoice totals
2. Declare two module-level variables: (1) an array that can hold up to five invoice totals and (2) an index that you can use to work with that array.
3. Add code that adds the invoice total to the next element in the array each time the user clicks the Calculate button.
Test the program by entering three invoices and then clicking the Exit button. This should display a dialog box like the one that follows. But note that the fourth and fifth elements in the array are also displayed because they were initialized with zero values.
6. Fix this problem by adding an If statement to the For Each loop that ignores any array elements that are equal to zero. Then, test the program to make sure that it works.
7. Test the program by entering more than five invoices. When you do, an IndexOutOfRangeException should be thrown.
Sort the invoice totals
8. Add code to sort the invoice totals in the array.
9. Test the program again to be sure that the message box displays the invoice totals in the correct sequence.
Modify the program so it uses a list
10. Without changing any of the current code, add code that uses the List() class to hold the invoice totals. Then, when the user clicks the Exit button, sort the list elements and add a second For Each loop to format and display the totals stored in the list in a second message box. In other words, display two message boxes: one for the array and one for the list.
11. When youve got this working right, close the solution.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started