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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education