Due: Monday, October 9 2017, 11:59 pm

Part I: C Semantics

The purpose of this part is to understand the function handler of the C language. The library function qsort is good practice for this purpose. You are expected to use qsort to address the following question.

Given an array of random integers, sort the array in a way that the even numbers apper first and the odd numbers apper later. The even numbers should be sorted in descending order and the odd numbers should be sorted in ascending order. For example, given [3, 8, 2, 9, 1, 6], the output of your program should be [8, 6, 2, 1, 3, 9].

Download the template of the program. Read and understand the program. Implement your comparator function. Compile and run the program. The output of the program should be as follows.

	The sorted array is: 12 10 8 6 4 2 0 1 3 5 7 9 11 13 

Part II: Semantics of Selected Languages

In this part you'll explore both the syntax and semantics of certain types of statements in your chosen languages.


For each of your languages, complete the following tasks.

  1. What control flow statements does the language provide? Write a program that uses all these control flow statements. Name the source file to task1.xx. For each of the statements, compare it with C if C also has it. Briefly describe the differences if there are any.

  2. Function Type: write a program to shows how are functions treated in the language as a data type? Name the program to task2.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? Explain thes in your write-up.

  3. Implement a general sort algorithm (e.g., quick sort, merge sort) that can be used for any type and can be used to obtain any desired order. Write a test program for your implementation, and demonstrate your algorithm works.


  1. A perfectly acceptable extension for any assignment going forward is to do a third language.
  2. Choose other aspects of the language, like polymorphism, dynamic function definitions, lifetime, or aggregate data type storage and internal representation, and write example programs demonstrating those concepts.
  3. Explore the precedence and semantics of the C memory operators like & and *, or look at whether your languages have similar capabilities.
  4. Make a compilable and runnable haiku in the language that helps to demonstrate the meaning of a statement in the language.
  5. The haiku Python def shows how the def function adds a new symbol to the computer's state which can subsequently be called.

  6. Make your comparator function for qsort as efficient as possible. Make it uses less operations and control flow statements. Use it to sort a large array. Observe the computation time, and compare it with the less-efficient version if possible. Explain why your implementation is efficient in the comments.


The submission of this project has three components:

  1. Codes: Your qsort, general sort algorithms, and source codes for other tasks and extensions should be submitted to the fileserver. Please make the filename of your source codes reflect the tasks or extensions.Note that the quality of your comments counts toward your grade.
  2. README: In this project, you need to submit a README file for your C codes and the general sort algorithms using the selected languages. The README file can be a .txt file. It should be well-organized in a way that readers can easily know the usage and the outputs of the source codes in C and the selected languages. In addition, the known bugs of your codes should also be indicated in the README file. Please also indicate the version of your C complier, your operationg system, and its version in the README file.
  3. Wiki write-up: The write-up of this project should have the following elements.
    • Title of the project and your name
    • You are expected to have a section to explain the control flow of the selected languages, and another section to explain the function type.
    • Please include necessary code snapshots in your explanations.

Please note that it is your responsibility to explicitly indicate the extensions you have taken. If you take the extension in qsort of C, please indicate explicitly in the codes and README file. If you take the extensions in selected languages, please indicate explicitly in your wiki write-up or source codes and README.

© 2017 Ying Li. Page last modified: .