ICT159 Foundations of Programming
Assignment 2
DUE :
See LMS
If you are unsure of anything, you need to get clarification early. So read this document very carefully.
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:
• Completed all readings, exercises and assignment leading up to assignment 2.
Worth:
This assignment is worth 20% of the total assessment for ICT159.
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.
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.
General Submission Guidelines:
Failure to adhere to these guidelines will result in marks being lost or a fail grade being awarded.
• Your assignment MUST be submitted via LMS containing ALL sections.
• To be accepted and receive marks, your submission must meet the following criteria:
• submitted as separate files, NOT any kind of compressed/aggregated file format such as ZIP, ARJ, RAR, TGZ, etc.
• source code files named Assignment2.c or Assignment2.cpp, etc.
• executable files named Assignment2.exe, etc.
• a single document according to the supplied templates in .DOCX or .PDF format (ICT159 Assignment2.docx or ICT159 Assignment2.pdf).
• Summary evaluation file with file name evaluation.txt
• Nothing else that is not asked for
• The non-source code parts of the assignment must be word processed and proof read: no hand written work will be accepted.
• Students must use the assignment template provided in this document. Using a different or altered structure provided may result in marks being deducted or work not being accepted due to assignment requirements not being met.
• All questions and sections within questions must be submitted in order: marks may reduce otherwise. The supplied template ensures this requirement is met.
• The assignment requires the submission of the different sections as specified below. Your final submission should be prepared as a single document containing each of the sections in order. You can do this by copying and pasting your algorithms/code into this document. Code (when discussing code aspects as needed) and algorithms within this document should be formatted with a font such as Courier New to enhance their readability. Source code files are submitted separately along with a summary evaluation file evaluation.txt. Source code is submitted as C compilable source code with the appropriate code file extensions.
• Algorithms that look like the code was written first and then word processed to look like an algorithm would receive no marks.
• Assignments must be received by the deadline. Late assignments will be penalised 10% per day late or part thereof.
• Assignments will not be accepted where these are more than 5 days late.
• Should you anticipate difficulty in completing this work by the specified deadline, you should contact the Unit Coordinator via e-mail as soon as possible to discuss whether an extension may be granted. Note that extensions will not normally be granted very close to the due date or without suitable grounds. Also, other than in exceptional circumstances, the amount of extra time that can be granted will normally be quite limited. If you have been granted an extension, you must include a printed copy of the e-mail confirming the extension with your assignment submission.
You should keep a copy of all your work.
Assignment Sections:
Your assignment must contain the following components either in the documentation or as separate electronic files, where indicated:
• 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.
• Structure chart for your program. Show parameter passing.
• Your algorithm written in a uniform fashion using a pseudocode or a similar style and adhering to the conventions required in the unit. Your algorithm should be presented at an appropriate level of detail sufficient to be easily implemented. Submit your high- level algorithm (where necessary) along with algorithms of your decompositions 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.
• 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.
• Source code files (.c, .cpp, and/or .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.
• Results of applying your test data to your final program (tabular form), including a sample printout of your program in operation.
• Self-assessment of how successful you were in achieving the requirements and a discussion of any problems you encountered. This write up is done in this document template. You need to also submit a separate file evaluation.txt. This file will have, in point form, a summary of what works and what does not work in your program. A false claim here would mean that marks for this component would not be awarded. So make sure that you have tested your program thoroughly. The file evaluation.txt will also declare if you have checked each submitted file for viruses or malware. Name the tool and version number of the tool that you used to conduct the check. If the checks for viruses/malware are not made and the declaration is not shown in evaluation.txt, this assignment will not be marked and no marks will be given to you. Any delay that results from virus or malware will incur the specified daily penalty for the assignment.
Please submit the printed sections in order as shown in the assignment template in this document. Marks may be lost otherwise.
Question
This question extends assignment 1. Assignment 1 was a simplified version of this assignment. 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. If you did not do well in assignment 1, assignment 2 would enable you to apply lessons learned.
Before attempting this question, please complete the prerequisites listed on the first page of this document.
Like Assignment, Assignment 2 uses structured design implemented in C. In Assignment 2, Array of records (structs) with file I/O is needed.
The program takes two inputs at a time. The name of a person, and, the coin value as an integer in the range 5 to 95. Input coin values should always be divisible by 5 (integer division). Names are one word strings. An example input is:
Jane 30
This input line indicates that 30 cents change is to be given to Jane.
Output change values need to be in multiples of 50, 20, 10 and 5 cents. The program should aim to give as much of the higher valued coins as possible. A poor solution for an input of 30 cents is to give six 5 cent coins. A better solution is to give a 20 cent coin and a 10 cent coin.
Input to the program comes from a data file called coins.txt. There can be 0 and up to 10 input lines like the example above. It is also possible to have the same name repeated in the data file but the coin values can be different. When the name is the same, it would mean the same individual. If the name is the same, your program would need to add up the coin amounts to obtain a total amount for that individual before computing the change to be given.
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. 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.
1. Enter name
2. Exit
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 30 cents Change: 20 cents: 1 10 cents: 1 Change values of 0 are not shown.
If the user enters a non-existent name (e.g. Donald) at menu option 1, and therefore would not be in the array of records, your program will print:
Name: Donald
Not found
After the process output for menu option 1, the menu is redisplayed.
If the user enters 2 to exit, your program will write the coin and change data in CSV format to file called change.csv. After writing the data to the file your program will exit. In change.csv, the data line for Jane will look like the following, with each value separated by a comma and the line is terminated by newline:
Jane,30,0,1,1,0
Each data line in change.csv will be in the format:
name of person,total coin value,number of 50 cent coins, number of 20 cent coins,number of 10 cent coins,number of 5 cent coins newline.
So in the example output, Jane has 30 cents in one 20 cent coin and one 10 cent coin. There are no 50 or 5 cent coins.
The output data file change.csv cannot have repeated names.
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. Your solution (program and algorithm) should be modular in nature.
This requires the submission of a structure chart and a high-level algorithm and suitable decompositions of each step.
Note that for this problem, the principle of code reuse is particularly 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 a similar task (or have a lot of code that is repeated in the functions) then attempt to analyse your design to generalise the logic so that you have just one general version of the function (module).
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.
When submitting the assignment, delete this and all previous pages.
Assignment submission template is on the next page.
ICT159 Assignment 2
• Assumptions
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.
• First assumption
• Second assumption
• …
• Structure Chart
Structure chart for your program. Show parameter passing.
• Algorithm
Your algorithm written in a uniform fashion using a pseudocode or a similar style and adhering to the conventions required in the unit. Your algorithm should be presented at an appropriate level of detail sufficient to be easily implemented. Submit your high- level algorithm (where necessary) along with algorithms of your decompositions 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.
….
•
• Test Table
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.
Add rows to the following table as needed. Table can span more than one page. Each test id tests only one condition for the desk check.
For this assignment, there can be up to 10 records in a data file. In the test table below, you might have one test id for 10 records. So the actual 10 records must be in one cell of the test table in the column Actual data. Of course there are other test conditions and you need to include those too.
Test id
Test description/justification – what is the test for and why this particular test.
Actual data for this test
Expected output
Actual desk check result when desk check is carried out
Desk check outcome – Pass/Fail
1
2
3
4
•
• Code
Name and purpose of functions/modules in the source code files. Do not put actual source code here. Code exists as separate source code files that are submitted. Source code files (.c, .cpp, and/or .h) must be submitted separately 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.
Extend the following table as needed. Functions/modules need to match what is in the structure chart. If it is the same file name for a number of functions/modules, you write the file name once in the File name column for the first function/module listed in the table.
File name
Name of Functions/modules in the file
Purpose of the Function/module
•
• Results of Program Testing
Results of applying your test data to your final program (tabular form), including a sample printout of your program in operation.
Add rows to the following table as needed. Table can span more than one page.
Each test id tests only one situation for the test run of the program. Table is copy/paste of the desk check with actual output column showing results of the program output. There should be no duplicated reasons listed in the second column.
Test id
Test description/justification – what is the test for and why this particular test.
Actual data for this test
Expected output
Actual program output when test is carried out
Test run outcome – Pass/Fail
1
2
3
4
After the above test table, copy/paste sample printouts of your program in operation. You can screen capture and paste here. Make sure you label each printout with the correct Test id.
•
• Self Assessment
Self-assessment of how successful you were in achieving the requirements and a discussion of any problems you encountered. This write up is done in this document in the space provided below. You need to also submit a separate file evaluation.txt. A false claim in evaluation.txt would mean that marks for this component would not be awarded. So make sure that you have tested your program thoroughly.
Write your self-assessment here. Use as much space as needed. Describe how well your solution meets the requirements. Explain how you can improve your solution. Discuss problems you encountered and how you resolved them.
Submit a separate file called evaluation.txt. This file has two headings and you enter the required summary as dot points under the headings. The first heading is “What works” and the second heading is “What does not work”. Do not make any false claims as marks for this component may not be awarded. Testing should be thorough.
The file evaluation.txt will also declare if you have checked each submitted file for viruses or malware. Name the tool and version number of the tool that you used to conduct the check. If the checks for viruses/malware are not made and the declaration is not shown in evaluation.txt, this assignment will not be marked and no marks will be given to you. Any delay that results from virus or malware will incur the specified daily penalty for the assignment. Advice on how to do a malware scan is under Unit Info or Essential Resources at the LMS site for this unit.