Friday, 23 November 2012

How does it work?

What is it?

The program is an employee time scheduler for employers. It was made with the idea that Ron’s mother needed software that allowed her to keep track of all of her employees. Thus we created a simple time keeping solution.
Our solution allows the user to add employees by adding data files to the folder 'docs' – It has to only contain the name of the employee and a return to a new line. The rest will be taken care by the program. Deletion is also as simple as just deleting the desired employees data file.
When you launch the program you are able to see all of the employees of your company and their `status` - if they are Check In or Checked Out. (Currently in the `Office` working or not)
Then it allows the user to
                    change the status of the employee by just writing in their ID. This also stores the time of the status change in the data file.
                    print out all of the times the employees were at work by typing 88

The Code


As a main data structure we used a fixed size array of Structs to hold employee data, each Struct contains variables for employee details, name time etc.

The main function calls the function listContents and passes a reference of the variable numberOfEmployees to it. The listContents method returns char **, this is a pointer to char array, which in turn is a string containing the file names of the files where the employee data is stored. Due to the fact that number of employees was passed as a reference we are able to modify it so the rest of the program knows how many employees there are. This is done by reading the files from the specified directory, checking the file is valid,  if not valid it returns a NULL pointer, otherwise, using the dirent library we read in all of the files in the directory. We had use a conditional statement to make sure we were only reading correct files, not system links ( . and .. ). When adding file names to the array we had to malloc space for each character array created.

After the arrays of filenames have been returned, the function readEmployeeFile is called. This function opens up each file that has been added to the array created in the previous function. This then initialises and sets up the array that is used to store our employee Structs. After reading the file, it parses the data from the file and creates a Struct from the data contained and adds this to the array.
After all of this initialisation, main then calls mainMenu function. This is a continuous loop that displays the menu to the user using the terminal and waits for user input. If the user enters 99, the program terminates. If the user enters 88, the program lists all employees with how long they have been “clocked in”. This is achieved by looping through the array of Structs and printing out the information contained in each Struct. If the user enters a user ID, the program first checks if it is valid input and if the employee exists. If these checks fail it prompts the user to re-enter a valid choice. If the user selects a valid ID then the function changeStatus is called.
This function firstly checks to see if the user has clocked in already, then updates the time variable in its corresponding Struct, and writes the time to the employee file. It calculates the difference between start time and end time using the time library and prints out to the user how long they were clocked in for. It does this by appending the start time and total worked time to the employee file. If the employee wasn’t “clocked in” the function only adds the start time to the Struct, and the user is now technically “clocked in”.

1 comment:

  1. A bit edgy, but I suppose that's what it's meant to be like. As I wrote a considerable part of the program, I understand it. I'm not sure however, if anybody else would understand the program or its functionality from this text

    ReplyDelete