Each exercise this quarter is rated on a integer scale of 1 – 5, inclusive, with 1 being the "least time-consuming" and 5 being the "most time-consuming".
This difficulty scale is meant as a rough guide for you in predicting the amount of time to set aside for each exercise as you balance the work required for 333 with your other obligations. However, it is necessarily imperfect as everyone's set of circumstances and experiences with the exercises differ. If your experience with an exercise does not align with its rating, that is not a reflection of you or your abilities.
typedef.malloc and free to manage dynamically-allocated data without memory leaks.Your job is to write a C program that does the following:
typedef to define a new structured type
called Point3d, which contains int32_t
fields for x, y, and z coordinates.
Point3d p = ...;typedef to define pointers to
Point3d structs to be Point3dPtr;
instead, use Point3d*.Point3d_Allocate that (1) accepts three
int32_t arguments, (2) malloc's space
for a Point3d, (3) assigns the three arguments to
the x, y, and z fields, and (4) returns (a pointer to) the
malloc'ed Point3d.Point3d_Scale that (1) accepts one
Point3d* and one int32_t value as
arguments, (2) scales the x, y, and z fields of the pointed-to
struct by the given value, and (3) returns nothing.
bool, even though it would a reasonable design
decision to do so.Point3d_GetOrigin that (1) accepts no arguments,
(2) constructs a Point3d with x, y, and z equal to
zero, and (3) returns a copy of the struct.main function that runs at
least one automated test on each of your functions.
Make sure to read the relevant portion of the Implementation
Notes below ("Testing") very carefully to make sure that you
understand what this is asking for.Point3d.h, Point3d.c, and
ex3.c.
Point3d.h should contain the struct definition
and function declarations related to Point3d.Point3d.c should contain the function
definitions.ex3.c should contain the main
that tests your functions.
As part of this exercise, you will have to make design decisions
about how to handle errors.
Be sure to take some time and reason about what arguments might be
problematic for each function.
Be sure to handle other types of errors, like the case in which
malloc fails.
Whatever decisions you make, be sure to document them appropriately.
Make sure your main frees any memory that was
dynamically allocated, even when handling edge cases.
We will be using valgrind
(valgrind --leak-check=full ./ex3) to check for
memory leaks and other memory issues.
For the purposes of this exercise, it is enough for you to write code that makes use of all of the functions that you wrote and verifies that the struct members contain the correct values at each step. When an error is encountered during testing, you should immediately return an appropriate status code to indicate failure in addition to printing an error message. This signals an error to the parent process (this is what makes it automated) and is easier to detect than having to manually scan over your program output, especially if you have a lot of tests.
main is considered testing code for your
Point3d module.
Testing code is the only place where the use of
assert() is allowed, though you do not need to use
it at all if you don't want to.For the sake of our autograder, make sure that your function and type names match the specifications exactly, including capitalization. You should write comments explaining the behaviour and purpose of the struct and functions you define. Be sure that the comments you write document how errors are handled.
This is supposed to make your life easier! Make sure that your syntax is correct and that you're taking advantage of the new alias.
Make sure to include header guards, where appropriate, and that you place the function block comments in the appropriate place.
Submit the following file(s) by creating an ex3-submit tag in your exercise repo before the assignment deadline. The file(s) should be located in the exact directory listed below (there should be a folder titled ex3 with the ex3.c, Point3d.h, and Point3d.c files within that folder), including capitalization:
ex3/ex3.cex3/Point3d.hex3/Point3d.cFor full credit, your code must:
attu, or CSE home VM).gcc and valgrind).$ gcc -Wall -g -std=c17 -c -o Point3d.o Point3d.c $ gcc -Wall -g -std=c17 -c -o ex3.o ex3.c $ gcc -Wall -g -std=c17 -o ex3 ex3.o Point3d.o
.c file with
your name(s) and CSE or UW email address(es).cpplint.py --clint).