ICT159 - Assignment 2(1)

.docx

School

Murdoch University *

*We aren’t endorsed by this school

Course

159

Subject

Computer Science

Date

May 13, 2024

Type

docx

Pages

25

Uploaded by HighnessIbex4352 on coursehero.com

ICT159 Foundations of Programming ICT159 – Assignment 2 This is an individual assignment, and is worth 20% of the total assessment for the unit. Student ID Name Final Mark Objectives Construct algorithms to solve problems using a combination of sequence, selection and iteration constructs. Implement such algorithms in a common programming language, C . Read/write data to/from files. Use arrays of records (structs). Search arrays of records. Apply the methodology of top-down design to the construction of solutions and implement these solutions in a modular way. Prerequisites This Assignment extends Assignment 1. There is meant to be code reuse from Assignment 1 if your design and code from Assignment 1 adheres to the principles of high cohesion and low coupling. You will know if these principles were adhered to if you are able to reuse most of the modules from Assignment 1. Before attempting this question, please complete the following prerequisites: Make sure you have attempted Assignment 1, even if not submitted. All lab exercises for modular programming, arrays, Files and Data Structures have been completed. Make sure that you have corrected your solution to Assignment 1 following the solution discussed during the lectures (please refer to the recorded videos). This is an individual assignment and must be completed by you alone. Any unauthorised collaboration/collusion may be subject to investigation and result in penalties if found to be in breach of University policy.
Submission Guidelines Your assignment must be submitted via LMS following the guidelines listed below. Failure to adhere to these guidelines will result in marks being lost or a fail grade being awarded. Create a folder named ICT159_StudentID_Surname_Assignment2. Make sure you replace StudentID with your student ID and Surname with your surname Put the source code (i.e., C program) files into this folder. Answer the questions directly on this World document (the C programs need to be included separately; see the previous points. Do not paste code into this word document). Once done, convert it into PDF and save it inside the folder ICT159_StudentID_Surname_Assignment2. You should always keep a copy of all your work. Keep the backup of your work in cloud storage like OneDrive. Losing your work/files (for any reason) a few days before the deadline is not a valid ground for extension. Note that: You may be required to demonstrate and explain your solution in person after the submission. If such demonstration is needed, you will be contacted. If you do not defend/demonstrate in-person, no marks will be given, resulting in a mark of 0. You must use modular design and modular programming . Failure to use modular programming will result in a straight 0. What you need to provide Your assignment must contain the following components either in the documentation or as separate electronic files, where indicated: 1. All assumptions made other than those stated in the question that you make about the problem. There will virtually always be assumptions you are implicitly making so think about this very carefully. Also, be careful that you do not put in unnecessary assumptions. (5%) 2. Structure chart for your program. Make sure that your structure chart shows the parameter passing. ( 5% ) 3. Your algorithms written in a uniform fashion using a pseudocode or a similar style and adhering to the conventions required in the unit. Your algorithms should be presented at an appropriate level of detail sufficient to be easily implemented. Submit your high- level algorithm along with algorithms of your decompositions (refinements) as appropriate to the question. Algorithms that look like the code was written first and then word processed to look like an algorithm would receive no marks. (25%) 4. A set of test data in tabular form with expected results and desk check results from your algorithm. Each test data must be justified – reason for selecting that data. No marks will be awarded unless justification for each test data is provided. (10%) 5. Source code files (.c and .h) must be submitted and the source code must build (compile and link) to create an executable that operates correctly. Make sure you use the code style required in the unit. No marks awarded if the source code does not build and run. (50%) 6. Results of applying your test data to your final program (tabular form), including screenshots of your program in operation . You need to provide one screenshot per test case (5%) 2
Please submit the sections in order as shown in the assignment template in this document. Marks may be lost otherwise. 3
Assignment Question 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 any number of lines in the file. 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 type of files. 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$. 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 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 4
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. In 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). 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. 5
Important Note: For this problem, the principles of code reuse, low coupling and high cohesion, covered in Week 6, are particularly important: A significant number of marks are allocated to these aspects of your design. You should attempt to design your solution such that it consists of a relatively small number of modules (functions), but still meets the modular design best practice requirements of this unit. In particular, strive to have one module that can be reused (called repeatedly) to solve the coin calculation problem. If you find that you have developed a large number of modules where each performs a similar task, or that you have a lot of instructions that are repeated in one module, then attempt to analyse your design to generalise the logic so that you have just one general version of the module. Be mindful of the cohesion exhibited by each module. If you have a module that is doing more than one task (i.e. demonstrating low cohesion), then you should re-design it to have high cohesion. 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). 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help