Use project code hw7
You will have create a hw7 folder containing these program files:
Makefile Makefile for homework 7 LinkedBitArray.h Header file containing: (1) the struct definition for segment (2) the typedef of BitArray (3) function headers in LinkedBitArray.c LinkedBitArray.c C Project file for hw7 where you write 6 functions to implement a linked Bit Array "class" (object) sieve.c C Project file for hw7 where you use the bit array object to write the Sieve of Eratsothenes test1.c Test program for the Allocate() function test2.c Test program for the clrAll() function test3.c Test program for the setAll() function test4.c Test program for the clrBit() function test5.c Test program for the setBit() function test6.c Test program for the testBit() function |
|
Since C does not have classes to organize = (package) the variables (= data structure) and methods (= algorithm) into a coherent unit (= "class"), I like to show you how this is done in C programming with a header file and a C program file
HW7 basically introduces
software engineering in
C,
i.e.: how do you define a
object "class" (=
struct) in
C and
write functions that
manipulate
objects of that "class".
I use "class" loosely here because
C does not
have classes.
#define SIZE_OF_SEG 256 // # int variables in one segment #define BITS_PER_SEG (SIZE_OF_SEG*sizeof(int)*8) // # bits in one segment struct segment { int bits[SIZE_OF_SEG]; // bit array stored in one segment struct segment *next; // Link to the next segment }; typedef struct segment * BitArray; |
The header file: LinkedBitArray.h contains the definitions of the struct segment "object" that you will need to maintain.
The struct segment "object" consists of (1) an integer array bits[ ] (that will be used as a bit array) and (2) a link variable next:
The int array bits[ ] consists of SIZE_OF_SEG variables (and SIZE_OF_SEG is defined as 256). This array will be used as a bit array. The way we use an int array to represent a bit array has been discussed in the lectures and you have used it in homework 5, so I will not repeat it here again. There is - however - a twist in this implementation (see next pargraph).
Unlike in homework 5 where we define a large array, you will create a dynamic bit array by chaining a number of struct segment objects into a linked list as follows:
Suppose the variable A points to the first struct segment; then the next variable of this segment will point to the next segment; and so on.
Furthermore:
|
For your convenience, the header file LinkedBitArray.h contains the BITS_PER_SEG constant which is equal to the # bits in one segment
You will need to implement the following 6 functions used to maintain the linked bit array data structure:
|
Note: you may noticed that Allocate() returns a BitArray type and wonder what that is. The answer is inside the LinkedBitArray.h header file:
typedef struct segment * BitArray;
|
Therefore, each part can be worked on independently
|
|
|
|
|
|
|
|
|
|
|
|
The bonus part is graded using your bit array implementation, so if your implementation is faulty, the bonus part cannot (and will not) be graded !!!
|
|
|
I have discussed how to use the gdb debugger in class and you can find my gdb slides here: click here
Use EGTAPI to turn in your LinkedBitArray.c program file with assignment code hw7
If you have done the bonus part, you can turn in your sieve.c program file with assignment code hw7-a
You must make the extenion request before the deadline of the homework
Your request will be successful if you have not exceeded the maximum number of "free" (no-questions-asked) requests allowed