/* Includes ------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
/* Define --------------------------------------------------------------------
*/
#define MAX_ROW 2
#define MAX_COLUMN 15
#define MAX_ENTERPRISE 30
/* Enum ----------------------------------------------------------------------
*/
typedef enum Status
{
Empty,
Registered
} Status;
typedef enum CommandType
{
REGISTER,
ALTER,
SHOW,
DELETE,
QUIT,
INVALID
} CommandType;
/* ---------------------------------------------------------------------------
*/
/* Begin: Student Answer
*/
/* ---------------------------------------------------------------------------
*/
// Requirement 1: Generate abbreviation from the full name of an enterprise
void getAbbreviation(char *name, char *abbre)
{
// TODO: Implement this function
}
// Requirement 2: Determine the type of command
CommandType getCommandType(char *command)
{
// TODO: Implement this function
}
// Requirement 3: Define the structure to store enterprise details
typedef struct
{
// TODO: Implement this function
} Enterprise;
// Requirement 4: Print the details of a specific enterprise
void printEnterpriseDetails(Enterprise e)
{
// TODO: Implement this function
}
// Requirement 5: Create an enterprise with specified values
void createEnterprise(Enterprise *e, int booth_index, int itemValue, int
itemWeight, char *name, char *abbre)
{
// TODO: Implement this function
}
// Requirement 6: Register an enterprise to a booth
void registerEnterprise(int map[MAX_ROW][MAX_COLUMN], Enterprise
enterpriseArray[MAX_ENTERPRISE],
char *name, int booth, int
itemValue, int itemWeight, int *out_booth, char *out_abbre)
{
// TODO: Implement this function
}
// Requirement 7: Display the booth map and status
void showMap(int map[MAX_ROW][MAX_COLUMN])
{
// TODO: Implement this function
}
// Requirement 8: Show booth indexes based on their status
void showIndexOfStatus(Enterprise enterpriseArray[MAX_ENTERPRISE], Status
status)
{
// TODO: Implement this function
}
// Requirement 9: Show the total count of booths with a specific status
void showTotalOfStatus(Enterprise enterpriseArray[MAX_ENTERPRISE], Status
status)
{
// TODO: Implement this function
}
// Requirement 10: Display details of booths in a specified range
void showIndexBracket(Enterprise enterpriseArray[MAX_ENTERPRISE], int start,
int end)
{
// TODO: Implement this function
}
// Requirement 11: Handle the "Show" command and call the appropriate function
void handleShowCommand(int map[MAX_ROW][MAX_COLUMN], Enterprise
enterpriseArray[MAX_ENTERPRISE], char *command)
{
// TODO: Implement this function
}
// Requirement 12: Alter the booth assignment for a specified enterprise
void alterEnterprise(int map[MAX_ROW][MAX_COLUMN], Enterprise
enterpriseArray[MAX_ENTERPRISE], char *abbre,
int registerBooth, int newBooth, int
*out_booth, char *out_abbre)
{
// TODO: Implement this function
}
// Requirement 13: Delete an enterprise from the system
void deleteEnterprise(int map[MAX_ROW][MAX_COLUMN], Enterprise
enterpriseArray[MAX_ENTERPRISE], char *abbre, int booth, int *totalEmpty)
{
// TODO: Implement this function
}
// Requirement 14: Process commands and call the relevant function
void handleCommand(char *command, int map[MAX_ROW][MAX_COLUMN], Enterprise
enterpriseArray[MAX_ENTERPRISE], CommandType *commandType)
{
// TODO: Implement this function
}
// Requirement 15: Optimize items collected using the knapsack algorithm
int knapsack(int map[MAX_ROW][MAX_COLUMN], Enterprise
enterpriseArray[MAX_ENTERPRISE],
int maxWeight)
{
//TODO: Return the maximum value collected
}
/* ---------------------------------------------------------------------------
*/
/* End: Student Answer
*/
/* ---------------------------------------------------------------------------
*/
/* ---------------------------------------------------------------------------
*/
/* Example Test Cases for Main
*/
/* ---------------------------------------------------------------------------
*/
// Initializes booth map and enterprise array to default values and then
// runs a series of test cases to verify enterprise registration, booth
// assignments, alterations, and knapsack optimization functionality.
// Initialize the booth map with default status Empty
void initMap(int map[MAX_ROW][MAX_COLUMN])
{
for (int i = 0; i < MAX_ROW; i++)
{
for (int j = 0; j < MAX_COLUMN; j++)
{
map[i][j] = Empty;
}
}
}
// Initialize the enterprise array with default values
void initEnterpriseArray(Enterprise enterpriseArray[MAX_ENTERPRISE])
{
for (int i = 0; i < MAX_ENTERPRISE; i++)
{
enterpriseArray[i].booth_index = -1;
strcpy(enterpriseArray[i].name, "");
strcpy(enterpriseArray[i].abbre, "");
enterpriseArray[i].itemValue = 0;
enterpriseArray[i].itemWeight = 0;
}
}
int main()
{
// Initialize the map and enterprise array
int map[MAX_ROW][MAX_COLUMN];
Enterprise enterpriseArray[MAX_ENTERPRISE];
initMap(map);
initEnterpriseArray(enterpriseArray);
int booth;
char abbrev[10];
int totalEmpty = 0;
// Test Case 1: Register enterprises with automatic booth assignment
registerEnterprise(map, enterpriseArray, "Tech Co", -1, &booth,
abbrev);
printf("Registered 'Tech Co' at booth %d with abbreviation %s\n",
booth, abbrev);
registerEnterprise(map, enterpriseArray, "Innovative Solutions", 10,
&booth, abbrev);
printf("Registered 'Innovative Solutions' at booth %d with
abbreviation %s\n", booth, abbrev);
registerEnterprise(map, enterpriseArray, "NextGen", -1, &booth,
abbrev);
printf("Registered 'NextGen' at booth %d with abbreviation %s\n",
booth, abbrev);
// Test Case 2: Show map to confirm booth registration
printf("\nMap Status after Registrations:\n");
showMap(map);
// Test Case 3: Show indexes based on their status
printf("\nEmpty Booths:\n");
showIndexOfStatus(enterpriseArray, Empty);
printf("\nRegistered Booths:\n");
showIndexOfStatus(enterpriseArray, Registered);
// Test Case 4: Show total count of booths with specific status
printf("\nTotal Empty Booths:\n");
showTotalOfStatus(enterpriseArray, Empty);
printf("Total Registered Booths:\n");
showTotalOfStatus(enterpriseArray, Registered);
// Test Case 5: Register an enterprise to an already occupied booth
registerEnterprise(map, enterpriseArray, "CompeteX", 10, &booth,
abbrev);
if (booth == -1)
{
printf("\nBooth 10 is already occupied. Registration failed
for 'CompeteX'.\n");
}
// Test Case 6: Alter the booth assignment for an enterprise
printf("\nAltering 'NextGen' from current booth to booth 12:\n");
alterEnterprise(map, enterpriseArray, "N", booth, 12, &booth, abbrev);
if (booth != -1)
{
printf("Booth assignment altered successfully for 'NextGen' to
booth %d.\n", booth);
}
else
{
printf("Failed to alter booth assignment for 'NextGen'.\n");
}
// Show map to confirm the booth alteration
printf("\nMap Status after Alteration:\n");
showMap(map);
// Test Case 7: Delete an enterprise and free up the booth
printf("\nDeleting 'Innovative Solutions' from booth 10:\n");
deleteEnterprise(enterpriseArray, "I", 10, &totalEmpty);
printf("Total empty booths after deletion: %d\n", totalEmpty);
// Show map to confirm deletion
printf("\nMap Status after Deletion:\n");
showMap(map);
// Test Case 8: Knapsack optimization test with sample data
int maxWeight = 10;
int maxValue, usedWeight;
knapsack(map, enterpriseArray, maxWeight, &maxValue, &usedWeight);
printf("\nKnapsack Optimization:\n");
printf("Max Value Collected: %d with Weight Used: %d\n", maxValue,
usedWeight);
return 0;
}