Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

DPST1091 23T2 - Programming Fundamentals!

Assignment 2 - CS ToDo

In assignment 2 you will be implementing a todo list, to help Ben keep track of all the jobs he has to do for DPST1091! Todo lists are a classic first project for any aspiring developer,   so we decided to let you implement your own todo list in C, to get some more practice

working with linked lists.

Overview

Assignment Structure

This assignment will test your ability to create, use, manipulate and solve problems using linked lists. To do this, the todo list is implemented as a linked list of tasks, and another    separate linked list is used to keep track of your “completed tasks”.

We have defined some structs in the provided code to get you started. You may modify any of the structs if you wish, but you should not need to.

struct todo_list

Purpose:

To store all of the information about our todo list.

Contains:

struct task *tasks

A pointer to the first task in the todo list.

struct completed_task *completed_tasks

A pointer to the first completed task in the list

struct task

Purpose:

To store information about a task on your list.

Contains:

char task_name[MAX_TASK_LENGTH]

The name of the task (e.g   “Finish-Assignment-2”)

char category[MAX_CATEGORY_LENGTH]

The task’s category (e.g “Assignments”)

enum priority priority

The task’s priority - how urgent is it that the task is completed?) (e.g HIGH)

struct task *next

A pointer to the next task in the list.

struct completed_task

Purpose:

To hold information about a task that has already been completed. Contains:

struct task *task

A pointer to a task that has been completed, and removed from the   tasks list. The  next  pointer of this task should always point to   NULL .

int start_time

The time at which we started this task. It will be given in 24-hour time (e.g 1234  corresponds to a time of 12:34pm). You have been provided with

functions to process these times.

int finish_time

The time at which we finished this task.

struct completed_task *next

A pointer to the next completed task in the list.

HINT:

Remember to initialise every field inside the structs when creating them (not just the fields you are using at that moment!).

HINT:

There are diagrams inside stages 1 and 2 to indicate what your todo list should look like.

Commands

To help Ben manage his jobs, you will need to setup the todo list program for him, which will allow creation of a todo list and handy commands to manipulate it.

1. Setup of todo list (Stage 1.1) : Create and initialise the todo list.

2. Commands (Stage 1.2 onward) : The program now reads command continuously until  CTRL-D .

Each command will begin with a character and then potentially have strings or enums in string format after it.

The number of arguments in a command depends on the first character. For    example, to add a task, the command is   a  followed by 3 arguments, whereas counting tasks with the   n  command requires no extra arguments.

Some commands have helper functions provided to help you read in and format the arguments that follow. These functions are mentioned in their respective

parts of this spec.

NOTE:

You can assume that your program will never be given a non-existent command or command arguments that are not of the right type. Commands will always start

with a char.

You can also assume that the right number of inputs will be given with each command.

How To Get Started

There are a few steps to getting started with CS ToDo.

1. Create a new folder for your assignment work and move into it.

$ mkd ir as s2

$ c d ass2

2. Download the starter code (cs_todo.c) here or use this command on your CSE account to copy the file into your current directory:

$ cp -n /web/dp 109 1/23T2/activities/cs_to do/cs_to do.c .

3. Run  1091 autotest cs_todo  to make sure you have correctly downloaded the file.

$ 109 1 au to test cs_to do

NOTE:

When running the autotest on the starter code (with no modifications),it is expected to see failed tests.

4. Read through Stage 1.

5. Spend a few minutes playing with the reference solution -- get a feel for how the assignment works.

$ 109 1 cs_to do

6. Think about your solution, draw some diagrams to help you get started. 7. Start coding!

About the Starter Code

The provided starter code has done some setup for you. This is explained below.

Before the main function, the starter code has:

1. Imported libraries, defined some initial   #define 's and enums, and defined the structs described above.

2. Declared a   command_loop  function which you will have to use in stages 1.1 and beyond.

3. Declared some functions, which are used to help manage the todo list. Some of these you will not need to use, most of them you will. Please read the comments and the spec as we will suggest certain provided functions for you to use.

In the main function, the starter code has:

1. Created a a pointer to a   struct todo_list  called   todo .

2. Prompts for you to write your own code!

HINT:

To start with,write your code in the main function! You can (and should!) write and add your own functions as you go :)

Your Tasks

This assignment consists of four stages. Each stage builds on the work of the previous

stage, and each stage has a higher complexity than its predecessor. You should complete the stages in order.

Stage 2

Stage 3

Stage 4

Stage 1

For stage 1 of this assignment, you will be creating a basic structure for CS ToDo. This will include:

Setting up an empty todo list

Adding tasks to the todo list

Printing tasks in the todo list

Updating priority of tasks in the todo list

Counting the number of tasks in the todo list

Stage 1 Diagram

At the end of stage 1, your linked lists should look similar to this!


Stage 1.1 - Setup

In stage 1.1, we will initialise the provided   todo  variable found in the   main()  function.

You should use  malloc  to allocate some space in memory for the   todo_list  structure, and set the  tasks  and   completed_tasks  fields to   NULL  — as we don’t have any tasks in our lists yet!

Once you are done, you can compile your program with

$ dc c cs_to do.c -o cs_to do

Examples

+ Example 1.1.1: Running the program

$ ./cs_to do

Welcome to CS ToDo!

Enter Command : [CTRL-D] All done!

NOTE:

You may like to autotest this section with the following command:

109 1 au to test- stage 0 1_0 1 cs_to do

Stage 1.2 - Adding Tasks

Command

a [task] [category] [priority]

There’s not much point in having a todo list if we can’t put any tasks on it. So, in this stage, we will allow the user to add tasks to the end of their todo list! To add a task, the user will type the command   a , followed by:

the task’s name,

the task’s category,

the task’s priority.

For example, to add the task "finish_assignment_2" in the category "assignments" with a high priority, you would type the following:

Enter Command : a fin ish_assignmen t__2 assignmen ts high

To process these inputs, we have provided you with the function   parse_add_task_line() . It will extract the name, category, and priority from the line for you. This function is ready to be  used by you, each time you add a task to your todo list (you just have to call it!). An

example of how you should use this function is below.

// Create a string to scan the entire command input into.

char buffer [MAX_STRING_LENGTH] ;

f gets(buffer, MAX_STRING_LENGTH, stdin) ;

// Create variables for each part of the command being scanned in

// (name of task, category of task and priority of task)

char task_name[MAX_TASK_LENGTH] ;

char task_category [MAX_CATEGORY_LENGTH] ;

e num priority task_priority;

parse_add_task_line(buffer, task_name, task_category, &task_priority) ;

In this assignment, you will need to continuously loop the program until   CTRL+D  is

pressed, while also being able to enter commands (much like assignment 1!). We tend to call this a "command loop", and we have already set one up for you in the   command_loop

function!

Currently, this command loop only handles a single command - 'a'. You should write code

for 1.2 inside this loop to handle adding of a task - remember to use the related parse_add_task_line()  code!

HINT:

We highly recommend that you make functions for each command to separate your code out!

For this stage, you should also write helper functions to create a new task, and to append your new task to the list. Are there any other functions you could write to help split up your program’s logic?

Assumptions/Restrictions/Clarifications

New tasks should be added to the end of the todo list.

The same task will never be added to the todo list. This means that two tasks will   never share the same name and category. However, it is perfectly fine to share just one of these.

You can assume that the task name and category will onlyinclude alphanumeric     characters (upper/lowercase letters and numbers) and underscores (_). This allows  for a wide range of inputs, for example, both "complete_stage 3 with_testing" and "2" are valid task names. You do not need to do any error checking for this.

You can assume that the priority given will be one of "low", "medium", or "high". You do not need to do any error checking for this.

You can assume that both   task  and   category  will be at most   MAX_TASK_LENGTH  and MAX_CATEGORY_LENGTH  characters long, respectively.

Examples

+ Example 1.2.1: Adding a task

$ ./cs_to do

Welcome to CS ToDo!

Enter Command : a fin ish_assignmen t__2 assignmen ts high

Enter Command : [CTRL-D] All done!

WARNING:

You will not pass any autotests for Stage 1.2 until you have implemented Stage 1.3.

Stage 1.3 - Printing Tasks

Command

p