Write a C application to do the following First create an ar

Write a C# application to do the following.

     First, create an array of Invoice objects with the following data:

     [Please see next page]

    

Part number

Part description

Quantity

Price

83

Electric sander

7

57.98

24

Power saw

18

99.99

7

Sledge hammer

11

21.50

77

Hammer

76

11.99

39

Lawn mower

3

79.50

68

Screwdriver

106

6.99

56

Jig saw

21

11.00

3

Wrench

34

7.50

     Then perform the following queries on the array of Invoice objects and display the results:

     (a) Use LINQ to sort the Invoice objects by PartDescription.

     (b) Use LINQ to sort the Invoice objects by UnitPrice.

     (c) Use LINQ to select the PartDescription and Quantity and sort the results by Quantity.

     (d) Use LINQ to select from each invoice the PartDescription and the invoice total amount. The GetInvoiceAmount method returns the total amount of the invoice. Order the results by invoice total amount. [Hint: Use let in the LINQ query to store invoice total amount in a new variable. See the example in textbook Figure 9.7]

     (e) Using the results of the LINQ query in part (d), select invoices with total amount in the range $200 to $500.

     The output of the program should look like the following:

Invoices sorted by part description

83        Electric sander     7             $57.98

77        Hammer              76            $11.99

56        Jig saw             21            $11.00

39        Lawn mower          3             $79.50

24        Power saw           18            $99.99

68        Screwdriver         106            $6.99

7         Sledge hammer       11            $21.50

3         Wrench              34             $7.50

Invoices sorted by unit price

68        Screwdriver         106            $6.99

3         Wrench              34             $7.50

56        Jig saw             21            $11.00

77        Hammer              76            $11.99

7         Sledge hammer       11            $21.50

83        Electric sander     7             $57.98

39        Lawn mower          3             $79.50

24        Power saw           18            $99.99

Part description and quantity sorted by quantity

{ PartDescription = Lawn mower, Quantity = 3 }

{ PartDescription = Electric sander, Quantity = 7 }

{ PartDescription = Sledge hammer, Quantity = 11 }

{ PartDescription = Power saw, Quantity = 18 }

{ PartDescription = Jig saw, Quantity = 21 }

{ PartDescription = Wrench, Quantity = 34 }

{ PartDescription = Hammer, Quantity = 76 }

{ PartDescription = Screwdriver, Quantity = 106 }

Part description and invoice total sorted by invoice total

{ PartDescription = Jig saw, invoiceTotal = 231.00 }

{ PartDescription = Sledge hammer, invoiceTotal = 236.50 }

{ PartDescription = Lawn mower, invoiceTotal = 238.50 }

{ PartDescription = Wrench, invoiceTotal = 255.00 }

{ PartDescription = Electric sander, invoiceTotal = 405.86 }

{ PartDescription = Screwdriver, invoiceTotal = 740.94 }

{ PartDescription = Hammer, invoiceTotal = 911.24 }

{ PartDescription = Power saw, invoiceTotal = 1799.82 }

Part description and invoice total, total between $200 and $500

{ PartDescription = Jig saw, invoiceTotal = 231.00 }

{ PartDescription = Sledge hammer, invoiceTotal = 236.50 }

{ PartDescription = Lawn mower, invoiceTotal = 238.50 }

{ PartDescription = Wrench, invoiceTotal = 255.00 }

{ PartDescription = Electric sander, invoiceTotal = 405.86 }

Part number

Part description

Quantity

Price

83

Electric sander

7

57.98

24

Power saw

18

99.99

7

Sledge hammer

11

21.50

77

Hammer

76

11.99

39

Lawn mower

3

79.50

68

Screwdriver

106

6.99

56

Jig saw

21

11.00

3

Wrench

34

7.50

Solution

Module Module2

    Sub Main()
        \' array of Invoice objects with the following data
        Dim invoices As In() = { _
        New Invoice(\"83\", \"Electric Sander\", \"7\", 57.98), _
        New Invoice(\"24\", \"Power Saw\", \"18\", 99.99), _
        New Invoice(\"7\", \"Sledge Hammer\", \"11\", 21.50), _
        New Invoice(\"77\", \"Hammer\", \"76\", 11.99), _
        New Invoice(\"39\", \"Lawn Mower\", \"3\", 79.50), _
        New Invoice(\"68\", \"Screwdriver\", \"106\", 6.99), _
        New Invoice(\"56\", \"Jig Saw\", \"21\", 11.00), _
        New Invoice(\"3\", \"Wrench\", \"34\", 7.50)
                                    }

        \'Display the original array

        \'Question Part a PartDescription
        Dim Desc = From i In invoices Order By i.PartDescription Ascending
        Display(Desc, \"sorted the Invoice objects by PartDescription.\")

        \'Question Part b   UnitPrice
        Dim invPrice = From i In invoices Order By i.UnitPrice Ascending
        Display(invPrice, \"sort the Invoice objects by UnitPrice.\")

        \'Question Part c   PartDescription & quantity and sort by quantity
        Dim SortDescQuant = From invoice In invoices Select invoice.PartDescription, qu= invoice.Quantity Order By qu Ascending
        Display2(SortDescQuant, \"selecting the PartDescription and Quantity and sort the results by Quantity\")

        \'Question Part d   adding InvoiceTotal and multiplying quantity & price
        Dim InvoiceTotal = From i In invoices Select i.PartDescription, t = (i.Quantity * i.Price).ToString(\"c2\") Order By CDec(t) Ascending
        Display2(InvoiceTotal, \"total amount of the invoice.\")

        \'Question Part e    select InvoiceTotal between $200 & $500 using part d
        Dim between = From l In InvoiceTotal Where CDec(l.t) >= 200 AndAlso CDec(l.t) <= 500 Select l
        Display2(between, \"invoices with total amount in the range $200 to $500.\")

        \'display console window for 50sec
            Threading.Thread.Sleep(50000)

    End Sub

    Sub Display(Of T)(ByVal results As IEnumerable(Of T), ByVal header As String)
        Console.WriteLine(\"{0}:\", header)

        For Each element As T In results
            Console.WriteLine(\" {0}\", element)
        Next
        Console.WriteLine()
    End Sub

    Sub Display2(Of T)(ByVal results As IEnumerable(Of T), ByVal header As String)
        Console.WriteLine(\"{0}:\", header)

        For Each element As T In results
            Dim parts(1) As String
            Dim rx As New Regex(\"(?<=\\=\\s)(.|\\s|,)+?(?=(\\s\\}|,\\s))\")
            parts(0) = rx.Matches(element.ToString).Item(0).Value
            parts(1) = rx.Matches(element.ToString).Item(1).Value
            Console.WriteLine(String.Format(\"{0,-20} {1,9}\", parts(0), parts(1)))
        Next
        Console.WriteLine()
    End Sub

End Module

Write a C# application to do the following. First, create an array of Invoice objects with the following data: [Please see next page] Part number Part descripti
Write a C# application to do the following. First, create an array of Invoice objects with the following data: [Please see next page] Part number Part descripti
Write a C# application to do the following. First, create an array of Invoice objects with the following data: [Please see next page] Part number Part descripti

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site