/* Store insurance policy holder info (gender, minor/major, policy name, duration) using bit-fields.
*/
/* Let Us C, Chap- 22 (Miscellaneous Features), Qn No.: C(b) */

/* This file is auto-generated by a bot. */
/* This code is not compiled; it is for reference only. */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Define structure with bit-fields
struct policy_holder
{
    char policy_name[50];
    unsigned int duration : 7;  // 0-127 years is sufficient for policy duration
    unsigned int gender : 1;    // 0: Male, 1: Female (1 bit)
    unsigned int status : 1;    // 0: Minor, 1: Major (1 bit)
};

int main()
{
    struct policy_holder p;
    int temp_gen, temp_stat, temp_dur;

    printf("--- Enter Policy Holder Details ---\n");

    printf("Policy Name: ");
    scanf(" %[^\n]s", p.policy_name); // Reads string with spaces

    printf("Duration (Years): ");
    scanf("%d", &temp_dur);
    p.duration = temp_dur;

    printf("Gender (0 for Male, 1 for Female): ");
    scanf("%d", &temp_gen);
    p.gender = temp_gen;

    printf("Status (0 for Minor, 1 for Major): ");
    scanf("%d", &temp_stat);
    p.status = temp_stat;

    printf("\n--- Policy Information Stored ---\n");
    printf("Policy:   %s\n", p.policy_name);
    printf("Duration: %u years\n", p.duration);
    
    // Interpret bits for display
    printf("Gender:   %s\n", (p.gender == 1) ? "Female" : "Male");
    printf("Status:   %s\n", (p.status == 1) ? "Major" : "Minor");
    
    printf("\nSize of structure: %zu bytes\n", sizeof(p));
    // Note: Size will be policy_name size + padding + integer size containing the bits
    
    return 0;
}
