Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

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

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 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 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 must add up the coin amounts that belong to the same currency to obtain a total amount for that individual in that currency. It needs to compute the change to be given for that individual for each currency that individual owns.

e.g, the example above shows Jane has 30 + 25 = 55 cents in AU$ and 15 cents in US$. The program needs to calculate how many coins (hereinafter referred to as change) it should give to Jane for the amount in AU$ and in US$.

The coins we have are the same as Assignment 1:

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 are between 1 to 95. However, when you sum up the all the lines of an individual, the total for that individual can exceed 95. 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 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 individual’s 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).

Your solution (program and algorithm) should be modular in nature. Use a high cohesion and low coupling design.

Also, all the displays (i.e., printf) should happen in the main program, not in the individual functions, except for the functions designed to ask the user to enter some input and those designed to print the final result.

Submit a structure chart and a high-level algorithm with suitable decompositions (refinement) of each step (low-level algorithm).

Note that for this problem, the principle of code reuse is very important, and a significant number of marks are allocated to this. You should attempt to design your solution such that it consists of a relatively small number of functions that are as general in design as possible, and you should have functions/subroutines that can be reused (called repeatedly) in order to solve the majority of the problem.

Be mindful of the cohesion exhibited by the function (module). So, if you have a function (module) that is doing more than one task, then cohesion is low, and, you will need to redesign to have high cohesion.

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education