Due: Wednesday, October 21 2026, 11:59 pm
The purpose of this part is to understand the usage of .h and .c files and the concept of prototype in C.
You will implement a stack by using an array in this part. Your program should be able to use the stack to hold a list of integers and print out the list in the original order and the reverse order.
cstk.h. The .h file should contain the
necessary structures and the declarations of the basic functions of a
stack. In this project, you will need the following structure and
basic functions.
typedef struct Stack
{
int *data; // this is a pointer to the start of the data for the stack
int *top; // this will point to the next place to insert in the stack
int capacity; // this is the maximal size of the stack
} Stack;
Stack *stk_create(int) creates a Stack with a maximal capacity
specified by the int valueint stk_empty(Stack *) returns 1 if the given Stack is empty, otherwise 0.int stk_full(Stack *) returns 1 if the given Stack is full, otherwise 0.void stk_push(Stack *, int) adds a new value to the
top of the stack if there's space. If there's no space, prints out a warning
but does nothing (and doesn't crash).
int stk_peek(Stack *) returns the value on the top of
the stack if such a value exists. Otherwise, prints out a warning and
returns 0.int stk_pop(Stack *) removes and returns the value on the top of
the stack if such a value exists. Otherwise, prints out a warning and
returns 0.void stk_display(Stack *, int) prints out the list in
the reverse order (LILO) if the int value is 1, otherwise, prints out in
the original order (LIFO).void stk_destroy (Stack *) frees up the memory Stack *stk_copy(Stack *) copies the contents into another Stack
of the same maximal size and returns it.cstk.c file. This file should contain the
implementation of the basic functions declared in the cstk.h file.
gcc -o cstktest cstktest.c cstk.c
./cstktest
Fix your code until all tests are passed and the output displays as described.
In your report, include a screenshot of the output.
Report: Your goal is to demonstrate that your code works correctly and that you can represent visually how memory is manipulated by it.
/** * Simple Heap Allocation Code * * Stephanie Taylor * Spring 2024 */ #include#include int main (int argc, char **argv) { int *a = (int *)malloc( sizeof(int)*4 ); int i; printf( "a is at %p\n", &a ); printf( "i is at %p\n", &i ); printf( "array starts at %p\n", a ); for (i = 0; i < 4; i++) { a[i] = i*2; } // Mark 1 (first memory picture) free( a ); // Mark 2 (first memory picture) return 0; }
Leads to this image at Mark 1. Enough space for 4 ints has been allocated on the heap and is pointed
to by the variable a. i is the loop control variable, and its value is 4
after the loop.
And this image at Mark 2. The space on the heap has been made available to later calls to malloc. I
drew it as if it has disappeared. The value of a still has the same address in it, but
we aren't supposed to go to that address.
In this task, we'll update our Stack file from the above tasks to work for arbitrary data types. To help
you get started, we've created cstk2.h This updated header file is dedicated to this task, and you are not expected to use it for the above integer stack. Your job for this task is to implement the functions in the header file in a new cstk2.c file. You can use cstktest2.c to test your work. In order for it to work, you'll need
to:
cstk2.c. Probably the hardest function will now be the toString method. For partial
credit, you can assume that we'll only use strings of relatively small size, so allocating space
for, say, 1024 characters will be sufficient for all tests. For full credit, ensure that
you never allocate more than twice as much memory as necessary, while still maintaining a linear
time toString method and detail your method in the report.cstktest2.c; you'll see two functions: intToString and
accountToString. Although each has a void * parameter, you need to
write a method that casts the given parameter to the appropriate type, then converts that result
into an appropriate string. For ints, you should do the obvious thing (10 --> "10"). For
Accounts, an Account with the name "Max Bender" and balance 10 should be converted to "Max
Bender: 10" (in general: "<name>: <balance>")
cstktest2.c is a small test you can use to confirm that you removed any potential
memory leaks in your toString method (which is not trivial, especially if done correctly)In your report, 1) include a screenshot of your output of running cstktest2.c and 2) draw the memory contents at mark 1 of this file.
In this project you'll start learning your selected language.
Write an sample program in the selected language that demonstrates the rules for identifier naming, variable declarations and identifier scoping. Focus on any special rules or capabilities of your language. Name your program to task1.xx (e.g. task1.py, task1.java). Make a Google Sites page for this project, and have a section on the page for the sample code and a brief explanation of how the scoping rules apply to the language. This should be written as a tutorial for someone learning how to create variables and use them.
Write an example program in the selected language that executes a binary search on a list or array of numbers. Make it a function/method, if possible. Name your program to task2.xx. Make a section on the project 3 Google Sites page that explains the basic syntax of the language, including how to create a function/method and how to use control flow statements, using the binary search program as an example.
Write an example program in the selected language that demonstrates all of the basic built-in types and how to construct aggregate types (e.g., records, classes or structures). The program should demonstrate which of the standard suite of operators (+-/*%) manipulate which types and what the resulting type of each operation is. Use it to explain the type system in your language on the project 3 Google Sites page. Name your program to task3.xx.
What control flow statements does the language provide? Write a program that uses all these control flow statements. Name the source file to task4.xx. For each of the statements, compare it with C if C also has it. Briefly describe the differences if there are any on project 3 Gogle Sites page.
Function Type: write a program to show how are functions treated in the language as a data type? Name the program to task5.xx. Can you assign a function to a variable? Can you pass a function to another function? If so, how do you then execute the function using the reference? Do you have to name a function? Answer these questions in your Google Sites report and use example code in your explanations.
Please note that it is your responsibility to explicitly indicate the extensions you have undertaken. If you complete extensions for the C stack, please indicate explicitly in the code and README file. If you complete an extension in a selected language, please indicate explicitly on your Google Sites page.
The submission of this project has two components:
Required Files:
.md filename extension. Each project should have a README file along with all your source codes. The README file will contain:
tree command to generate this.You can follow the instructions for the README file from Project 1.
Please do NOT include: Executable files. On Windows, these have the .exe extension. On Mac and Linux, there is no e xtension. We have found that graders often have difficulty downloading submissions if they contain executable files.
To check whether you've made your report well organized, please follow the Organization part in the Google Sites section in this writing page. Remember to publish all your changes and include the homepage link of your CS333 Google Sites in the README file.
© 2026 Ying Li, Stephanie Taylor, Max Bender. Page last modified: .