/******************************************************
 * Comprehensive Examination - II sem 1999-2000
 * Computer Programming - I
 * 5 May 2000
 * ***************************************************/

/*
 *  You are developing an employee management application for Macrohard Inc. Loharu.  The organization has 1000 employees.  Each employee's employee number, name, designation pay scale and salary has to be stored.  There are 10 different pay scales in the company; the salary depends on an employee's pay scale.  Excluding Gill Bates Chaudhary the CEO, the organizational structure has ten different designations each of which is associatied with a rank.  the rank ranges from 1 to 10 withe lowest rank given to the lowest and the hightest rank, given to the highest designation.  
 *
 *  You are required to write a complete C program that takes an employee number as input and geerates the following details:
 *
 *  Employee name, designation, salary, date of joining and the list of designations above his designation in the organizational hierarchy.
 *
 *  If the given employee number is not found among the records, print an appropriate error message and exit.
 *
 *  Assume that the following piece of code exists.  You need to build this code.  Also note that a variable of renk_desig structure has already been defined and sorted in increasing order of rank.  Also assume that all the vaues for the structure variable have already been input.
 *
 *  Since you are developing the application for Macrohard, let your code be well indented with suitable comments.
 *
 */

main()
{
        struct date {
                int dd;         /* day value*/
                int mm;         /* month value*/
                int yy;         /* year value*/
        };

        struct employee{
                int employee_number;    /* Holds the employee number */
                char name[30];
                char designation[30];
                int payscale;           /* The payscale is an integer from 0 to 10*/
                struct date date_of_joining;
        };
        struct payscale{
                int payscale;
                float salary;   /* This holds the salary of the employee */
        };
        struct rank_desig{
                int rank;       /* rank of the corresponding designation, an integer
                                   in the range 1-10 */
                char designation[30];
        };
        /* Variables that store the values of all records
         */
        struct employee emp[1000];
        struct payscale pay_salary[10];
        struct rank_desig hierarchy[10];

        /* 
         * assume that the hierarch array is sorted according to the rank
         */
        /*
         * assume that the values for all the variables of the structure 
         * has been scanned
         */
        /* You code goes here */
        int e_num,i,j,flag=0;
        while(1)
        {
                printf("Give the employee number: ");
                scanf("%d",&e_num);
                for(i=0;i<1000;i++)
                {
                        if(emp[i].employee_number==e_num)
                        {
                                printf("Name: \t\t%s\n",emp[i].name);
                                printf("Designation:\t\t%s\n",emp[i].designation);
                                for(j=0;j<10;j++)
                                        if(pay_salary[j].payscale==emp[i].payscale)
                                        {
                                                printf("Salary:\t\t%.2f\n",pay_salary[j].salary);
                                                break;
                                        }
                                printf("Date of Joining (DD-MM-YY):\t%d-%d-%d\n",\
                                                emp[i].date_of_joining.dd,\
                                                emp[i].date_of_joining.mm,\
                                                emp[i].date_of_joining.yy);
                                printf("List of Designations above that of the employee:\n");
                                for(j=9;j>=0;j--)
                                {
                                        if(!flag && strcmp(emp[i].designation,hierarchy[j].designation)==0)
                                                {
                                                        flag=1;
                                                        continue;
                                                }
                                        if(flag)
                                                printf("\t\t%s\n",hierarchy[j].designation);
                                                                
                                }
                                break; //Breaks the for loop
                        }/*End of if employee found*/
                }/*End of For*/
                if(i==1000)
                {
                        /*
                         * Employee number not found in the records
                         */
                        printf("No employee is present with the given employee number");
                        exit(1);
                }
                printf("Do you want to continue <y>/n: ");
                i=getchar();
                if(toupper(i)=='N')
                        exit(0);
        }
        
} /* End of main() */