View the step-by-step solution to:

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

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




For example, the first line

John 100 12/30/2017

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

  1. one record, and the fields in a record are separated by tab;
  2. 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//yyyy where mm and are two- integers representing the month and day for this record, yyyy is a four- integer representing year for this record.
  6. spending_date is correct (i.e., no input validation is needed);
  7. "" 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

The format of this command is:

guest_name

Note that "summarize" is the name of the command, guest_name is the name of the guest, and is an integer between 1 and 12. The command asks the program to print, for each month from the first to money spent by the guest 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 the command:

John 5

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 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 the command

" King 4"

following in report.txt

Result Jan: $0

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

John 5:

Result for 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

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

" John 17"

following in record.txt. Suppose John has 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

"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 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. tab between "Find-stat" and "Q1

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

3. Each line with a single tab

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

Note that the quarter must be either Q1, Q2, Q3 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 John 17: 17 is invalid

Result for Find-stat Q1: Max: $2812

Min: $980 Avg: $167900

Result for 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.

:

The format of this command is: Sort desc_money

, 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. tab between "Sort" and "desc_money". 2. One blank line should be added after the last line.

3. Each line with a single tab.

The entries a line are separated by a single tab

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

How to read the command txt. and execute then? How to find the specific guest name on the string and specifies which it is (string name[100], John is name[?])? And what about other two commands? I have been struggling for whole day. Thanks so much.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question