Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This program will take the first few daily assignments and combine their behaviors to make an opaque object wrapper that allows for all the behaviors
This program will take the first few daily assignments and combine their behaviors to make an opaque object wrapper that allows for all the behaviors we want in a bit collection data structure called BIT FLAGS #ifndef BIT FLAGS H define BIT FLAGS H include "status . h" typedef void BIT FLAGS //Intentionally leaving out a default init function to force user to at least guess at the size needed //If one WERE to be used it would have the following prototype //BIT_FLAGS bit flags init_default(void); //Precondition: number of bits is a positive integer //Postcondition: Returns the handle to a valid Bit flags object that has the ability to store up to /I number_of_bits bits but currently all flags are set at zero. Returns NULL on failure. The container I is assumed to hold size-number_of_bits after the init function runs BIT_FLAGS bit_flags_init_number_of_bits(int number_of_bits); //Precondition: flag position is a non-negative integer and hBit flags is a handle to a valid Bit flags object //Postcondition: The flag at the flag position index is set to 1. Function will attempt to resize the /I internal representation if the flag position is too large instead of failing for out of bounds. Returns // SUCCESS if the operation is successful and FAILURE if the operation fails a needed resize. This II operation is considered to be expensive if flag position is constantly going out of bounds by a small /I amount because the resize always attempts to mininize the amount of space required to store the bits All new flags created in a resize operation (except the one being set) will be set as zero Status bit flags_set_flag(BIT_FLAGS hBit flags, int flag position); //Precondition: flag position is a non-negative integer and hBit flags is a handle to a valid Bit flags object //Postcondition: The flag at the flag position index is set to 8 Function will attempt to resize the /I internal representation if the flag position is too large instead of failing for out of bounds. Returns // SUCCESS if the operation is successful and FAILURE if the operation fails a needed resize. This II operation is considered to be expensive if flag position is constantly going out of bounds by a small /I amount because the resize always attempts to mininize the amount of space required to store the bits All new flags created in a resize operation will be set as zero Status bit_flags_unset flag(BIT_FLAGS hBit_flags, int flag_position); //Precondition: flag position is a non-negative integer and hBit flags is a handle to a valid Bit flags object //Postcondition: returns the value of the flag at index flag position if it is in bounds or -1 otherwise int bit flags_check flag(BIT_FLAGS hBit_flags, int flag_position); //Precondition: hBit flags is a handle to a valid Bitflags object //Postcondition: returns the number of bits currently held by the data structure int bit_flags_get_size(BIT_FLAGS hBit flags); //Precondition: hBit flags is a handle to a valid Bitflags object //Postcondition: returns the number of bits the object CAN hold int bit_flags_get_capacity (BIT_FLAGS hBit_flags); //Precondition: phBit flags is the address of a handle to a valid Bit_flags object //Postcondition: The menory for the object referred to by the handle is free'd and the handle is set to NULL void bit_flags_destroy(BIT_FLAGS* phBit_flags); #endif Turn in only your bit_ flags.h and bit_flags.c files for grading. The graders will use their own main program to test your data structure but you should test it as well as you can yourself with your own driver. The graders will also assume you are using the status.h we created in class. Please note that you may not change prototype of any of these functions as the functions must work with our driver you can only use these In the comments section of your code think about your data structure and what might be missing Come up with one proposed function that you could add to the interface (you do not have to This program will take the first few daily assignments and combine their behaviors to make an opaque object wrapper that allows for all the behaviors we want in a bit collection data structure called BIT FLAGS #ifndef BIT FLAGS H define BIT FLAGS H include "status . h" typedef void BIT FLAGS //Intentionally leaving out a default init function to force user to at least guess at the size needed //If one WERE to be used it would have the following prototype //BIT_FLAGS bit flags init_default(void); //Precondition: number of bits is a positive integer //Postcondition: Returns the handle to a valid Bit flags object that has the ability to store up to /I number_of_bits bits but currently all flags are set at zero. Returns NULL on failure. The container I is assumed to hold size-number_of_bits after the init function runs BIT_FLAGS bit_flags_init_number_of_bits(int number_of_bits); //Precondition: flag position is a non-negative integer and hBit flags is a handle to a valid Bit flags object //Postcondition: The flag at the flag position index is set to 1. Function will attempt to resize the /I internal representation if the flag position is too large instead of failing for out of bounds. Returns // SUCCESS if the operation is successful and FAILURE if the operation fails a needed resize. This II operation is considered to be expensive if flag position is constantly going out of bounds by a small /I amount because the resize always attempts to mininize the amount of space required to store the bits All new flags created in a resize operation (except the one being set) will be set as zero Status bit flags_set_flag(BIT_FLAGS hBit flags, int flag position); //Precondition: flag position is a non-negative integer and hBit flags is a handle to a valid Bit flags object //Postcondition: The flag at the flag position index is set to 8 Function will attempt to resize the /I internal representation if the flag position is too large instead of failing for out of bounds. Returns // SUCCESS if the operation is successful and FAILURE if the operation fails a needed resize. This II operation is considered to be expensive if flag position is constantly going out of bounds by a small /I amount because the resize always attempts to mininize the amount of space required to store the bits All new flags created in a resize operation will be set as zero Status bit_flags_unset flag(BIT_FLAGS hBit_flags, int flag_position); //Precondition: flag position is a non-negative integer and hBit flags is a handle to a valid Bit flags object //Postcondition: returns the value of the flag at index flag position if it is in bounds or -1 otherwise int bit flags_check flag(BIT_FLAGS hBit_flags, int flag_position); //Precondition: hBit flags is a handle to a valid Bitflags object //Postcondition: returns the number of bits currently held by the data structure int bit_flags_get_size(BIT_FLAGS hBit flags); //Precondition: hBit flags is a handle to a valid Bitflags object //Postcondition: returns the number of bits the object CAN hold int bit_flags_get_capacity (BIT_FLAGS hBit_flags); //Precondition: phBit flags is the address of a handle to a valid Bit_flags object //Postcondition: The menory for the object referred to by the handle is free'd and the handle is set to NULL void bit_flags_destroy(BIT_FLAGS* phBit_flags); #endif Turn in only your bit_ flags.h and bit_flags.c files for grading. The graders will use their own main program to test your data structure but you should test it as well as you can yourself with your own driver. The graders will also assume you are using the status.h we created in class. Please note that you may not change prototype of any of these functions as the functions must work with our driver you can only use these In the comments section of your code think about your data structure and what might be missing Come up with one proposed function that you could add to the interface (you do not have to
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started