Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please separate the functions into a header file. Please do not write it all in main Assignment 2 will require Array of records (structs) with

Please separate the functions into a header file. Please do not write it all in main

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

In this assignment, 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 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 covert currencies.

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 (same as Assignment 1). Note that the amounts in each line have values from 1 to 99. However, when you sum up the 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). You need to provide a test plan to fully test your algorithm and program, and provide an input data file, coins.txt, that contains test data in the specified format for testing your program. Your solution (program and algorithm) should be modular in nature. Use a high cohesion and low coupling design.

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.

If you find that you have developed a large number of functions (code modules/subroutines) where each perform some similar or overlapping task (or have a lot of code that is repeated in the functions) to other modules/subroutines, then attempt to analyse your design to generalise the logic so that you have just one general version of the module/subroutine.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

How would we like to see ourselves?

Answered: 1 week ago

Question

2 . Describe the dimensions of data quality.

Answered: 1 week ago