Related questions
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:
- 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
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.
Step by stepSolved in 5 steps with 2 images
- each line in the input file will represent a record of data. There will be 10 lines, thus 10 records. Each record (line) will consist of 3 space separated fields: a name (1 word as a string), and age (as an integer), and a wage (as a float). Write a C program that: takes an input file name from the command line; opens that file if possible; declares a C struct with three variables; these will have data types that correspond to the data types read from the file (i.e. string, int, float); declares an array of C structs (i.e. the same struct type declared in point c); reads a record from the file and stores the values read into the appropriate struct variable at the appropriate array index (for that record); continues reading each record into a struct (as in point 1e), and stores each struct containing the 3 values into the array of structs declared in point d; closes the file when all records have been read. should print an error message in the event that the file cannot be...arrow_forwardThe international Olympics Committee has asked you to write a program to process their data and determine the medal winners for the pairs figure skating. You will be given a file named Pairs.txt.This file contains the data for each pair of skaters. The data consists of each skater’s name, their country and the score from each of eight judges on the technical aspects and on the performance aspects. A typical record in the file would be as follows: SmithJonesAustralia5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.84.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5 LennonMurrayEngland2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.83.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8GustoPetitotItalia4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.85.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8LahaiePetitFrance1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.85.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8BilodeauBernardCanada2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.84.1 4.2 4.3 4.8 4.9 4.6 4.0 4.5LahorePedroMexico3.2 3.1 3.8 3.9 3.0 3.6 3.9 3.35.9 5.8 5.8 5.8 5.9 5.6 5.0 5.5MaliakKolikovRussia4.2 4.1 4.8 4.9 4.0 4.6 4.9 4.31.9 1.8 1.8 1.8...arrow_forwardThe Pinewood Derby involves racing Derby cards down multiple lanes and calculating the average time to determine the winner. Create a program that prompts the user to enter in the number of racers that are competing. For each racer that is competing, the user should be specified to enter in four race times and the program should display the average of those times. That data should be then saved to a file. The program should drop the racers slowest time and calculate the average of the remaining times to determine a winner. Note: The most common error I see is that people drop the fastest race time, not the slowest. The program does not need to report who won; the program just needs to display the adjusted average for each racer.arrow_forward
- Word Puzzle GameIn this assignment is only for individual. You are going to decode the scrambled word into correct orderin this game. One round of play is as follows:1. Computer reads a text file named words.txt2. Computer randomly picks one word in the file and randomly scrambles characters in the wordmany times to hide the word3. Computer displays the scrambled word to user with indexes and gives the user options to1. Swap two letters in word based on index given2. Solve the puzzle directly3. Quit the game4. If a player chooses to swap letters, the computer reads two indexes and swaps the letters. Thegame resume to step 3 with the newly guessed word. If the resulted word after swapping is thesecret word, the game is over.5. If a user chooses to solve directly, computer prompts the user to enter the guessed word. If it’scorrect, the game is over, otherwise goes to step 3.6. After game is over, display how many times the player has tried to solve the puzzle.The following is sample...arrow_forwardPROGRAM NEEDS TO MATCH EXAMPLE PHOTO Write a program ( lab6.cpp ) that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the program. You can use your editor to enter the initial piece of advice in the file so that the first person who runs the program receives some advice. Allow the user to type in advice of any length so that it can be any number of lines long. The user is told to end his or her advice by pressing the Return key two times. Your program can then test to see that it has reached the end of the input by checking to see when it reads two consecutive occurrences of the character ‘\n’. Hints:- You need to look at each character as it is read to see if it is...arrow_forwardWrite a program that opens a specified text file then displays a list of all the unique words found in the file. Hint: Store each word as an element of a set. 5. Word Frequency Write a program that reads the contents of a text file. The program should create a dictio- nary in which the keys are the individual words found in the file and the values are the number of times each word appears. For example, if the word "the" appears 128 times, the dictionary would contain an element with 'the' as the key and 128 as the value. Thearrow_forward
- Write the code segments based on the given descriptions: Declare a file pointer called input. Open a file called location.txt for reading using this pointer. If the file is not available, display "File does not exist.". The content of the text file location.txt is as shown below. It includes the location, latitude and longitude values. FILE location.txt CONTENTS <Location> <Latitude> <Longitude> UTM 1.5523763 103.63322 KLCC 3.153889 101.71333 UM 3.1185 101.665 UMS 6.0367 116.1186 UNIMAS 1.465174 110.4270601 Ask the user to enter a location. Check if the user’s location can be found in the text file. If found, display the location, latitude and longitude as shown below. SAMPLE OUTPUT Enter a location: UM Location : UM Latitude : 3.1185 Longitude : 101.6650 Otherwise display "Sorry, location could not be found". SAMPLE OUTPUT Enter a location : MMU Sorry, location could not be foundarrow_forwardIn pythonarrow_forwardDescriptionWrite a program to compute average grades for a course. The course records are in a single file and are organized according to the following format: each line contains a student's first name, then one space, then the student's last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program will read data from this file and write its output to a second file. The date in the output file will be nearly the same as the data in the input file except that you will print the names as last-name, first-name; each quiz score, and there will be one additional number at the end of each line:the average of the student's ten quiz scores.Both files are parameters. You can access the name of the input file with argv[1]. and the name of the output file with argv[2].The output file must be formatted as described below: 1. First and last names...arrow_forward
- Design an application for the ABC Company that will process inventory from a file called ABC_Inventory.txt (attached to this assignment). The file contains Item ID, Description and list price stored on a separate line in the file. The program should display the contents of each record and then calculate and display the average list price. it is important that this is done in Thonny for python warrow_forwardData File: Example #1AAAAABBBBBCCCCCDDDDDAAEBCBAFBBCDCECDADDEFEEFFFExample #2AAATAABTBBBBCCCCTCDDTDDDAASAABBSBBCCSCCDSDDDEEEAEEFBFFFDDF Write a program that will give the user a brief introduction, then allow the user to type in the name of the file to be analyzed, the name of the data file to generate, and then process the data to match the output that is shown below. This DNA test measures the various parts of the sequence and assigns them a letter. While the letters could be anything from A to Z, the only letters that matter for this test are the letters {A,B,C,D} all other letters can be ignored completely. A sample will be tested, given a length of time and then tested again. Each time the scientist will generate a line of data. Here is one Example: Example #1 AAAAABBBBBCCCCCDDDDD AAEBCBAFBBCDCECDADDEFEEFFF At first glance the sample looks significantly different after the second test. But if you look at the data, you will note that since we only care about A,B,C,D’s that the...arrow_forwardWAP to read 4 student objects and write them into a file, then print total number of student number in file. After that read an integer and print details of student stored at this number in the file using random access and file manipulators.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education