Title image Fall 2018

Due: Thursday, 4 October 2018

Part I: C Syntax

The purpose of this part is to understand the usage of .h and .c files, the keyword extern, and the concept of prototypes in C.

For the C portion of this project, you will implement a stack data structure by using an array. 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.


  1. Create a cstk.h. The .h file should contain the necessary structures and the declarations of the member functions. In this project, you will need the following structure and member functions.
      	typedef struct stack {
      		int* stack;
      		int top;
      	} Stack;
    • Stack *stk_create(int) creates a stack with the size specified by the int value
    • void stk_destroy (Stack*) recycles a stack
    • void stk_push(Stack*, int) adds a new value to the top of the stack
    • int stk_pop(Stack*) removes a value from the top of the stack
    • void stk_display(Stack*, int) prints out the list in the reverse order if the int value is 1, otherwise, prints out in the original order
  2. Create a cstk.c file. This file should contain the implementation of the member functions declared in the cstk.h file. In this project, specify the capacity of your stack as a glocal variable int CSTK_MAX = 50; in the cstk.c file. Use extern to make the global variable is accessible in other c files, cstktest.c. An extern statement is the keyword extern followed by the type and name of the global variable, but no initial assignment of its value.
  3. Download cstktest.c. Read the code and understand it. Compile and run the code as follows:

    gcc -o cstktest cstktest.c cstk.c

    Your output should be

    The original list: 0 1 2 3 4 5 6 7 8 9 
    The reversed list: 9 8 7 6 5 4 3 2 1 0 

Part II: Syntax of Selected Languages

In this project you'll start learning your selected languages.


  1. Write an example program in each 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 programs task1.xx (e.g. task1.py, task1.java). Make a wiki page with code snippets and a brief explanation how the scoping rules apply to it. This should be written as a tutorial for someone learning how to create variables and use them.

    This task should be possible in both of your selected languages.

  2. Write an example program in each language that executes a binary search on a list or array of numbers. Make it a function/method, if possible. Name your program task2.xx. Make a wiki page that explains the basic syntax of the language, using the binary search program as an example.

    This task is possible for your A list language. It should be possible in most B/C list languages. Note, it will be easier to implement recursively in functional languages (list B). If you run into a problem with your B/C language, focus on basic operations such as iteration, conditional statements, and defining functions.

  3. Write an example program in each 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 languages. Name your sample program task3.xx.


  1. A perfectly acceptable extension for any assignment going forward is to do a third language.
  2. Write other example programs that show unique features of the syntax, naming, or scoping in the selected language.
  3. Develop explicit comparison code in Python, Java, or C and compare and contrast it with your selected languages.
  4. If the selected language has a built-in capability for binary search, include an example of using it.
  5. Come up with an example of just how horribly you can write the binary search program using the selected language, making it as difficult as possible to understand what is going on. Use this as an example of how syntactic or semantic rules permit obfuscation.
  6. Make a compilable and runnable haiku in the selected language. Less strict forms of poetry are also acceptable. Note, this is generally a minor extension in terms of points, but it can be fun.
  7. Demonstrate whether functions are a basic data type in your language. Can a variable hold an arbitrary function?
  8. Make your stack more robust so that it can handle the overflow errors, or expand automatically as needed. Create more functions for the stack library.


The submission of this project has three components:

  1. Code: Your cstk.h, cstk.c, and cstktest.c of part I, your source code for tasks of part II, and your source code for extensions should be submitted to the fileserver. Please make the filenames of your source code reflect the tasks or extensions.Note that the quality of your comments counts toward your grade.
  2. README: Submit a README file to the fileserver for your C code and the code for your selected languages. The README file can be a .txt file. No matter what, it should be readable from the terminal (no Word files). It should be well-organized such that readers can easily understand the usage and the outputs of the C code and the code for your selected languages. In addition, any known bugs should be in the README file. Follow the format and content instructions from project 1.
  3. Wiki Report: The non-C language pages for this project should have the following elements.
    • Title of the project and your name
    • A section for each task of part II. Each section should contain appropriate snippets of your sample programs, the outputs, and your explanations.
    • If you complete extensions in your selected languages, please include a section for each extension, providing sample programs, outputs, and explanations.
    To check whether you've made your write-up well organized, please follow the Organization part in the Wiki section on this writing page.

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 languages, please indicate this explicitly in your wiki report. Along with each extension, indicate if you completed it with a partner.