a program that allows you to view and edit the sales amounts for each month of the current year. Example COMMAND MENU add - Add sales for specified month view - View sales for specified month edit - Edit sales for specified month totals - View sales summary for year exit - Exit program
Monthly Sales
Example
Specifications
- The program should use a list to store the sales data for each month with the three-letter abbreviation for the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec) as the key for each item.
- When the program starts, it should read the sales data inserted from the user.
- If the user edits the sales data, the program should edit the data (review slide 45 for calculate total function example).
- Has to be in c++
- Has to use ALL commands : add,edit,exit,totals, and view
- If the user selects total, the program should calculate the total sales and average monthly sales.
- Use functions to view sales, edit sales, calculate total, and calculate average.
def readFile():
sale={}
file=open("monthly_sales.txt")
for line in file:
l=line.split("\t")
sale[l[0]]=int(l[1])
file.close()
return sale
def writeFile(d):
file=open("monthly_sales.txt", 'w')
for k, v in d.items():
file.write(k)
file.write("\t")
file.write(str(v))
file.write("\n")
file.close
d=readFile()
print("Monthly Sales program\n")
print("COMMAND MENU")
print("view\t- View sales for specified month")
print("edit\t- Edit sales for specified month")
print("totals\t- View sales summary for year")
print("exit\t- Exit pogram")
while True:
command=input("\nCommand: ")
command=command.lower()
if command=='view':
mon=input("Three-letter Month: ")
monupper=mon.upper()
if len(mon)!=3:
print("Inavlid three-letter month.")
else:
for k, v in d.items():
if monupper==k:
print(f"Sales amount for {mon} is {v:0.2f}.")
break
Trending now
This is a popular solution!
Step by step
Solved in 2 steps