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


CS 2110 Project 4: C Programming

Fall 2021


1 Introduction

Hello and welcome to Project 4. This project is separated into 2 parts. Part 1, consists of functions you have seen in project 3 but now you get to complete them in C! Part 2, you’ll write a calendar program in C!

Please read through the entire document before starting. Often times we elaborate on instructions later on in the document. Start early and if you get stuck, there’s always Piazza or office hours.


2 Can I make my own functions? Can I use Operating System functions?

1. You are allowed to make your own helper functions in the ’.c’ project files if you so desire.

2. You can use printf in your project but you shouldn’t need any other OS functions.

3. Do NOT modify or add your own include statements.

4. In lecture you learned about dynamic memory allocation with malloc. Please note - You do NOT need to use malloc or any dynamic memory functions in this project. If you attempt to use malloc the compiler will tell you to include stdlib.h. Including a new header file is NOT allowed and the autograder will get mad at you.


3 Part 1 - Assembly Functions in C

For this first section you will be completing Project 3 again but this time you have the C language to help you out. This section is specifically designed to demonstrate the power of C.

3.1 Compare

You are given two parameters: ‘a‘ and ‘b‘. The value you return depends on whether ‘a‘ is greater than ‘b‘.

1. return -1 if b is larger

2. return 0 if equal

3. return 1 if a is larger

3.2 Modulus

Since there are different interpretations of modulus for negative numbers, you should take the absolute value of both of your parameters and then perform the operation. Return the result of the modulus operation.

3.3 String Manipulation

You will write a function that takes in a string stored in memory, changes any lowercase letters in the string to uppercase characters. Implement toUppercase.

* Strings are essentially a contiguous array of ASCII values. In this case, the first character is stored at the address given by the parameter ‘string‘.

* The string continues until the first instance of a null terminator, which has the value of 0.

* Memory addresses in C can be treated as arrays. In particular, writing ‘string[i]‘ will give the i-th character in ‘string‘. You can read from that character, as well as assign to it.



The string that you receive can contain any characters, and you should change all letters to uppercase, and leave non-letters as is.

3.4 Shift Right

You will be given an original value, and an amount of bits to shift by to the right. Return the shifted value. You will not have to handle overflow.

3.5 Shift Left

You will be given an original value, and an amount of bits to shift by to the left. Return the shifted value. You will not have to handle overflow.

3.6 Collatz

You will be implementing a calculator for iterations of the Collatz Conjecture.

The Collatz Conjecture is a famous unsolved math problem, which operates under a few simple rules. We have our Collatz function, C(n), which takes in exclusively positive integers.

1. If n is an odd number, C(n) = 3n + 1

2. If n is an even number, C(n) = n/2

From here, we seek to calculate how many times we need to run n (and its subsequent results) through the Collatz function in order for it to reach the value 1.

3.7 Dot Product

The last method you will be writing is a dot product calculator. Given two arrays in memory, your job is to compute the dot product and return it back into memory. In mathematics, the dot product is calculated as the sum of multiplication between each pair of vector components.

If A = [ a1 a2 a3 ] and B = [ b1 b2 b3 ], then the dot product between A and B would be

The values inside vectors can be positive or negative integers.

You are given three input values:

* ‘vecA‘ represents the address of the first vector in memory

* ‘vecB‘ represents the address of the second vector in memory

* ‘len‘ represents the length of each individual vector


4 Part 2 - Calendar Implementation

The bulk of your work for this project will be implementing various functions for the 2021 Calendar. The specifications for these functions are listed briefly in the code itself, but are explained with more detail in the sections below. This section specifically pertains to the part2-calendar.c and part2-calendar.h files..

4.1 Overview

Before the function explanation, please notice that there is a global calendar array (found at the top of part2-calendar.c). This array will hold everything related to the calendar! You will be initializing it, adding events to it, removing events from it, and much more.

The following structs will be important (found in part2-calendar.h).



