1 – Assignment Following on the success of homework 1, your mother has asked you to augment your tag sale price recording program to save all of the data to files. She noticed that if you close the program around lunchtime, all of the sales data is lost. She wants it to be permanent. Change your program from homework 1 to do two new things: • Upon opening the program, load data from a file (name the file whatever you want) into the array in which you store prices. Update the statistics in the GUI using the loaded data. • Continue to run the program normally while collecting data… • Before closing the program, write all of the collected data to the file. If you already loaded all data from the file into the array when you started the program, then all of that data and the new data collected should be in the array. Overwrite the existing file with the new data File format – The simplest method to store data in the file would be entering a newline after each price, so that your file looks like this: 3.50 0.50 2.00 25.00 Notes: • Make sure to open a file in read mode when reading… • Make sure to open a file in write mode when writing. If overwriting an existing file, make sure you set the correct flags, otherwise you will be appending to the file • Make sure you close the files after you are done reading or writing to them. When a file is opened, the file is locked from other programs using it at all, until you close it… This is true even for your own program, you can’t open the same file again without closing it first. Visual basic/visual studio Current code Imports System.IO Public Class FrmMain     Dim prices(0) As Double ' Array to store prices of items sold     Dim totalSales As Double ' Total amount of money collected     Dim totalItems As Integer ' Total number of items sold     Dim averageSalePrice As Double ' Average sale price     Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click         Me.Close()     End Sub     Private Sub btnSubmitPrice_Click(sender As Object, e As EventArgs) Handles btnSubmitPrice.Click         Dim price As Double = InputBox("Enter Price: ", "Enter a Number")         ' Add the price to the array and update the statistics         ReDim Preserve prices(prices.Length + 1)         prices(prices.Length - 1) = price         totalSales += price         totalItems += 1         averageSalePrice = totalSales / totalItems         ' Display the statistics         lblTotalSales.Text = "Total Sales: " + totalSales.ToString()         lblTotalItems.Text = "Total Items: " + totalItems.ToString()         lblAverageSalePrice.Text = "Average Sale Price: " + averageSalePrice.ToString()     End Sub End Class

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter6: Managing Multiple Worksheets And Workbooks
Section: Chapter Questions
Problem 3.8CP
icon
Related questions
Question

1 – Assignment
Following on the success of homework 1, your mother has asked you to augment your tag sale price
recording program to save all of the data to files. She noticed that if you close the program around
lunchtime, all of the sales data is lost. She wants it to be permanent.
Change your program from homework 1 to do two new things:
• Upon opening the program, load data from a file (name the file whatever you want) into the
array in which you store prices. Update the statistics in the GUI using the loaded data.
• Continue to run the program normally while collecting data…
• Before closing the program, write all of the collected data to the file. If you already loaded all
data from the file into the array when you started the program, then all of that data and the
new data collected should be in the array. Overwrite the existing file with the new data
File format – The simplest method to store data in the file would be entering a newline after each price,
so that your file looks like this:
3.50
0.50
2.00
25.00
Notes:
• Make sure to open a file in read mode when reading…
• Make sure to open a file in write mode when writing. If overwriting an existing file, make sure
you set the correct flags, otherwise you will be appending to the file
• Make sure you close the files after you are done reading or writing to them. When a file is
opened, the file is locked from other programs using it at all, until you close it… This is true even
for your own program, you can’t open the same file again without closing it first.

Visual basic/visual studio

Current code

Imports System.IO

Public Class FrmMain
    Dim prices(0) As Double ' Array to store prices of items sold
    Dim totalSales As Double ' Total amount of money collected
    Dim totalItems As Integer ' Total number of items sold
    Dim averageSalePrice As Double ' Average sale price
    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnSubmitPrice_Click(sender As Object, e As EventArgs) Handles btnSubmitPrice.Click

        Dim price As Double = InputBox("Enter Price: ", "Enter a Number")

        ' Add the price to the array and update the statistics
        ReDim Preserve prices(prices.Length + 1)
        prices(prices.Length - 1) = price
        totalSales += price
        totalItems += 1
        averageSalePrice = totalSales / totalItems

        ' Display the statistics
        lblTotalSales.Text = "Total Sales: " + totalSales.ToString()
        lblTotalItems.Text = "Total Items: " + totalItems.ToString()
        lblAverageSalePrice.Text = "Average Sale Price: " + averageSalePrice.ToString()

    End Sub
End Class

 

 

Tag Sale
Total Sales
Average Sale Price
Submit Price
Total Items
Exit
X
Transcribed Image Text:Tag Sale Total Sales Average Sale Price Submit Price Total Items Exit X
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning