Sales Report Brewster\'s Used Cars, Inc. employs several salespeople. K Brewster
ID: 3802775 • Letter: S
Question
Sales Report Brewster's Used Cars, Inc. employs several salespeople. K Brewster, the owner of the company, has provided a file that contains sales records for each salesperson for the past month. Each record in the file contains the following two fields: The salesperson's ID number, as an integer The amount of a sale, as a real number Files The records are already sorted by salesperson ID. Brewster wants you to design a program that prints a sales report. The report should show each salesperson's sales and the total sales for that salesperson. The report should also show the total sales for all salespeople for the month. Here is an example of how the sales report should appear: Brewster's Used Cars, Inc. Sales Report Salesperson ID Sale Amount 100 $10,000.00 100 $12,000.00 100 $5,000.00 Total sales for this salesperson: $27,000.00 101 $14,000.00 101 $18,000.00 101 $12,500.00 Total sales for this salesperson: $44,500.00 102 $13,500.00 102 $14,500.00 102 $20,000.00 Total sales for this salesperson: $48,000.00 Total of all sales: $119,500.00Explanation / Answer
Here is the program as per your requirements.
As per your requirement you keep the file data.txt in your current working directory and you will get output.txt
Private Sub SalesReport()
Dim FileHandler As String 'declaring variable
Dim FileHandlerOutput As String 'declaring variable
Dim SalesID(1000) As Integer 'declaring variable
Dim SalesIDPerson As Integer 'declaring variable
Dim SalesAmountIndividual As Double 'declaring variable
Dim i As Integer 'declaring variable
Dim PrintString As String 'declaring variable
Dim SalesAmount(1000) As Double 'declaring variable
Dim TotalSalesAmount As Double 'declaring variable
FileHandler = App.Path & "data.txt" ' assigning value
FileHandlerOutput = App.Path & "output.txt" ' assigning value
Open FileHandler For Input As #1 ' opening the file for input
Open FileHandlerOutput For Output As #2 ' opening the file for output
PrintString = "Sales Person ID" & " " & "SaleAmount"
Write #2, PrintString
i = 0
Do Until EOF(1) ' until end of file is reached go through all the records
i = i + 1
Input #1, SalesID(i), SalesAmount(i)
Loop
i = 1
SalesIDPerson = SalesID(i)
For i = 1 To 1000
If SalesID(i) = 0 Then
Exit For
End If
If SalesID(i) = SalesIDPerson Then
PrintString = SalesID(i) & " $" & SalesAmount(i)
Write #2, PrintString
SalesAmountIndividual = SalesAmountIndividual + SalesAmount(i)
TotalSalesAmount = TotalSalesAmount + SalesAmount(i)
Else
PrintString = "Total sales " & SalesIDPerson & ": $" & SalesAmountIndividual
Write #2, PrintString
PrintString = SalesID(i) & " $" & SalesAmount(i)
Write #2, PrintString
salesamontindividual = 0
SalesAmountIndividual = SalesAmount(i)
TotalSalesAmount = TotalSalesAmount + SalesAmount(i)
SalesIDPerson = SalesID(i)
End If
Next i
PrintString = "Total sales " & SalesIDPerson & ": $" & SalesAmountIndividual
Write #2, PrintString
PrintString = "Total sales amount = $" & TotalSalesAmount
Write #2, PrintString
Close #1
Close #2
End Sub
data.txt
100 10000
100 12000
100 55000
101 14000
101 18000
101 12500
102 13500
102 14500
102 20000
This is the output got in the file output.txt
output.txt
"Sales Person ID SaleAmount"
"100 $10000"
"100 $12000"
"100 $55000"
"Total sales 100: $77000"
"101 $14000"
"101 $18000"
"101 $12500"
"Total sales 101: $44500"
"102 $13500"
"102 $14500"
"102 $20000"
"Total sales 102: $48000"
"Total sales amount = $169500"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.