Answered You can hire a professional tutor to get the answer.

QUESTION

The club stores the spending records of its guests in a text file called record.txt as follows: John 100 Ronald 250 Francis 300 John 167 Cliff 34...

The club stores the spending records of its guests in a text file called record.txt as follows:

John 100 Ronald 250 Francis 300 John 167 Cliff 34 Ronald 353 ...

12/30/2017 01/01/2017 08/13/2017 01/04/2017 01/03/2017 01/03/2017

Note that each line in record.txt stores one record, which has three fields, namely, guest_name, money_spent, spending_date. For example, the first line

John 100 12/30/2017

shows that a guest with name John has spent $100 on December 30, 2017. When writing the program, you may assume that

  1. each line has only one record, and the fields in a record are separated by tab;
  2. the club has no more than 100 guests;
  3. guest_name is a single word (i.e., there is no space in a name);
  4. money_spent is a non-negative integer;
  5. spending_date is of the format mm/dd/yyyy where mm and dd are two-digits integers representing the month and day for this record, yyyy is a four-digits integer representing year for this record.
  6. the spending_date is correct (i.e., no input validation is needed);
  7. the year "yyyy" is always 2017.

Note: if the month or the day has a single digit, then it should be preceded by the digit '0'. For example, the date January 2, 2017 should be 01/02/2017.

At the end of every year, the club will need to execute your program to extract some useful statistics from record.txt. In addition to record.txt, your program should read another file command.txt, which stores the commands for processing record.txt. After executing each command, your program should append the result to an output file called report.txt. Below, we summarize the commands your program needs to handle.

Command summarize

The format of this command is:

summarize guest_name endmonth

Note that "summarize" is the name of the command, guest_name is the name of the guest, and endmonth is an integer between 1 and 12. The command asks the program to print, for each month from the first to the endmonth, the money spent by the guest in that month. It also prints the total amount of money spent by the guest during this period. The words in a command line are separated by one tab.

For example, suppose that John has been at the club for four different days in the whole year, and his records in record.txt appear as follows:

..

John 123 ...

John 200 ...

John 304 ...

John 225 ...

02/11/2017 02/24/2017 05/13/2017 12/07/2017

Then for the command:

summarize John 5

your program should print the following lines in report.txt

Notes:

1. One blank line should be added after the line for "Total". 2 Each line is starting with a single tab.

3. The entries of a line are separated by a single tab

Our program should also check for errors in the command. There are two types of errors.

1. No record found.

Suppose there is not any record for King in record.txt. Then for the command

"summarize King 4"

your program should print the following in report.txt

Result for summarize Jan: $0

Feb: $323 Mar: $0 Apr: $0 May: $304 Total: $627

John 5:

Result for summarize King 4: There is no record for King

Notes:

1. One blank line should be added after the last line 2 the second line is starting with a single tab.

2. Invalid endmonth.

Recall that endmonth is an integer from 1 to 12. Then for the command

"summarize John 17"

your program should print the following in record.txt. (Suppose John has records in record.txt, otherwise, you should output "no record" as above)

Notes:

1. One blank line should be added after the last line 2 the second line is starting with a single tab.

Command Find-stat

The format of this command is:

Find-stat quarter

where "Find-stat" is the name of the command, and quarter can be one of the four strings: "Q1", "Q2", "Q3" and "Q4", corresponding to the four quarters of a year, or more precisely, Q1 covers the first three months, from Jan to Mar, Q2 covers Apr to June, Q3 covers July to Sep, and Q4 covers Oct to Dec.

For this command, your program should compute, for each guest, the total amount of money he/she has spent in that quarter, and then prints in report.txt the max, min and average spent by these guests in that quarter. For example, suppose the club has only three guests Peter, John, and Tom who has spent money in the first quarter, i.e., Q1. Suppose Peter, John and Tom have spent $1245, $2812, and $980, respectively in Q1. Then, in response to the command:

Find-stat Q1

Your program should output the following to report.txt:

Notes:

1. there is a single tab between "Find-stat" and "Q1"

2.One blank line should be added after the line for "Avg".

3. Each line is starting with a single tab

4. The entries of a line are separated by a single tab

Note that the quarter must be either Q1, Q2, Q,3 or Q4. For other value, your program should output an error message. For example, for the command "Find-stat X1", your program should output to report.txt

Result for summarize John 17: Endmonth 17 is invalid

Result for Find-stat Q1: Max: $2812

Min: $980 Avg: $1679.00

Result for Find-stat X1: Quarter X1 is invalid

Notes:

1. One blank line should be added after the last line 2 the second line is starting with a single tab.

Command Sort:

The format of this command is: Sort desc_money

For this command, all the guests will be listed in descending order of how much they spent in the whole year. For example, for this command, your program should output the following to report.txt:

Result for Sort desc_money:

Ronald 353 Francis 300 Ronald 250 John 167 John 100 Cliff 34 ...

01/03/2017 08/13/2017 01/01/2017 01/04/2017 12/30/2017 01/03/2017

P.S.: please refer to the record.txt in the beginning.

Note 1:

1. there is a single tab between "Sort" and "desc_money". 2. One blank line should be added after the last line.

3. Each line is starting with a single tab.

4.The entries of a line are separated by a single tab

Note 2: You may assume that there is no other command in command.txt 

How to write this program?

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question