C Programming Basics
assign2/Makefile
# Make environment CC=gcc CFLAGS=-I. -c -g -Wall LINKARGS=-lm LIBS=-lm # Files SOURCE_FILES= cmpsc311-s17-assign2.c \ a2support.c OBJECT_FILES=cmpsc311-s17-assign2.o \ a2support.o # Productions all : cmpsc311-s17-assign2 cmpsc311-f14-assign2 : $(OBJECT_FILES) $(CC) $(LINKARGS) $(OBJECT_FILES) -o $@ $(LIBS) clean : rm -f cmpsc311-s17-assign2 $(OBJECT_FILES)
assign2/cmpsc311-s17-assign2.c
//////////////////////////////////////////////////////////////////////////////// // // File : cmpsc311-s17-assign2.c // Description : This is the main code file for the CMPSC311 assignment 2. // see class assignment for details on what needs to be added. // // Author : ??? // Created : ??? // #define NUMBER_ENTRIES 20 //////////////////////////////////////////////////////////////////////////////// // // Function : main // Description : This is the main function for the cmpsc311-s17-assign2 program. // // Inputs : none // Outputs : 0 if successful, -1 otherwise int main( void ) { // Local variables int integerArray[NUMBER_ENTRIES], i; // Read the integer values for ( i=0; i<NUMBER_ENTRIES; i++ ) { scanf( "%d", &integerArray[i] ); } ???? // Return successfully return( 0 ); }
assign2/a2support.h
#ifndef A2SUPPORT_INCLUDED #define A2SUPPORT_INCLUDED //////////////////////////////////////////////////////////////////////////////// // // File : a2support.h // Description : This is the header file for the functions for assignment // 2 of the CMPSC311 course. Students are required to define // the following functions and implement them in another // file, a2support.c. // // Author : ??? // Created : ??? // Functions to define void showFloats( ??? ); void showIntegers( ??? ); float medianFloat( ??? ); float medianInteger( ??? ); int countBits( ??? ); void binaryString( ??? ); unsigned short reverseBits( ??? ); void floatQuickSort( ??? ); void integerQuickSort( ??? ); void showCDF( ??? ); #endif
assign2/test-input2.txt
11 5 8 9 11 11 29 30 31 18 9 4 3 27 11 10 14 22 23 9
assign2/test-input.txt
4 13 20 8 18 9 12 5 11 15 3 17 7 14 1 10 2 19 6 16
assign2/test-output2.txt
11 5 8 9 11 11 29 30 31 18 9 4 3 27 11 10 14 22 23 9 0.00 -0.96 -0.15 0.41 0.00 -1.00 -0.75 -0.99 0.91 -0.75 -0.91 -0.76 -0.99 0.96 0.00 -0.54 0.14 -0.01 -0.53 0.41 The integer array value b has 3 bits. The integer array value 5 has 2 bits. The integer array value 8 has 1 bits. The integer array value 9 has 2 bits. The integer array value b has 3 bits. The integer array value b has 3 bits. The integer array value 1d has 4 bits. The integer array value 1e has 4 bits. The integer array value 1f has 5 bits. The integer array value 12 has 2 bits. The integer array value 9 has 2 bits. The integer array value 4 has 1 bits. The integer array value 3 has 2 bits. The integer array value 1b has 4 bits. The integer array value b has 3 bits. The integer array value a has 2 bits. The integer array value e has 3 bits. The integer array value 16 has 3 bits. The integer array value 17 has 4 bits. The integer array value 9 has 2 bits. The sorted integers are: 3 4 5 8 9 9 9 10 11 11 11 11 14 18 22 23 27 29 30 31 The sorted floats are: 0.96 0.91 0.41 0.41 0.14 0.00 0.00 0.00 -0.01 -0.15 -0.53 -0.54 -0.75 -0.75 -0.76 -0.91 -0.96 -0.99 -0.99 -1.00 The median value of the integer array is : 11.00 The median value of the float array is : -0.34 The unsigned short value 0x3: ORIG : 0000000000000011 REVR : 1100000000000000 The unsigned short value 0x4: ORIG : 0000000000000100 REVR : 0010000000000000 The unsigned short value 0x5: ORIG : 0000000000000101 REVR : 1010000000000000 The unsigned short value 0x8: ORIG : 0000000000001000 REVR : 0001000000000000 The unsigned short value 0x9: ORIG : 0000000000001001 REVR : 1001000000000000 The unsigned short value 0x9: ORIG : 0000000000001001 REVR : 1001000000000000 The unsigned short value 0x9: ORIG : 0000000000001001 REVR : 1001000000000000 The unsigned short value 0xa: ORIG : 0000000000001010 REVR : 0101000000000000 The unsigned short value 0xb: ORIG : 0000000000001011 REVR : 1101000000000000 The unsigned short value 0xb: ORIG : 0000000000001011 REVR : 1101000000000000 The unsigned short value 0xb: ORIG : 0000000000001011 REVR : 1101000000000000 The unsigned short value 0xb: ORIG : 0000000000001011 REVR : 1101000000000000 The unsigned short value 0xe: ORIG : 0000000000001110 REVR : 0111000000000000 The unsigned short value 0x12: ORIG : 0000000000010010 REVR : 0100100000000000 The unsigned short value 0x16: ORIG : 0000000000010110 REVR : 0110100000000000 The unsigned short value 0x17: ORIG : 0000000000010111 REVR : 1110100000000000 The unsigned short value 0x1b: ORIG : 0000000000011011 REVR : 1101100000000000 The unsigned short value 0x1d: ORIG : 0000000000011101 REVR : 1011100000000000 The unsigned short value 0x1e: ORIG : 0000000000011110 REVR : 0111100000000000 The unsigned short value 0x1f: ORIG : 0000000000011111 REVR : 1111100000000000 100 + * 95 + ** 90 + *** 85 + ***** 80 + ********* 75 + ********** 70 + ************** 65 + ****************** 60 + ********************* 55 + ********************* 50 + ********************* 45 + ********************* 40 + ********************** 35 + *********************** 30 + *********************** 25 + *********************** 20 + ************************ 15 + *************************** 10 + **************************** 5 +***************************** 0 +***************************** +----------------------------- 1111111111222222222233 34567890123456789012345678901
assign2/test-output.txt
4 13 20 8 18 9 12 5 11 15 3 17 7 14 1 10 2 19 6 16 -0.65 0.42 0.41 0.99 0.66 0.41 0.84 -0.96 0.00 0.65 -0.99 -0.96 0.75 0.99 0.54 -0.54 -0.42 0.15 0.96 -0.29 The integer array value 4 has 1 bits. The integer array value d has 3 bits. The integer array value 14 has 2 bits. The integer array value 8 has 1 bits. The integer array value 12 has 2 bits. The integer array value 9 has 2 bits. The integer array value c has 2 bits. The integer array value 5 has 2 bits. The integer array value b has 3 bits. The integer array value f has 4 bits. The integer array value 3 has 2 bits. The integer array value 11 has 2 bits. The integer array value 7 has 3 bits. The integer array value e has 3 bits. The integer array value 1 has 1 bits. The integer array value a has 2 bits. The integer array value 2 has 1 bits. The integer array value 13 has 3 bits. The integer array value 6 has 2 bits. The integer array value 10 has 1 bits. The sorted integers are: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 The sorted floats are: 0.99 0.99 0.96 0.84 0.75 0.66 0.65 0.54 0.42 0.41 0.41 0.15 0.00 -0.29 -0.42 -0.54 -0.65 -0.96 -0.96 -0.99 The median value of the integer array is : 10.50 The median value of the float array is : 0.41 The unsigned short value 0x1: ORIG : 0000000000000001 REVR : 1000000000000000 The unsigned short value 0x2: ORIG : 0000000000000010 REVR : 0100000000000000 The unsigned short value 0x3: ORIG : 0000000000000011 REVR : 1100000000000000 The unsigned short value 0x4: ORIG : 0000000000000100 REVR : 0010000000000000 The unsigned short value 0x5: ORIG : 0000000000000101 REVR : 1010000000000000 The unsigned short value 0x6: ORIG : 0000000000000110 REVR : 0110000000000000 The unsigned short value 0x7: ORIG : 0000000000000111 REVR : 1110000000000000 The unsigned short value 0x8: ORIG : 0000000000001000 REVR : 0001000000000000 The unsigned short value 0x9: ORIG : 0000000000001001 REVR : 1001000000000000 The unsigned short value 0xa: ORIG : 0000000000001010 REVR : 0101000000000000 The unsigned short value 0xb: ORIG : 0000000000001011 REVR : 1101000000000000 The unsigned short value 0xc: ORIG : 0000000000001100 REVR : 0011000000000000 The unsigned short value 0xd: ORIG : 0000000000001101 REVR : 1011000000000000 The unsigned short value 0xe: ORIG : 0000000000001110 REVR : 0111000000000000 The unsigned short value 0xf: ORIG : 0000000000001111 REVR : 1111000000000000 The unsigned short value 0x10: ORIG : 0000000000010000 REVR : 0000100000000000 The unsigned short value 0x11: ORIG : 0000000000010001 REVR : 1000100000000000 The unsigned short value 0x12: ORIG : 0000000000010010 REVR : 0100100000000000 The unsigned short value 0x13: ORIG : 0000000000010011 REVR : 1100100000000000 The unsigned short value 0x14: ORIG : 0000000000010100 REVR : 0010100000000000 100 + * 95 + ** 90 + *** 85 + **** 80 + ***** 75 + ****** 70 + ******* 65 + ******** 60 + ********* 55 + ********** 50 + *********** 45 + ************ 40 + ************* 35 + ************** 30 + *************** 25 + **************** 20 + ***************** 15 + ****************** 10 + ******************* 5 +******************** 0 +******************** +-------------------- 11111111112 12345678901234567890