{"id":1932,"date":"2026-10-13T12:00:40","date_gmt":"2026-10-13T10:00:40","guid":{"rendered":"http:\/\/www.blue.pri.ee\/ttu\/?page_id=1932"},"modified":"2026-11-06T15:58:31","modified_gmt":"2026-11-06T13:58:31","slug":"homework-ii","status":"publish","type":"page","link":"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/","title":{"rendered":"Homework II"},"content":{"rendered":"<div class=\"su-tabs su-tabs-style-default su-tabs-mobile-stack\" data-active=\"1\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-tabs-nav\"><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">Requirements<\/span><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">The task<\/span><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">Example solution<\/span><\/div><div class=\"su-tabs-panes\"><div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"Requirements\">\n<p>For homework 2, you must create a software solution to solve a problem according to your individual task variant and the requirements listed on this page. The solution must be documented.<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Report\" >Report<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Report_content\" >Report content<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Requirements_for_input\" >Requirements for input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Input_file_structure\" >Input file structure<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Requirements_for_the_standards_and_environment\" >Requirements for the standards and environment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Program_requirements\" >Program requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Extra_task_for_bonus_points\" >Extra task for bonus points<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Deadlines_points_and_bonuses\" >Deadlines, points and bonuses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Results_and_feedback\" >Results and feedback<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-ii\/#Fixing_your_homework\" >Fixing your homework<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>This assignment focuses on identifying and analyzing erroneous situations in greater depth, finding solutions where possible, and documenting them. The programming aspects of the task focus on task decomposition, using arrays and handling potential erroneous situations.<\/p>\n<p>When testing the program, you must<\/p>\n<ol>\n<li>Test using stream redirection with the supplied inputs<\/li>\n<li>Make sure that all outputs from the program are understandable when the program is executed normally and all inputs are written manually by the user based on guidance given by your program.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Report\"><\/span>Report<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You must submit a detailed report on the solution you made. The quality of the report is a part of the homework points.<\/p>\n<p>The report must adhere to the IT faculty&#8217;s thesis guidelines. Most faculties use the same or similar principles with minor alterations. We have prepared a shortened guide (non-complete, reduced to only cover relevant sections) for you to follow <a href=\"https:\/\/blue.pri.ee\/ttu\/resources\/report-guidelines\/\"><strong>https:\/\/blue.pri.ee\/ttu\/resources\/report-guidelines\/<\/strong><\/a><\/p>\n<p><strong>The report should be reasonable and manageable in terms of both language and length for both the writer and the reader.<\/strong> Avoid unnecessarily complicated wording (i.e. terms you would struggle to understand yourself) and describing activities in a more elaborate way than their actual complexity warrants.<\/p>\n<p>Use the homework 1 template as the basis for your report (<a href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-i\/\">https:\/\/blue.pri.ee\/ttu\/programming-i\/homework-i\/<\/a>) and adapt it to fit the requirements of this homework. <strong>The report chapters evolve over time with your skills and changing focus of the work.<\/strong><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Report_content\"><\/span>Report content<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Your report should contain the following sections<\/p>\n<ul>\n<li>Title page<\/li>\n<li>Declaration of originality<\/li>\n<li>List of abbreviations and terms (if needed)<\/li>\n<li>Table of contents<\/li>\n<li>List of figures and tables (if needed)<\/li>\n<li>Task description and variant<\/li>\n<li>Description of the solution\n<ul>\n<li>Written text should be 2 .. 4 A4 pages long, not including figures. The description must be clearly structured.<\/li>\n<li><span style=\"font-style: inherit;\">What is the purpose of your program? What does it do?<\/span><\/li>\n<li>Explain the program&#8217;s input <em>(where does the input come from, what format must it be in, in which order are inputs expected and whether there are any limitations to input values)<\/em>.<\/li>\n<li><span style=\"font-style: inherit;\">Program workflow (<em>be brief and generic, present as a list<\/em>)<\/span><\/li>\n<li>Algorithm modeled as UML activity diagram. Include <b>only<\/b> the steps needed to process the data and achieve the result. Do not show reading of inputs or anything from the extra task requirements. See the example.<\/li>\n<li>Special situation analysis (simplified risk analysis)\n<ul>\n<li>Must include problem&#8217;s ID, description, status and, if applicable, a solution or an idea how it could be solved.<\/li>\n<li>Reminder: Solving all problems might be beyond your current skill level. Main priority is to be aware of the potential issues.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Use of AI<\/li>\n<li>Summary\n<ul>\n<li>Write a few sentences about your approach to the assignment and your work process.<\/li>\n<li>Write a few sentences about the assignment and how difficult it was for you<\/li>\n<li>If possible, give an estimate on the workload<\/li>\n<li>Would you recommend using this assignment in the future? Would you change anything, and if so, what?<\/li>\n<li>Additional comments, emotions, thoughts<\/li>\n<\/ul>\n<\/li>\n<li>References (if needed)\n<ul>\n<li>Use IEEE citation style<br \/>\nEnglish official reference:\u00a0<strong><a href=\"https:\/\/journals.ieeeauthorcenter.ieee.org\/wp-content\/uploads\/sites\/7\/IEEE_Reference_Guide.pdf\">https:\/\/journals.ieeeauthorcenter.ieee.org\/wp-content\/uploads\/sites\/7\/IEEE_Reference_Guide.pdf<\/a><br \/>\n<\/strong>Reference help by TalTech (in Estonian):\u00a0<strong><a href=\"https:\/\/haldus.taltech.ee\/sites\/default\/files\/2024-05\/IEEE_stiilis_viitamine_2024%20%281%29.pdf\">https:\/\/haldus.taltech.ee\/sites\/default\/files\/2024-05\/IEEE_stiilis_viitamine_2024%20%281%29.pdf<\/a><\/strong><\/li>\n<li>Cite everything that was not covered in this course and that you did not create independently.<\/li>\n<li>You must also cite help received from a friend or fellow student: <strong><a href=\"https:\/\/libraryguides.vu.edu.au\/ieeereferencing\/personalcommunication\">https:\/\/libraryguides.vu.edu.au\/ieeereferencing\/personalcommunication<\/a><\/strong><\/li>\n<li>The use of artificial intelligence must be cited in accordance with the university\u2019s rules<\/li>\n<li>References to sources must be specific. Generic references such as wikipedia.org, stackoverflow.com or google.com are not acceptable<\/li>\n<\/ul>\n<\/li>\n<li>Appendix: Screen capture(s) of the working program\n<ul>\n<li>You must show your program running with stream redirection. Leave the executed command visible on at least one of the figures.<\/li>\n<li>Screen captures should illustrate various situations that your program can handle, as well as the normal behavior.<\/li>\n<li>Screenshots can be added as an appendix or included in the description of the solution &#8211; in this case you can extend the length by the amount of figures.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Note: If you use techniques or language constructs that have not yet been covered in class, you must explain how they work and the advantages of using them in your solution. You may extend the solution description to accommodate these explanations.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Requirements_for_input\"><\/span>Requirements for input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Your program may be used in two ways<\/p>\n<ol>\n<li>Through input stream redirection. This will affect the requirements for the order of inputs that your program must accept. More information about this under &#8220;input file structure&#8221;.<\/li>\n<li>By executing your program normally and typing input using the keyboard. This requires clear prompts and feedback for the user.<\/li>\n<\/ol>\n<p>Your program must support dataset lengths of up to 15. This means that for 1-dimensional arrays, you may have up to 15 values and for 2-dimensional arrays you may have 15 x 15 values. Your task variant may include multiple arrays.<\/p>\n<p>Your assignment variant includes two text files with example inputs. These will be your first datasets that your program must work with. Your program must read the inputs in the same order as they are in the provided data files. Choose the data types for your program according to the data in the provided input files. You are expected to create additional test files to show handling of erroneous inputs. These will be submitted for grading alongside your solution.<\/p>\n<p>Part of your task will be to analyze and solve various situations that your program may come across. E.g. what happens if the user wants to enter only 1 input? -55 inputs? 100 inputs? Your program must be able to handle problematic inputs. At a minimum, it must gracefully handle inputs that are outside of the expected range, within the data type that is expected. The risk analysis chapter in the documentation must analyze for a wider range of inputs, but handling them in code is only expected when you submit the extra task.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Input_file_structure\"><\/span>Input file structure<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The first number in the input file describes the number of array members following it. If it&#8217;s a matrix, two numbers preceding the data define the dimensions. If the program also has other inputs, they will be listed after the last array member.<\/p>\n<p>Example of an input file for finding the average grade: <span class=\"lang:default highlight:0 decode:true crayon-inline \">9 1 0 4 5 5 3 5 4 2<\/span><\/p>\n<p>The first number 9 indicates how many grades will follow, after which there will be 9 grades.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Requirements_for_the_standards_and_environment\"><\/span>Requirements for the standards and environment<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The program must be written in the C programming language. By default, it is expected to comply with the C99 standard. Other standards (C90, C11, C17, C23) may be used if they provide added value. The justification must be included in the report.<\/p>\n<p>In addition to the standard C libraries, you are allowed to use C POSIX and GNU C libraries and extensions. The use of other libraries must be agreed upon in advance.<\/p>\n<p>Your solution will be compiled and tested in a Linux environment, equivalent to the one in the lab computers (OpenSUSE SLED-15 SP5, using GCC-12) or the recommendation for home setup\u00a0 (Ubuntu Linux 26.04, using GCC-15 compiler or later). Compatibility with other operating systems (Windows, MacOS) is not required.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Program_requirements\"><\/span>Program requirements<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Your code must adhere to the practices covered so far. In addition, the following requirements must be met<\/p>\n<ul>\n<li>There are no <span class=\"lang:c highlight:0 decode:true crayon-inline \">goto<\/span>\u00a0 statements, global variables in your code<\/li>\n<li>Your program must read the input from <span class=\"lang:c highlight:0 decode:true crayon-inline \">stdin<\/span>\u00a0 standard stream. Your program will be tested both by running it with stream redirection and directly typing the inputs on the keyboard.<\/li>\n<li>There are no unused components &#8211; e.g. libraries, variables, ..<\/li>\n<li>Code is divided into functions\n<ul>\n<li>Compose your functions based on the practices learned and follow the coding style requirements<\/li>\n<li>No function, including the main function, may contain\u00a0 spaghetti code<\/li>\n<li>The <span class=\"lang:c highlight:0 decode:true crayon-inline \">main()<\/span>\u00a0 function must be the first function in your code file. All user-defined functions should be placed after the main function<\/li>\n<li>You can also use a header file if you wish<\/li>\n<\/ul>\n<\/li>\n<li>Code must adhere to the coding style requirements<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Extra_task_for_bonus_points\"><\/span>Extra task for bonus points<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can earn up to 15 bonus points from this task. In order to get any points, you must document the added features in the report. It is possible to obtain partial bonus points if not all requirements are met, however only if the added features are documented in the report.<\/p>\n<p>To earn bonus points, the following requirements must be met in addition to the basic requirements<\/p>\n<ul>\n<li>The application must support the following command line arguments\n<ul>\n<li><span class=\"lang:c highlight:0 decode:true crayon-inline\">-i=file_name<\/span>\u00a0 and\u00a0 <span class=\"lang:c highlight:0 decode:true crayon-inline\">&#8211;input=file_name<\/span> &#8211; Program reads the input from the given file and prints the results immediately.<\/li>\n<li><span class=\"lang:c highlight:0 decode:true crayon-inline\">-p=interactive<\/span>\u00a0 and\u00a0 <span class=\"lang:c highlight:0 decode:true crayon-inline\">&#8211;prompt=interactive<\/span> \u00a0&#8211; Program reads input from\u00a0 <span class=\"lang:c highlight:0 decode:true crayon-inline\">stdin<\/span>\u00a0 standard stream. The program must clearly express what it requires from the user and print error messages as they happen. This is the default option.<\/li>\n<li><span class=\"lang:c highlight:0 decode:true crayon-inline\">-p=disabled<\/span>\u00a0 and\u00a0 <span class=\"lang:c highlight:0 decode:true crayon-inline\">&#8211;prompt=disabled<\/span>\u00a0 &#8211; Program reads input from\u00a0 <span class=\"lang:c highlight:0 decode:true crayon-inline\">stdin<\/span>\u00a0 standard stream. The program must not present the user with any prompts for input. Only the results are displayed.<\/li>\n<li><span class=\"lang:c highlight:0 decode:true crayon-inline\">&#8211;help<\/span>\u00a0 &#8211; Prints a guide how to use the program using the classical help page structure and style (Some examples: \u00a0<span class=\"lang:c highlight:0 decode:true crayon-inline\">grep &#8211;help<\/span>\u00a0 and\u00a0 <span class=\"lang:c highlight:0 decode:true crayon-inline\">man grep<\/span>\u00a0)<\/li>\n<\/ul>\n<\/li>\n<li>The program must not break down if the user enters a string instead of an integer.<\/li>\n<li>Add a top-level numbered heading to the report called &#8220;Extra task&#8221;\n<ul>\n<li>Describe the added features<\/li>\n<li>Describe how you approached adding and checking the command line arguments<\/li>\n<li>Describe how you decided what was important to be displayed on the help page<\/li>\n<li>Explain your approach to input validation so that the program wouldn&#8217;t break on invalid input.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Deadlines_points_and_bonuses\"><\/span>Deadlines, points and bonuses<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"color: #ff0000;\"><strong>A complete homework assignment must be submitted no later than 13.12.2026 23:59:59 (local time)<\/strong><\/span><\/p>\n<p>One point will be deducted from the final homework score for each day past the deadline.<\/p>\n<p>If we have additional questions about the homework or there are doubts about its authorship, the homework will receive 0 points until it has been successfully defended.<\/p>\n<p>If necessary, we will enforce the rules and guidelines of [<a href=\"https:\/\/haldus.taltech.ee\/sites\/default\/files\/2020-10\/Terviktekst_IT-teaduskonna%20\u00f5ppuri%20akad%20tavade%20rikkumise%20ja%20v\u00e4\u00e4ritu%20k\u00e4itumise%20menetlemise%20kord_ENG.pdf\">Procedure for processing a student\u2019s violation of academic practices and contemptible behavior in the School of Information Technologies<\/a>]\n<p><strong><span style=\"font-style: inherit; color: #ff0000;\">The lockdown date for submitting and defending the homework is specified on the introductory slides. Submitting your homework after that date will not be possible.<\/span><\/strong><\/p>\n<p><span style=\"font-size: 22px; font-weight: bold;\">Submitting Your work<\/span><\/p>\n<p>You need to submit the documentation in\u00a0 PDF format, all the necessary code files to compile your program and a zip archive with the test inputs, which should include additional inputs created by you.<\/p>\n<p data-select-like-a-boss=\"1\">Naming schema: HW2_lastname_studentcode.\u00a0 Example:<\/p>\n<p>HW2_Smith_123456MVEB_code.c<br \/>\nHW2_Smith_123456MVEB_report.pdf<br \/>\nHW2_Smith_123456MVEB_inputs.zip<\/p>\n<p>Homework is submitted through Moodle.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Results_and_feedback\"><\/span>Results and feedback<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Once your work has been checked, you will find your points and feedback in Moodle. If everything was done well, feedback may be absent.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Fixing_your_homework\"><\/span>Fixing your homework<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You are allowed to fix and improve your homework until the homework lockdown date. Be aware that if you submit your homework less than two weeks before the lockdown date, there may not be enough time for it to be graded and for you to make corrections.<\/p>\n<p>Revised homework must be defended.<\/p>\n<p>To revise your homework, first review the feedback on your work. Then contact the lecturer to agree on the revision process.<\/p>\n<p>NB! If revision requires changing more than half of the work, it will be treated as a new submission, and a late-submission penalty may be deducted based on the date the revision is submitted.<\/p>\n<\/div>\n<div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"The task\">\n\n<!-- iframe plugin v.6.0 wordpress.org\/plugins\/iframe\/ -->\n<iframe loading=\"lazy\" src=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/kodutoo\/homework2.html\" width=\"100%\" height=\"1150px\" scrolling=\"yes\" class=\"iframe-class\" frameborder=\"0\"><\/iframe>\n\n<\/div>\n<div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"Example solution\">\n<p>NB! This is only a partial example displaying some parts of the code structure, inputs, testing, algorithm and coding style. The submitted task must meet the complete requirements.<\/p>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Click me to see the example code<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<p>The example does not fully comply with the requirements. E.g. the input validation in some places is too relaxed.<\/p>\n<pre class=\"font-size:12 line-height:16 left-set:true left-margin:0 right-margin:0 nums:false nums-toggle:false wrap-toggle:false lang:c decode:true\">\/**\r\n * Author:          Risto Heinsar\r\n * Created:         23.10.2015\r\n * Modified:        06.11.2026\r\n * Description:     This snippet of code helps Nick Fury keep track of his\r\n *                  minions a little better.\r\n *\/\r\n\r\n#include &lt;stdio.h&gt;\r\n\r\n\/\/ Array limits\r\n#define MIN_AVENGERS 1\r\n#define MAX_AVENGERS 10\r\n#define MAX_NAME_LEN 16\r\n\r\n\/\/ Function prototypes\r\nint GetAvengerCount(int minVal, int maxVal);\r\nvoid GetMissionStats(char name[MAX_AVENGERS][MAX_NAME_LEN], int disposeCount[],\r\n                      int cnt);\r\ndouble CalcAvgBaddieDisposed(int disposeCount[], int cnt);\r\nvoid DisplaySlackers(char name[MAX_AVENGERS][MAX_NAME_LEN], int disposeCount[],\r\n                     int avengerCnt, double avgBaddiesDisposed);\r\n\r\nint main(void)\r\n{\r\n    char avengers[MAX_AVENGERS][MAX_NAME_LEN];\r\n    int disposeCount[MAX_AVENGERS];\r\n\r\n    \/\/ Get number of avengers participating in the mission\r\n    int avengerCount = GetAvengerCount(MIN_AVENGERS, MAX_AVENGERS);\r\n\r\n    \/\/ Collect mission statistics\r\n    GetMissionStats(avengers, disposeCount, avengerCount);\r\n \r\n    \/\/ Data processing and output\r\n    double avgBaddiesDisposed = CalcAvgBaddieDisposed(disposeCount, \r\n                                                      avengerCount);\r\n    DisplaySlackers(avengers, disposeCount, avengerCount, avgBaddiesDisposed);\r\n\r\n    return 0;\r\n}\r\n\r\n\/**\r\n * Description: Prompts for an integer within the allowed range. Only returns\r\n *              once user input is within the permitted range, otherwise prints \r\n *              an error and reprompts.\r\n * \r\n * Parameters:  minVal - lower limit for allowed range (inclusive)\r\n *              maxVal - upper limit for allowed range (inclusive)\r\n * \r\n * Return:      Integer in range of minVal and maxVal\r\n *\/\r\nint GetAvengerCount(int minVal, int maxVal)\r\n{\r\n    int count;\r\n    \r\n    do\r\n    {\r\n        printf(\"Enter avenger count between %d and %d\\n\", minVal, maxVal);\r\n        scanf(\"%d\", &amp;count);\r\n        \r\n        \/\/ Print an error for invalid input\r\n        if (count &lt; minVal || count &gt; maxVal)\r\n            puts(\"I'm sorry, I can't handle that :(\");\r\n    }\r\n    while (count &lt; minVal || count &gt; maxVal);\r\n    \r\n    return count;\r\n}\r\n\r\n\r\n\/**\r\n * Description: Populates the mission stats - the names of avengers who were\r\n *              on the mission and how many baddies they disposed of. Assumes\r\n *              both arrays use the same index for corresponding values.\r\n * \r\n * Parameters:  name - Array of strings for avenger names\r\n *              disposeCount - number of baddies disposed of by each avenger\r\n *              cnt - number of avengers on the mission\r\n * \r\n * Return:      none\r\n *\/\r\nvoid GetMissionStats(char name[MAX_AVENGERS][MAX_NAME_LEN], int disposeCount[],\r\n                      int cnt)\r\n{\r\n    for (int i = 0; i &lt; cnt; i++)\r\n    {\r\n        printf(\"Enter the name and disposed of count for avenger %d: \", i + 1);\r\n        scanf(\"%s %d\", name[i], &amp;disposeCount[i]);\r\n    }\r\n}\r\n\r\n \r\n\/**\r\n * Description: Finds the average number of baddies disposed on a mission\r\n *              per avenger.\r\n * \r\n * Parameters:  disposeCounts - number of baddies disposed of by each avenger\r\n *              cnt - number of avengers on the mission\r\n * \r\n * Return:      number of baddies disposed of on average\r\n *\/\r\ndouble CalcAvgBaddieDisposed(int disposeCount[], int cnt)\r\n{\r\n    int sum = 0;\r\n    \r\n    \/\/ Find the total baddies disposed of\r\n    for (int i = 0; i &lt; cnt; i++)\r\n    {\r\n        sum += disposeCount[i];\r\n    }\r\n    \r\n    \/\/ Returns the average\r\n    return ((double)sum \/ (double)cnt);\r\n}\r\n\r\n\/**\r\n * Description: Prints the mission statistics, finds the avengers who were\r\n *              goofing off and reports them to Fury.\r\n * \r\n * Parameters:  name - 2D array for avenger names\r\n *              disposeCount - number of baddies disposed of by each avenger\r\n *              avengerCnt - number of avengers on the mission\r\n *              avgBaddiesDisposed - average number of baddies disposed of by \r\n *                                   one avenger during the mission\r\n * \r\n * Return:      -\r\n *\/\r\nvoid DisplaySlackers(char name[MAX_AVENGERS][MAX_NAME_LEN], int disposeCount[],\r\n                     int avengerCnt, double avgBaddiesDisposed)\r\n{\r\n    printf(\"The total number of avengers on mission was %d\\n\", avengerCnt);\r\n    printf(\"Average baddies disposed of was: %lg\\n\\n\", avgBaddiesDisposed);\r\n    \r\n    printf(\"The following avengers were slacking off:\\n\");\r\n    \r\n    \/\/ Go through the list of avengers\r\n    for (int i = 0; i &lt; avengerCnt; i++)\r\n    {\r\n        \/\/ Print if the avenger disposed of fewer baddies than the average\r\n        if (disposeCount[i] &lt; avgBaddiesDisposed)\r\n        {\r\n            printf(\"%15s %3d\\n\", name[i], disposeCount[i]);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Click me to see the example algorithm<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<p>The algorithm expects you to show the steps required for data processing and achieving the required results. Do not include reading or validating inputs. You also don&#8217;t need to include anything from the extra task requirements (e.g. processing of command line arguments).<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/11\/avengers_en.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10899\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/11\/avengers_en.png\" alt=\"\" width=\"994\" height=\"754\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/11\/avengers_en.png 994w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/11\/avengers_en-300x228.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/11\/avengers_en-768x583.png 768w\" sizes=\"auto, (max-width: 994px) 100vw, 994px\" \/><\/a><\/p>\n<\/div><\/div>\n<h5>Examples of testing<\/h5>\n<p>To test this, I&#8217;m going to use multiple test files to check if my conditions work as expected.<\/p>\n<h5>Test 1: Expected inputs, running with stream redirection<\/h5>\n<p>Test inputs<\/p>\n<pre class=\"toolbar:2 lang:c decode:true\" title=\"HW2_Risto_Heinsar_012345ABCD_test1.txt\">4\r\nHulk 19\r\nThor 4\r\nCpt.America 12\r\nHawkeye 6<\/pre>\n<p>Testing process with output<\/p>\n<pre class=\"theme:cisco-router toolbar:2 nums:false lang:c highlight:0 decode:true\">risto@risto-wk-tux:~\/git\/IAX0583\/HW2$ .\/HW2_Heinsar_112233IASB &lt; tests\/test_1_valid_inp \r\nEnter avenger count between 1 and 10 \r\nEnter the name and disposed of count for avenger 1:\r\nEnter the name and disposed of count for avenger 2:\r\nEnter the name and disposed of count for avenger 3:\r\nEnter the name and disposed of count for avenger 4:\r\nTotal number of avengers in mission was 4\r\nAverage baddies disposed of was: 10.25\r\n\r\nThe following avengers were slacking off:\r\n           Thor   4\r\n        Hawkeye   6\r\n<\/pre>\n<h5>Test 2: Test inputs outside of the allowed range, running with stream redirection<\/h5>\n<p>Test inputs<\/p>\n<pre class=\"toolbar:2 lang:c decode:true\" title=\"HW2_Risto_Heinsar_012345ABCD_test2.txt\">19\r\n0\r\n-5\r\n5\r\nFalcon 2\r\nHulk 24\r\nThor 3\r\nCpt.America 5\r\nHawkeye 21\r\n<\/pre>\n<p>Testing process with output<\/p>\n<pre class=\"theme:cisco-router toolbar:2 nums:false lang:c highlight:0 decode:true\">risto@risto-wk-tux:~\/git\/IAX0583\/HW2$ .\/HW2_Heinsar_112233IASB &lt; tests\/test_2_err_range\r\nEnter avenger count between 1 and 10 \r\nI'm sorry, I can't handle that :(\r\nEnter avenger count between 1 and 10 \r\nI'm sorry, I can't handle that :(\r\nEnter avenger count between 1 and 10 \r\nI'm sorry, I can't handle that :(\r\nEnter avenger count between 1 and 10 \r\nEnter the name and disposed of count for avenger 1:\r\nEnter the name and disposed of count for avenger 2:\r\nEnter the name and disposed of count for avenger 3:\r\nEnter the name and disposed of count for avenger 4:\r\nEnter the name and disposed of count for avenger 5:\r\nTotal number of avengers in mission was 5\r\nAverage baddies disposed of was: 11\r\n\r\nThe following avengers were slacking off:\r\n         Falcon   2\r\n           Thor   3\r\n    Cpt.America   5\r\n<\/pre>\n<h5>Test 3: Inputs from the keyboard<\/h5>\n<p>This example does not include an input file, the input is directly written on the keyboard. The prompts and output of the program must be clear to the user.<\/p>\n<pre class=\"theme:cisco-router toolbar:2 nums:false lang:c highlight:0 decode:true \">risto@risto-wk-tux:~\/git\/IAX0583\/HW2$ .\/HW2_Heinsar_112233IASB\r\nEnter avenger count between 1 and 10 \r\n3\r\nEnter the name and disposed of count for avenger 1:\r\nHulk 15\r\nEnter the name and disposed of count for avenger 2:\r\nThor 30\r\nEnter the name and disposed of count for avenger 3:\r\nFalcon 5\r\nTotal number of avengers in mission was 3\r\nAverage baddies disposed of was: 16.6667\r\n\r\nThe following avengers were slacking off:\r\n           Hulk  15\r\n         Falcon   5\r\n\r\n<\/pre>\n<h5><span style=\"font-size: 16px; font-weight: 400;\"><\/div><\/div><\/div><\/span><\/h5>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":1425,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"page-templates\/code-width-wide.php","meta":{"footnotes":""},"class_list":["post-1932","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/1932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/comments?post=1932"}],"version-history":[{"count":18,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/1932\/revisions"}],"predecessor-version":[{"id":11834,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/1932\/revisions\/11834"}],"up":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/1425"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=1932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}