Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program this on C This is the status.h header file: num status { FAILURE, SUCCESS }; typedef enum status Status; enum boolean { FALSE, TRUE

Program this on C

This is the status.h header file:

num status { FAILURE, SUCCESS };

typedef enum status Status;

enum boolean { FALSE, TRUE };

typedef enum boolean Boolean

#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 number_of_bits bits but currently all flags are set at zero. Returns NULL on failure. The container 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 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 operation is considered to be expensive if flag_position is constantly going out of bounds by a small amount because the resize always attempts to minimize 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 0. Function will attempt to resize the 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 operation is considered to be expensive if flag_position is constantly going out of bounds by a small amount because the resize always attempts to minimize 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 Bit_flags 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 Bit_flags 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 memory 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions