1. Homepage
  2. Programming
  3. DPST1091 Programming Fundamentals - Assignment 2 - CS ToDo

DPST1091 Programming Fundamentals - Assignment 2 - CS ToDo

Engage in a Conversation
CProgramming FundamentalsCS DefenceAustraliaUNSWDPST1091

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. CourseNana.COM

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”. CourseNana.COM

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. CourseNana.COM

struct todo_list CourseNana.COM

  • 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 CourseNana.COM

  • 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 CourseNana.COM

  • 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.

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. CourseNana.COM

  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.

How To Get Started

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

  1. Create a new folder for your assignment work and move into it.
 
mkdir ass2
cd ass2
  1. 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/dp1091/23T2/activities/cs_todo/cs_todo.c .
  1. Run 1091 autotest cs_todo to make sure you have correctly downloaded the file.
1091 autotest cs_todo
  1. Read through Stage 1. CourseNana.COM

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

 1091 cs_todo
  1. Think about your solution, draw some diagrams to help you get started.
  2. Start coding!

About the Starter Code

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

Before the main function, the starter code has: CourseNana.COM

  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: CourseNana.COM

  1. Created a a pointer to a struct todo_list called todo.
  2. Prompts for you to write your own code!

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. CourseNana.COM

Stage 1

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

  • 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! CourseNana.COM

visual representation of the stage 1 linked list

Stage 1.1 - Setup

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

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! CourseNana.COM

Once you are done, you can compile your program with CourseNana.COM

dcc cs_todo.c -o cs_todo

Examples

CourseNana.COM

CourseNana.COM

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: CourseNana.COM

  • 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: CourseNana.COM

Enter Command: a finish_assignment_2 assignments 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. CourseNana.COM

CourseNana.COM

// Create a string to scan the entire command input into.
char buffer[MAX_STRING_LENGTH];
fgets(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];
enum priority task_priority;
parse_add_task_line(buffer, task_name, task_category, &task_priority);

CourseNana.COM

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! CourseNana.COM

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! CourseNana.COM

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 only include 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

CourseNana.COM

CourseNana.COM

Stage 1.3 - Printing Tasks

Command

p

Now that we are able to add tasks to our todo list, it would be useful if we could also print the list out, to view the tasks we have to complete. When the user types the command p, the list of tasks should be printed. CourseNana.COM

In order to match the autotests, you should loop through the list of tasks and, for each of them, call the provided print_one_task function (rather than calling printf yourself). This will ensure that the output from your program matches the autotest output exactly. CourseNana.COM

Assumptions/Restrictions/Clarifications

  • This command should not print any completed tasks (added in stage 2). It should just print the tasks in our tasks list.

Examples

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

Stage 1.4 - Update Priority

Command

i [task] [category]

Priority of tasks can change over time. This can be due to deadlines, oversights or a variety of other issues. As a result, it would be nice to be able to adjust the priority of tasks in your todo list. CourseNana.COM

The i command is followed by the name of the task, as well as, the category of the task. It increases the priority of the task matching this name and category upon being called. In the case where the task is at the highest priority, it should be reset back to the lowest priority. CourseNana.COM

Just like with 1.2, you will need to extract task and category from the input line involving this command. The code below will do this for you by using another one of our helper functions, parse_task_category_line(), make sure to use it! CourseNana.COM

CourseNana.COM

// Fetch `[task] [category]` from stdin
char buffer[MAX_STRING_LENGTH];
fgets(buffer, MAX_STRING_LENGTH, stdin);

// Create strings for `task`/`category` and populate them using the contents
// of `buffer`
char task[MAX_TASK_LENGTH];
char category[MAX_CATEGORY_LENGTH];
parse_task_category_line(buffer, task, category);

CourseNana.COM

In the case where the task does not exist in the given category, the following error should be printed: CourseNana.COM

Could not find task '[task]' in category '[category]'.

Assumptions/Restrictions/Clarifications

  • You can assume that both task and category will be at most MAX_STRING_LENGTH characters.
  • If you increase the priority of a task that already has a HIGH priority, then that task's priority should become LOW.

Examples

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

./cs_todo
Welcome to CS ToDo!
Enter Command: a feed_dog pets high
Enter Command: i complete_assignment comp1091
Could not find task 'complete_assignment' in category 'comp1091'.
Enter Command: [CTRL-D] All done!

CourseNana.COM

CourseNana.COM

Stage 1.5 - Counting Tasks

Command

n

When we’re planning our time, it might be nice to know how many tasks we have left to complete. As such, we need to implement the command n, to count the number of tasks in our todo list, and print this information out. CourseNana.COM

This command should print the message "There are [num] tasks in your list!" (replacing [num] with the number of tasks in the list). CourseNana.COM

Assumptions/Restrictions/Clarifications

  • This command should not count any completed tasks (added in stage 2). It should just count the tasks in our tasks list.

Examples

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

Testing and Submission

Remember to do your own testing CourseNana.COM

Are you finished with this stage? If so, you should make sure to do the following: CourseNana.COM

  • Run 1091 style, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style and readability!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1091 style cs_todo.c
1091 autotest-stage 01 cs_todo
give dp1091 ass2_cs_todo cs_todo.c

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
C代写,Programming Fundamentals代写,CS Defence代写,Australia代写,UNSW代写,DPST1091代写,C代编,Programming Fundamentals代编,CS Defence代编,Australia代编,UNSW代编,DPST1091代编,C代考,Programming Fundamentals代考,CS Defence代考,Australia代考,UNSW代考,DPST1091代考,Chelp,Programming Fundamentalshelp,CS Defencehelp,Australiahelp,UNSWhelp,DPST1091help,C作业代写,Programming Fundamentals作业代写,CS Defence作业代写,Australia作业代写,UNSW作业代写,DPST1091作业代写,C编程代写,Programming Fundamentals编程代写,CS Defence编程代写,Australia编程代写,UNSW编程代写,DPST1091编程代写,Cprogramming help,Programming Fundamentalsprogramming help,CS Defenceprogramming help,Australiaprogramming help,UNSWprogramming help,DPST1091programming help,Cassignment help,Programming Fundamentalsassignment help,CS Defenceassignment help,Australiaassignment help,UNSWassignment help,DPST1091assignment help,Csolution,Programming Fundamentalssolution,CS Defencesolution,Australiasolution,UNSWsolution,DPST1091solution,