Homework II

RequirementsThe taskExample solution

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.

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.

When testing the program, you must

  1. Test using stream redirection with the supplied inputs
  2. 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.

Report

You must submit a detailed report on the solution you made. The quality of the report is a part of the homework points.

The report must adhere to the IT faculty’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 https://blue.pri.ee/ttu/resources/report-guidelines/

The report should be reasonable and manageable in terms of both language and length for both the writer and the reader. 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.

Use the homework 1 template as the basis for your report (https://blue.pri.ee/ttu/programming-i/homework-i/) and adapt it to fit the requirements of this homework. The report chapters evolve over time with your skills and changing focus of the work.

Report content

Your report should contain the following sections

  • Title page
  • Declaration of originality
  • List of abbreviations and terms (if needed)
  • Table of contents
  • List of figures and tables (if needed)
  • Task description and variant
  • Description of the solution
    • Written text should be 2 .. 4 A4 pages long, not including figures. The description must be clearly structured.
    • What is the purpose of your program? What does it do?
    • Explain the program’s input (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).
    • Program workflow (be brief and generic, present as a list)
    • Algorithm modeled as UML activity diagram. Include only 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.
    • Special situation analysis (simplified risk analysis)
      • Must include problem’s ID, description, status and, if applicable, a solution or an idea how it could be solved.
      • Reminder: Solving all problems might be beyond your current skill level. Main priority is to be aware of the potential issues.
  • Use of AI
  • Summary
    • Write a few sentences about your approach to the assignment and your work process.
    • Write a few sentences about the assignment and how difficult it was for you
    • If possible, give an estimate on the workload
    • Would you recommend using this assignment in the future? Would you change anything, and if so, what?
    • Additional comments, emotions, thoughts
  • References (if needed)
  • Appendix: Screen capture(s) of the working program
    • You must show your program running with stream redirection. Leave the executed command visible on at least one of the figures.
    • Screen captures should illustrate various situations that your program can handle, as well as the normal behavior.
    • Screenshots can be added as an appendix or included in the description of the solution – in this case you can extend the length by the amount of figures.

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.

Requirements for input

Your program may be used in two ways

  1. Through input stream redirection. This will affect the requirements for the order of inputs that your program must accept. More information about this under “input file structure”.
  2. By executing your program normally and typing input using the keyboard. This requires clear prompts and feedback for the user.

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.

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.

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.

Input file structure

The first number in the input file describes the number of array members following it. If it’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.

Example of an input file for finding the average grade: 9 1 0 4 5 5 3 5 4 2

The first number 9 indicates how many grades will follow, after which there will be 9 grades.

Requirements for the standards and environment

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.

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.

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  (Ubuntu Linux 26.04, using GCC-15 compiler or later). Compatibility with other operating systems (Windows, MacOS) is not required.

Program requirements

Your code must adhere to the practices covered so far. In addition, the following requirements must be met

  • There are no goto  statements, global variables in your code
  • Your program must read the input from stdin  standard stream. Your program will be tested both by running it with stream redirection and directly typing the inputs on the keyboard.
  • There are no unused components – e.g. libraries, variables, ..
  • Code is divided into functions
    • Compose your functions based on the practices learned and follow the coding style requirements
    • No function, including the main function, may contain  spaghetti code
    • The main()  function must be the first function in your code file. All user-defined functions should be placed after the main function
    • You can also use a header file if you wish
  • Code must adhere to the coding style requirements

Extra task for bonus points

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.

To earn bonus points, the following requirements must be met in addition to the basic requirements

  • The application must support the following command line arguments
    • -i=file_name  and  --input=file_name – Program reads the input from the given file and prints the results immediately.
    • -p=interactive  and  --prompt=interactive  – Program reads input from  stdin  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.
    • -p=disabled  and  --prompt=disabled  – Program reads input from  stdin  standard stream. The program must not present the user with any prompts for input. Only the results are displayed.
    • --help  – Prints a guide how to use the program using the classical help page structure and style (Some examples:   grep --help  and  man grep )
  • The program must not break down if the user enters a string instead of an integer.
  • Add a top-level numbered heading to the report called “Extra task”
    • Describe the added features
    • Describe how you approached adding and checking the command line arguments
    • Describe how you decided what was important to be displayed on the help page
    • Explain your approach to input validation so that the program wouldn’t break on invalid input.

Deadlines, points and bonuses

A complete homework assignment must be submitted no later than 13.12.2026 23:59:59 (local time)

One point will be deducted from the final homework score for each day past the deadline.

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.

If necessary, we will enforce the rules and guidelines of [Procedure for processing a student’s violation of academic practices and contemptible behavior in the School of Information Technologies]

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.

Submitting Your work

You need to submit the documentation in  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.

Naming schema: HW2_lastname_studentcode.  Example:

HW2_Smith_123456MVEB_code.c
HW2_Smith_123456MVEB_report.pdf
HW2_Smith_123456MVEB_inputs.zip

Homework is submitted through Moodle.

Results and feedback

Once your work has been checked, you will find your points and feedback in Moodle. If everything was done well, feedback may be absent.

Fixing your homework

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.

Revised homework must be defended.

To revise your homework, first review the feedback on your work. Then contact the lecturer to agree on the revision process.

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.

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.

Click me to see the example code

The example does not fully comply with the requirements. E.g. the input validation in some places is too relaxed.

Click me to see the example algorithm

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’t need to include anything from the extra task requirements (e.g. processing of command line arguments).

Examples of testing

To test this, I’m going to use multiple test files to check if my conditions work as expected.

Test 1: Expected inputs, running with stream redirection

Test inputs

Testing process with output
Test 2: Test inputs outside of the allowed range, running with stream redirection

Test inputs

Testing process with output
Test 3: Inputs from the keyboard

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.