C++ Project APIIT

download C++ Project APIIT

of 22

description

staff management system in C++ with diagrams

Transcript of C++ Project APIIT

22ContentsIntroduction2UML3Use case3Use case Specification4Sequence Diagram6Class Diagram7Object oriented concepts8Classes8Objects9Encapsulation10Data Hiding10Constructor11Function overriding11Function overloading12Inheritance12Polymorphism13Validation14Test plan19Conclusion21References22

IntroductionThis documentation gives an overview of staff management system which has been developed in C++ programming language. In this system has been tried to use object oriented concepts as much as possible such as inheritance, polymorphism, function overloading and objects as well as classes. To make sure system working smoothly there has been some validation for birthdates, employment date, gender and some more functions such as menu and navigation through the system using Switch statement. The data are stored in a file and each record is distinguished by staff id which is considered record number in the file. A series of diagrams has been provided to ensure deep understanding of the system and its sequence of functions.

UMLUse case

Use case SpecificationUse caseAdd Staff

DescriptionAdds staff information according to their designation

ActorHr , Admin

Pre-conditionAdmin or HR personnel have to be logged in to perform the task.

Main Flow1. User login provide user name and password to login to the system.2. Once inside main menu, user chooses Add staff 3. All fields such as name, gender, Date of birth has to be filled up

Alternative Flow- Error will be popped if the user enters wrong entry for Gender, date of birth and employments date.

Use caseAdd HR

DescriptionAdds HR staff to the system

ActorHr , Admin

Pre-conditionAdmin has to be logged in to perform the task.

Main Flow1. Admin Selects Add HR option2. Admin fills up information related to HR personnel3. Information are saved to the file at end of this case.

Alternative Flow- Error will be popped if the user enters wrong entry for Gender, date of birth and employments date.

Use caseView Records

DescriptionThis case allows users to view staffs records

ActorHR, Admin , Staff

Pre-conditionUser must be logged in with its own privileges

Main Flow1) User selects View Records in their menu which is shown according to their privileges.2) For staff they have to search their id first. But for admin and hr just shows a list of records.

Alternative FlowWrong entry of user id for staff can shows someone elses records.

Use caseSearch Records

DescriptionAllows users to search for staffs records

ActorHR , Admin

Pre-conditionAdmin and Hr personnel must be logged in the system.

Main Flow1) User select Search Records option from the user menu2) The system will prompt the user to select any option of Searching by Id, name, department and IC number.3) The system will search the records according to provided information.

Alternative Flow- It shows continue menu if any wrong choice were selected- No record found on the staff who is being searched

Use caseEdit Records

DescriptionAllows admin and HR users to edit staffs records

ActorHR , Admin

Pre-conditionAdmin and Hr personnel must be logged in the system.

Main Flow1. User select Edit Records option from the user menu2. The system will prompt the user to enter ID or name of the staff to edit3. Changes are added to the record and saved

Alternative Flow- Error will be popped if the user enters wrong entry for Gender, date of birth and employments date.

Use caseDelete Records

DescriptionAllows Admin and HR to delete staffs records

ActorAdmin, HR

Pre-conditionAdmin and Hr personnel must be logged in the system.

Main Flow1) System prompt user to enter ID of the record to delete2) Message shows deletion has been successful.

Alternative FlowSystem shows error if the entered ID doesnt exist.

Sequence Diagram

Class Diagram

Object oriented concepts

ClassesThere are 3 classes in the staff management system which is used as a part of inheritance application in the code. Admin parent classclass admin{

// defining protected variables which will be accessable by child classesprotected:string department,Marital_Status,Gender;int Age,last,Eemployee_ID,location,IC,DOByear,DOBday,DOBmonth,Employment_Day,Employment_Month,Employment_Year;

char EmpName[80],Nationality[20],Religion[10];

// static variables to prevent from memory waste and duplicationstatic int depart , Record_No , choice,genderS;

public:// vistual fucntions ( application of polymorphism)virtual void menu();virtual void Add_Staff();virtual void DisplayRecords();virtual void EditRecords();virtual void SearchRecords();virtual void DeleteRecord();

void OpenFile(); // function to open the record filevoid WriteFile(); // function to write to record filevoid CloseFile(); // function to colose the file

void Add_HR(); // function that allows admin to add HR staff

}AdminObject; // object declration

HR child class of adminlass hr:public admin{

static int choiceL;public:// overriden functions from the paretn class void menu();void DisplayRecords();void Add_Staff();void SearchRecords();void EditRecords();void DeleteRecord();

}hrObject; // creation of hr objectStaff child class of Admin//application of inheritanceclass normal_user : public admin{public:void menu();void DisplayRecords();

}StaffObject; // declaration of an object

ObjectsThe main objects in the staff management system including Login object Admin class object, Human resource class object and Staff class object. The following code indicates the declaration of objects in the staff management system.login_module log;}HrObject;}AdminObject;}StaffObject;f.write((char *)&AdminObject,sizeof (AdminObject));

EncapsulationEncapsulation is the process of combining data and functions into a single unit called class. In staff management system all the variables and functions wrapped together into classes to provide encapsulation.class admin{

protected:string department,Marital_Status,Gender;int Age,last,Eemployee_ID,location,IC,DOByear,DOBday,DOBmonth,Employment_Day,Employment_Month,Employment_Year;

char EmpName[80],Nationality[20],Religion[10];static int depart , Record_No , choice,genderS;

public:virtual void menu();virtual void Add_Staff();virtual void DisplayRecords();virtual void EditRecords();virtual void SearchRecords();virtual void DeleteRecord();void OpenFile(); void WriteFile(); void CloseFile(); void Add_HR(); }AdminObject;Data HidingData encapsulation led to the important concept of data hiding. Data hiding is the implementation details of a class that are hidden from the user. The following class members are hidden from the rest of program and accessible only within the parent class.protected:string department,Marital_Status,Gender;int Age,last,Eemployee_ID,location,IC,DOByear,DOBday,DOBmonth,Employment_Day,Employment_Month,Employment_Year;

char EmpName[80],Nationality[20],Religion[10];

ConstructorConstructor is a function which is called automatically every time an object is created .it has the same name as class. If there is no constructor is defined, C++ invokes adefault constructor, which allocates memory for the object, butdoesn't initialize it. there is no constructor has been used in this assignment.Employee::Employee(void){

empID = "-";name = "-";IC = "-";DOB = "-";nationality = "-";religion = "-";maritialStatus = "-";}Function overridingWhen a child class has a function as the same name as the function in the parent class but it has different implementation it called function overriding. The following code indicated Menu overriding by child classes.Admin Menu functionvoid admin::menu(){ cout