Question: This will require Array of records (structs) with file I/O is needed. In this C program, instead of asking the user to input the amount

This will require Array of records (structs) with file I/O is needed.

In this C program, instead of asking the user to input the amount from the keyboard, this time, the program will read its data from a text file named coins.txt. There can be 0 and up to 10 input lines, each line is formatted like the example below:

Jane 30 cents in AU$

Joe 85 cents in EUR

Jane 25 cents in AU$

Jane 15 cents in US$

Names are one-word strings. The same name can be repeated in the data file but the coin values/currencies can be the same or different. If the name is the same, your program must assume it relates to the same individual.

You are asked to write a program that reads the data from this file. For each individual, the program then must add up the coin amounts that belong to the same currency to obtain a total amount for that individual in that currency. It then needs to compute the change to be given for that individual for each of the currencies that that individual owns.

For example, the example input file above indicates that Jane has 30 + 25 = 55 cents in AU$ and 15 cents in US$. The program then needs to calculate how many coins (hereinafter referred to as change) it should give to Jane for the amount it owns in AU$ and for the amount it owns in US$.

You do not convert currencies.

The coins we have are:

1) US$, which has four types of coins of 50, 25, 10 and 1 cents

2) AU$, which has four types of coins of 50, 20, 10 and 5 cents

3) Euro, which has four types of coins of 20, 10, 5 and 1 cents

The program should aim to give as much of the higher valued coins as possible. Note that the amounts in each line have values from 1 to 99. However, when you sum up all the lines of an individual, the total for that individual can exceed 99. If the file contains a value that is not in that range, it should display a message saying that the data file has incorrect values and should display the line numbers that contain these incorrect values.

Once your program has read in the data from coins.txt, your program will close coins.txt first, and then show a console screen menu as illustrated below:

1. Enter name 2. Exit

The program will continue to show the menu and execute the menu options until "Exit" is selected by entering the value 2 at the menu prompt. When the user enters the value 1 at the menu prompt, your program will ask for a name. As an example, if the user enters the name Jane, the program will output: Customer: Jane 55 cents in AU$ Change: 50 cents: 1 5 cents: 1

Jane 15 cents in US$ Change: 10 cents: 1 1 cents: 5

Change values of 0 should not be shown.

If the user enters a non-existent name (e.g., Donald) at menu Option 1, which would not be in the array of records, your program will print:

Name: Donald

Not found

After the output is provided for menu Option 1, the menu is redisplayed.

Once the user enters 2 to exit, your program must write the coin, the currency and change data in .csv format for all names present in the file coins.txt to another file called change.csv. After writing the data to the file your program must exit. In change.csv, the data lines for Jane will look as follows, with each value separated by a comma and with the line terminated by newline: Jane, the change for 55 cents in AU$ is 1,0,0,1

Jane, the change for 15 cents in US$ is 0,0,1,5 So in the example output, Jane has

55 cents in AU$: one 50 cent coin and one 5 cent coin. There are no 20 or 10 cent coins.

15 cents in US$: one 10 cent coin and five 1 cent coins. There are no 50 or 25 cent coins.

The output data file change.csv, if an individuals name appears more than once inside coins.txt, their name should appear only once per currency inside change.csv (with the accumulated coin amount and change for that currency).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!