Through this guided project, we want to see how you implement a command-line (CLI) program that lets you manage your tasks.
The specification for this problem is written down as tests. Since we haven’t actually implemented anything, the tests are currently failing. You have to solve the problem by implementing the application and getting all the tests to pass.
The capstone project guides you through the implementation of a command-line todo application. The application allows users to jot down their tasks with an associated priority, list them, delete them, mark them as done, and generate completion reports. Pending tasks should be stored in a file called task.txt
text file. Each task occupies a single line in this file. Each task should have an associated priority, an integer. Completed tasks are to be written to a done.txt
text file.
The code for this capstone project has been partially implemented with the necessary APIs to facilitate its completion. The following commands are to be implemented:
-
The command
./task ls
lists all the tasks fromtasks.txt
, which are assumed to be pending. -
The command
./task report
lists all tasks fromtasks.txt
anddone.txt
files, which indicates both the pending as well as the completed tasks. -
The command
./task add 2 Complete Python assignment
adds a new task intotasks.txt
, along with its associated priority as Complete Python assignment [2] -
The command
./task del INDEX
deletes the task at line 3 from thetask.txt
file. -
The command
./task done INDEX
marks the task at line 3 in thetask.txt
file as done, by moving the task line to thedone.txt
file.
The partial implementation will provide function APIs to perform specific operations. For instance, to complete the ./task ls
command’s implementation, the relevant task_add()
function is defined with an empty function definition. The logic for this function body should be implemented. Furthermore, function APIs are also available to perform elementary operations such as reading and writing lines from text files. These APIs must be used to complete the implementation.
The subsequent sections detail the end-user perspective (Usage) and the programmer perspective (Specification) of the project. Following this, the instructions to obtain the starter code locally, run them, and build atop the existing boilerplate to complete the project are described as independent goals.
-
The app can be run in the console with
./task
. -
The app should read from and write to a
task.txt
text file. Each task occupies a single line in this file. Each task should have an associated priority, an integer.
Priority denotes how important a task is. If it is a high priority task, it should be completed earlier. Priority is denoted using an integer. The lower the number, the higher the priority.
Here is an example of a list of 2 tasks in the file.
1 Prepare for CAT tests [2]
2 Complete Mini-Project [5]
-
Completed tasks are to be written to a
done.txt
text file. Each task line in this file should enapsulate all fields of the original task. -
Priority can be any integer greater than or equal to 0. 0 denotes the highest priority.
-
If two tasks have the same priority, the task that was added first should be displayed first.
The application must open the files
task.txt
anddone.txt
from where the app is run, and not where the app is located.For instance,
In,
$ cd /path/to/plans $ /path/to/apps/task ls
The application should look for the task files in
/path/to/plans
, since that is the user’s current directory. -
The files should always be sorted in order of the priority, i.e., the task with the highest priority should be first item in the file.
Please note that the programming task can and preferably, should be completed without the use of any additional packages.
Executing the command without any arguments, or with a single argument help prints the CLI usage.
$ ./task help
Usage :-
$ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list
$ ./task ls # Show incomplete priority list items sorted by priority in ascending order
$ ./task del INDEX # Delete the incomplete item with the given index
$ ./task done INDEX # Mark the incomplete item with the given index as complete
$ ./task help # Show usage
$ ./task report # Statistics
Use the ls command to see all the items that are not yet complete, in ascending order of priority.
Every item should be printed on a new line. with the following format
[index] [task] [priority]
Example:
$ ./task ls
1. Prepare for Practical Exams [2]
2. Complete Mini-Project [5]
index starts from 1, this is used to identify a particular task to complete or delete it.
Use the add command. The text of the task should be enclosed within double quotes (otherwise only the first word is considered as the item text, and the remaining words are treated as different arguments).
$ ./task add 5 "Buy textbook"
Added task: "Buy textbook" with priority 5
Tasks may have the same task text, leading to potential duplicates. De-duplication is not a focus of this implementation.
Use the del command to remove an item by its index.
$ ./task del 3
Deleted item with index 3
Attempting to delete a non-existent item should display an error message.
$ ./task del 5
Error: item with index 5 does not exist. Nothing deleted.
Use the done command to mark an item as completed by its index.
$ ./task done 1
Marked item as done.
Attempting to mark a non-existed item as completed will display an error message.
$ ./task done 5
Error: no incomplete item with index 5 exists.
Show the number of complete and incomplete items in the list. and the complete and incomplete items grouped together.
$ ./task report
Pending : 2
1. this is a pending task [1]
2. this is a pending task with priority [4]
Completed : 3
1. completed task
2. another completed task
3. yet another completed task
-
Login to your GitHub account.
-
Access the repository from the project starter page.
-
Follow the instructions here to
fork
the repository to your local desktop.
On a command line terminal,
-
git clone <YOUR-REPOSITORY-URL>
The git clone command copies your repository from GitHub to your local computer. Note that this is a git specific command.
-
cd C-Programming-Course_Project-Starter
Move into your repository's local copy.
-
Edit your code files here.
-
When you think you have made a good amount of progress, add your files, and commit your code.
git add . git commit -m <SHORT-MSG-INDICATING-WHAT-PROGRESS-YOU'VE-MADE>
-
When you are done for the day, push your code to GitHub.
git push origin
-
You should have a C compiler available for building the code.
-
You are expected to write the code in
task.c
file. -
You should be able to build the app by running
make task
. -
Once you are done with the changes you should be able to execute the task app by running the following command from the terminal.
On Windows:
.\task.exe
On *nix:
./task
- Follow the instructions in the Getting Started section to get the boilerplate code, and get it running on your local systems.
-
The usage section details the end-user interface. Understand how the CLI tool will be used by a user who gets your software.
-
The specification section details how you should actually implement each functionality, what happens in the background. This is your logic.
- Take a look at all the helper functions, interfaces, and structures in the source file. Simply try to understand what each function does: its input and output.
Start from the
main()
function, and trace your way through the function calls.
-
Start with the first use-case in the usage section.
-
Find the relevant portion of the code (start looking from
main()
!) and write your code to make appropriate function calls and/or operations to implement it. -
Compile and Run frequently, to ensure that you are headed in the right direction.
-
Got one case running? Great! - Let us know.
(implement-execute-test and repeat for the rest of the use-cases).
- Include an additional
date_of_completion
field that records when the task is marked as done.
The functions to get the current date and time, in the required character-array format, are already provided as helpers!
-
Follow the instructions in the Run Automated Tests section to run automated tests, that wil evaluate multiple edge-cases of your application.
-
Again, implement-execute-test and repeat for each use case.
If you are able to set up npm by following the steps below, great! You can validate that your app works as expected.
Otherwise, we'll do this for you, when we are evaluating the project. In addition to the test cases mentioned here, we'll add on a few more during the evaluation.
You need to have npm
installed in your computer for the following steps. It comes with Node.js and you can get it by installing Node from https://nodejs.org/en/
Run npm install
to install all dependencies.
To create a symbolic link on Windows, you'll need to run either the Windows Command Prompt, or Windows Powershell with administrator privileges. To do so, right-click on the icon for Command Prompt, or Powershell, and choose the "Run as Administrator" option.
Command Prompt:
> mklink task task.bat
Powershell:
> cmd /c mklink task task.bat
Run the following command in your terminal:
$ ln -s task.sh task
Now run npm test
and you will see all the tests failing. As you fill in each functionality, you can re-run the tests to see them passing one by one.
In the previous sections, you might witness many commands prefixed with ./
, or paths containing the /
(forward-slash) character.
If you're using the Windows Command Prompt, then you'll need to replace /
with \
(back-slash) for these commands and paths to work as expected.
On Windows Powershell, these substitutions are not required.
A few notes to help you avoid any hiccups while implementing the programming challenge:
-
If you are on Windows, you might have difficulty getting the tests to pass because of newline UTF encoding issues. If you get stuck, please refer to the thread here.
-
In Windows machines, the
make
command might not exist and can prevent you from running the tests. This can be fixed by using WSL, or installing MinGW, among other options. -
For any conceptual clarifications, look refer to the course material, the C/C++ documentation, or just Google them out!