Many of these functions return an integer flag which indicates success or failure. We have provided the macros #define ERROR -1 and #define SUCCESS 0 to help you (found in part2-calendar.h)



4.2 Calendar Conditions

Lastly, there are a few rules that the calendar follows.

1. Dates are strictly saved as integers. For example, January is 1, February is 2, ..., December is 12.

2. ’Military Time’: Event times will be strictly in a 24 hour time scale. That is, the time division is now out of 24 hours instead of two 12 hour periods (am/pm). So, times before 1 pm are written the same way (9:01, 10:46, 12:39) but now 1:00 pm is written as 13:00 , 2:03 pm is 14:03, 3:24 pm is 15:24, 11:59 pm is 23:59 and finally 12 am is 00:00.

3. ’Event Overlap’: Calendar event times can NOT overlap in any way. For example, if an Event A starts at 2:46 and ends at 13:05 and Event B starts at 12:03 and ends at 15:32; these events are considered to be overlapping since the start of Event B is within the time range of Event A. Edge Case: if an Event A ends at 4:45 and an Event B starts at 4:45 we consider this an overlap and this should not occur.

4. An events start time can NOT be after its end time. For example, an event with a start time of 17:23 and an end time of 16:44 is considered invalid and is not allowed to be added to your calendar. Edge Case: an event starting at 14:55 and ending at 14:55 is allowed.

5. Multi-day events are not possible.

6. The number of events (num_events in the date struct) gives the number of valid events on that date. For example, given some date, if num_events = 2 and the events array looks like:

we only consider event1 and event2 as valid events. The remaining events are garbage data and can be overwritten. If num_events = 0 and the event array looks like:

we consider e1, e2, e3, e4, and e5 to all be invalid and can be overwritten.

4.3 Functions

4.3.1 Initialize Calendar

Initialize the entire calendar with the correct dates. Set the month, day, year for every date in the cal-endar and initialize the num_events to zero.

For example, calendar_2021[364] should be assigned December 31st, 2021 - (12, 31, 2021).

NOTE: Check section 3.2 ”Calendar Conditions” to determine edge cases.

4.3.2 Check Event Overlap

Check if events e1 and e2 have overlapping times. See Calendar Conditions ’Event Overlap’ for the def-inition of overlap.

If the events overlap in anyway, return ERROR. Otherwise, return SUCCESS.

NOTE: Check section 3.2 ”Calendar Conditions” to determine edge cases.

4.3.3 Add Event

Add an event on the date specified. Find the date in the calendar and add the event into the calendar. Remember that new_event must not overlap with any of the events currently found on that date.

NOTE: date d is used to locate the date’s index in calendar_2021. Do not simply add new_event to date d as this will not accomplish anything.

If you are successful in adding the new_event to the calendar return SUCCESS, otherwise return ERROR.

NOTE: Check section 3.2 ”Calendar Conditions” to determine edge cases.

4.3.4 Remove Event

Remove an event on the date specified. Find the date in the calendar and remove the event, specified by event_index.

NOTE: date d is used to locate the date’s index in calendar_2021. Do not try to remove the event from date d as this will not accomplish anything.

If the event is removed successfully return SUCCESS, otherwise return ERROR.

Removing an event successfully requires that every subsequent event is shifted ’up’ in the array. For example, given the following event array of size 4:

If e2 is removed from this array the final array of size 3 will look like this:

NOTE: Check section 3.2 ”Calendar Conditions” to determine edge cases.

4.3.5 Change Event Time

Change an event’s start and end time. Find the date in the calendar and modify the event specified by event_ index. Change that event’s start and end time to the start and end time passed into the function.

NOTE: date d is used to locate the date’s index in calendar_2021.

NOTE: Check section 3.2 ”Calendar Conditions” to determine edge cases.

4.3.6 Change Event Description

Change an event’s description. Find the date in the calendar and modify the event specified by event_index. Change the event’s description string with the description string passed into the function. Recall string assignment requires you to copy every element in the string. Attempting to assign strings will not work. For example,

