Skip to content

Assignment 3: ID, Kendall, Max, CountingSort

Deadline

5 March 2021 (Friday), 4pm. (Note that due date is in Week 7 instead of the recess week. However, you are encouraged to complete this assignment early since Week 7 is the midterm/PE week.)

Prerequisite

  • You are able to access the CS1010 programming environment.
  • You are familiar with basic UNIX CLI and using terminal-based editor vim.
  • You have gone through Exercise 0 and have already set up your .gitconfig.
  • You are familiar with the steps of accepting, downloading, and submitting your exercise and assignment.
  • You are familiar with the directory structure and the common files included in your assignment skeleton.
  • You are comfortable writing simple C programs that involve arithmetic operations, long, double, and bool types, conditional if/else statements, loops, pointers, and arrays.
  • You are comfortable breaking down a problem into smaller sub-problems which can be resolved using functions, including reusing existing functions written for other programs (with a tweak), writing a function that calls itself, designing what should the inputs and return values/types of a function.

Learning Objectives

  • Be comfortable writing C programs that involve using one-dimensional arrays.
  • Be able to write C programs that are neat and readable, adhering to a common prescribed coding convention.

Setup

1
~cs1010/get-as03
  • You should see the folder as03-<github username> in your home directory with the assignment skeleton inside.
  • Inside that directory, you should see the following files:
    • id.c, kendall.c, max.c, and countingsort.c are the most important files. They are the skeleton C code that you should edit to solve the assignment and the only files that you should change.
    • inputs and outputs are subdirectories that contain test inputs and test outputs. We use the same convention as Exercise 0 so you should already be familiar with them.
    • Makefile: This is the configuration for the tool make that we use to automate the compilation and testing of the programs.
    • test.sh: This is a bash script for testing your code.
    • compile_flags.txt: This file specifies the flags for compilation and is used by both make and clang-tidy.
    • questions.md contains the description of the questions. This is a plain text file that you can view with vim, less, or other tools.

Solving The Assignments

  • Edit the files id.c, kendall.c, max.c, and countingsort.c to solve the corresponding question as described below.
  • To compile and run tests with the sample inputs and outputs:

    1
    make
    
    This command will compile all your C files with the appropriate settings and if there is no error, run the test scripts. If you pass the test cases, it will run clang-tidy to check if your code follows good code practices.

  • The test cases are given in the inputs and outputs subdirectory. You can use cat or less to look at the content of these test cases. You can add more test cases or edit the given ones if needed.

  • To compile individial program, type

    1
    make <program>
    
    For instance, the command
    1
    make echo
    
    compiles echo.c into echo without testing or running clang-tidy on it.

  • To test individial program, run

    1
    ./test.sh <program>
    

    For instance, the command

    1
    ./test.sh echo
    
    tests echo without compiling or running clang-tidy on echo.c.

Submission

When you are ready, run the following command to submit:

1
~cs1010/submit-as03

The four files id.c, max.c, kendall.c, and countingsort.c will be uploaded to GitHub. You can submit multiple times, but only the last submission will be graded.

Manipulating Files on GitHub

Do not manipulate (e.g., edit) the files on GitHub or close the pull requests on GitHub. Doing so would interfere with the scripts and the grading/testing process of CS1010.

Extra Files

You do not need to create extra files to solve this assignment. If you write your code on additional files not listed above, it will not be submitted.

Identifying Yourself

In every C file that you submit to CS1010, you need to identify yourself by writing your name and tutorial group. Marks will be deducted if you fail to do so. You need to edit the line:

1
@author XXXX (Group YYYY)

and change it to something like:

1
@author  Philippa Georgiou (Group D10)

Grading

This assignment contributes towards 3% of your final grade. The total marks for this assignment are 30 marks. For Programming Assignment 3,

  • 1 mark is allocated to style. This is an almost free mark -- as long as the code is neat and readable, and adhere to CS1010 coding convention, you will get this 1 mark.

  • 1 mark is allocated to efficiency for countingsort. Your code should not waste time by doing redundant work.

  • The rest of the marks are allocated to correctness -- this includes the correctness of syntax, practices, approach, and logic, and whether you correctly follow our instructions. Note that even if your solution produces the correct output every time, it may not get full marks if the approach is wrong.

Calling free

Remember to call free on arrays returned by the CS1010 I/O library.

Questions

To acclimatize you to the PE1 condition, the questions for this assignment is included in the skeleton instead, in a file named questions.md.

You should learn how to use vim to open both the .c file and the questions.md side-by-side (see https://nus-cs1010.github.io/2021-s1/vim.html#splitting-vims-viewport)