When copying the new string into the description, make sure not go out of bounds of the array. If supplied a string too long to fit, truncate the string to the longest possible length that can still fit entirely in the description array.

NOTE: date d is used to locate the date’s index in calendar 2021.

NOTE: Check section 3.2 ”Calendar Conditions” to determine edge cases.

4.3.7 Sort Events

Sort a date’s event array by start time (earliest time to latest time). For example,



Remember, this is CS 2110, we really don’t care that much about efficiency at the moment. Feel free to sort the event array with any algorithm you’d like.

NOTE: date d is used to locate the date’s index in calendar_2021.

NOTE: Check section 3.2 ”Calendar Conditions” to determine edge cases.

4.3.8 Destroy Calendar

Set everything in the calendar to 0. Set every date’s month, day, year, and num_events to zero. Re-member there is no need to zero out the events array because any events remaining are considered garbage data and invalid (see Calendar Conditions).

NOTE: Check section 3.2 ”Calendar Conditions” to determine edge cases.


5 Building & Testing

All of the commands below should be executed in your Docker container terminal, in the same directory as your project files.

5.1 Helpful Info

1. Use Docker’s ”Interactive Terminal” Run the following command in your terminal to access Docker’s terminal much easier: ./cs2110docker.sh -it

2. From within the ”Interactive Terminal” you should notice the ”host/” directory when you type lsNavigate to your Project diretory and run the unit tests using the commands mentioned later.

3. To exit Docker’s ”Interactive Terminal” simply type: exit.

4. make is a program to help you build your project (in other words, it helps you compile).

5. GDB is a very useful debugger however, it may be a bit confusing at first. Please refer to the following GDB Cheatsheet or ask a TA for help!

5.2 Unit Tests

These are the same tests that will run on Gradescope

To run the autograder locally (without GDB):

1. make clean - Clean your working directory

2. make tests - Compile all the required files

3. ./tests - Run the unit tests

4. make - Compile all the required files and Run the unit tests (previous two steps with one command)

Executing ./tests will run all the test cases and print out a percentage, along with details of the failed test cases.

Other available commands (after running make tests):

● To run a specific test case (to avoid all printing output/debug messages for all test cases):



● To run a test case with gdb:

5.3 Write Your Own Tests

In your Project 4 directory there is a file named ”main.c”. This file can be used to make your own tests. The main method provided can be executed with the following command.

1. make student

For example, if you want to write a test for your ”compare” function from Part 1 you can do the following in the main.c file:

Then execute make student inside Docker. Then, assuming your function is correct, you should receive an output similar to this:


6 Deliverables

Turn in the files collaborators.txt, part1-porting assembly.c and part2-calendar.c to Gradescope by the due date.

Please do not wait until the last minute to run/test your project, history has proved that last minute turn-ins will result in long queue times for grading on Gradescope. You have been warned!!!

NOTE: The syllabus states the following requirement is met - ”Your code must compile with gcc on Ubuntu 18.04 LTS. If your code does not compile, you will receive a 0 for the assign-ment.” HOWEVER, for this project your code MUST compile on our Docker image otherwise you will receive a 0.


7 Demos

This project will be demoed. Demos are designed to make sure that you understand the content of the project and related topics. They may include technical and/or conceptual questions.

● Sign up for a demo time slot via Canvas before the beginning of the first demo slot. This is the only way you can ensure you will have a slot.

● If you cannot attend any of the predetermined demo time slots, e-mail the Head TA before the beginning of the first demo slot.

● If you know you are going to miss your demo, you can cancel your slot on Canvas with no penalty. However, you are not guaranteed another time slot. You cannot cancel your demo within 24 hours or else it will be counted as a missed demo.

● Your overall project score will be ((autograder_score * 0.5) + (demo_score * 0.5)), meaning if you received a 90% on your autograder, but a 30% on the demo you would receive an overall score of 60%. If you miss your demo you will not receive any of these points and the maximum you can receive on the project is 50%.

● You will be able to makeup one of your demos at the end of the semester for half credit.