Sunteți pe pagina 1din 22

PCPP Assignment Page 1

1
Contents
Introduction ................................................................................................................................ 2
UML ........................................................................................................................................... 3
Use case ................................................................................................................................. 3
Use case Specification ........................................................................................................... 4
Sequence Diagram ................................................................................................................. 6
Class Diagram ........................................................................................................................ 7
Object oriented concepts ............................................................................................................ 8
Classes.................................................................................................................................... 8
Objects ................................................................................................................................... 9
Encapsulation ....................................................................................................................... 10
Data Hiding .......................................................................................................................... 10
Constructor ........................................................................................................................... 11
Function overriding .............................................................................................................. 11
Function overloading ........................................................................................................... 12
Inheritance............................................................................................................................ 12
Polymorphism ...................................................................................................................... 13
Validation ................................................................................................................................. 14
Test plan ................................................................................................................................... 19
Conclusion ............................................................................................................................... 21
References ................................................................................................................................ 22









PCPP Assignment Page 2

2
Introduction
This 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.



















PCPP Assignment Page 3

3
UML
Use case



PCPP Assignment Page 4

4
Use case Specification
Use case Add Staff
Description Adds staff information according to their designation
Actor Hr , Admin
Pre-condition Admin or HR personnel have to be logged in to perform the task.
Main Flow
1. 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 case Add HR
Description Adds HR staff to the system
Actor Hr , Admin
Pre-condition Admin has to be logged in to perform the task.
Main Flow
1. Admin Selects Add HR option
2. Admin fills up information related to HR personnel
3. 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 case View Records
Description This case allows users to view staffs records
Actor HR, Admin , Staff
Pre-condition User must be logged in with its own privileges
Main Flow
1) 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 Flow Wrong entry of user id for staff can shows someone elses records.



PCPP Assignment Page 5

5
Use case Search Records
Description Allows users to search for staffs records
Actor HR , Admin
Pre-condition Admin and Hr personnel must be logged in the system.
Main Flow
1) User select Search Records option from the user menu
2) 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 case Edit Records
Description Allows admin and HR users to edit staffs records
Actor HR , Admin
Pre-condition Admin and Hr personnel must be logged in the system.
Main Flow
1. User select Edit Records option from the user menu
2. The system will prompt the user to enter ID or name of the staff to
edit
3. 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 case Delete Records
Description Allows Admin and HR to delete staffs records
Actor Admin, HR
Pre-condition Admin and Hr personnel must be logged in the system.
Main Flow
1) System prompt user to enter ID of the record to delete
2) Message shows deletion has been successful.
Alternative Flow System shows error if the entered ID doesnt exist.




PCPP Assignment Page 6

6
Sequence Diagram









PCPP Assignment Page 7

7
Class Diagram
+ menu() : void
+DisplayRecords() : void
Staff
+menu() : void
+Add_Staff() : void
+DisplayRecords() : void
+EditRecords() : void
+SearchRecords() : void
+DeleteRecord() : void
+OpenFile() : void
+WriteFile() : void
+CloseFile() : void
+void Add_HR() : void
#department : String
#Marital_Status : String
#Gender : String
#Age : int
#Employee_ID : int
#location : int
#IC : int
#DOByear : int
#DOBmonth : int
#DOBday : int
#Emplyoment_Day : int
#Employment _Month : int
#Employment _Year : int
#EmpName : char
#Nationality : char
#Religion : char
#depart : int
#Record_No : int
#chioce : int
#GenderS : int
Admin
+menu() : void
+DisplayRecords() : void
+Add_Staff() : void
+SearchRecords() : void
+EditRecords() : void
+DeleteRecord() : void
-choiceL : int
HR


PCPP Assignment Page 8

8
Object oriented concepts

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

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

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

// static variables to prevent from memory waste and duplication
static 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 file
void WriteFile(); // function to write to record file
void CloseFile(); // function to colose the file


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

}AdminObject; // object declration







PCPP Assignment Page 9

9
HR child class of admin
lass 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 object
Staff child class of Admin
//application of inheritance
class normal_user : public admin
{
public:
void menu();
void DisplayRecords();


}StaffObject; // declaration of an object

Objects
The 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));



PCPP Assignment Page 10

10
Encapsulation
Encapsulation 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,Em
ployment_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 Hiding
Data 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,Em
ployment_Month,Employment_Year;

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





PCPP Assignment Page 11

11
Constructor
Constructor 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 a default
constructor, which allocates memory for the object, but doesn't initialize it. there is no
constructor has been used in this assignment.
Employee::Employee(void){

empID = "-";
name = "-";
IC = "-";
DOB = "-";
nationality = "-";
religion = "-";
maritialStatus = "-";
}
Function overriding
When 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 function
void admin::menu()
{
cout<<"\tTo Continue press(1) \n";
cout<<"\tTo Exit press (2) \n\n";
cin>>ChoiceF;
cin.ignore();
system ("cls");
if(ChoiceF==1)
{
cout<<"\n\t\t\tADMIN MENU\n\n";
cout<<"\n*************************************\n";
cout<<"select any option\n\n";
cout<<" 1 ---> Add HR "<<endl;
cout<<" 2 ---> Add Staff "<<endl;
cout<<" 3 ---> View records "<<endl;
cout<<" 4 ---> Search a record "<<endl;
cout<<" 5 ---> Edit for a record "<<endl;
cout<<" 6 ---> Delete a record "<<endl;
cout<<" 0 ---> Exit "<<endl;
cout<<"\n*************************************\n";
cin>>inputFile;
cin.ignore();
system ("cls");
}
else
{
exit(1); //
}
}

PCPP Assignment Page 12

12

HR overridden Menu function
void hr::menu()
{
cout<<"Human Resource Menu\n\n";
cout<<"\n*****************************************\n";
cout<<" 1--> Add staff "<<endl;
cout<<" 2--> View records "<<endl;
cout<<" 3--> Edit records "<<endl;
cout<<" 4--> Search records "<<endl;
cout<<" 5--> Delete records "<<endl;
cout<<" 0--> Exit "<<endl;
cout<<"\n******************************************\n";
cin>>choFile_HR;
cin.ignore();
system ("cls");
}
Function overloading
Overloaded functions are having same name but different parameters. To mention that in this
assignment function overloading hasnt been used.

Employee::Employee(void)
{ }
Employee::Employee(string empID1, string Name)
{ }

Inheritance
Inheritance is the process by which new classes called derived classes are created from
existing classes called base classes. Child classes have all the feature of the parent classes. In
staff management system there are 2 derived classes from Admin class which is the parent
class. The following shows how child classes are declared

Parent class
class admin
{
}

Child classes
class hr:public admin
{

}
class normal_user : public admin
{
}

PCPP Assignment Page 13

13
Polymorphism
Virtual functions
The virtual keywords tell the compiler that this function could be use by derived classes and
could have their own implementations.
virtual void menu();
virtual void Add_Staff();
virtual void DisplayRecords();
virtual void EditRecords();
virtual void SearchRecords();
virtual void DeleteRecord();
Function overriding
The HR menu has different implementation and it differs slightly from the parent class which
is Admin class.
void hr::menu()
{
cout<<"Human Resource Menu\n\n";
cout<<"\n*****************************************\n";
cout<<" 1--> Add staff "<<endl;
cout<<" 2--> View records "<<endl;
cout<<" 3--> Edit records "<<endl;
cout<<" 4--> Search records "<<endl;
cout<<" 5--> Delete records "<<endl;
cout<<" 0--> Exit "<<endl;
cout<<"\n******************************************\n";
cin>>choFile_HR;
cin.ignore();
system ("cls");

Pointer object
admin *p;
p=&AdminObject;
Arrow object
p->Add_HR();
p->OpenFile();
p->CloseFile();

p->WriteFile();





PCPP Assignment Page 14

14
Validation

Main menu
User can select 3 different types of login including Login as Admin, Hr or staff user.
if (option == 1 || option == 2 || option == 3 )
{
get_access();
check_access();

}

else
if (option == 4 )

exit(1);


else

cout<< " Please enter any number between 1 to 4 ";


}
Users Menu
Loading different menus according to user privileges defined in the system.
if(AccessOption==1) // shows admin menus
{
admin_Menu();
}
if(AccessOption==2) // shows hr menus
{
HR_Menu();
}
if(AccessOption==3) // shows staff menus
{

User login tries
Validation the number of wrong username and password tries.
if(cfile<3){ // checking number of wrong user tries
cfile++;
system("cls");
start();
}else
{
exit(1);}



PCPP Assignment Page 15

15
Day of birth
To ensure any number from 1 to 12 is entered which represents number of month.
if(DOBmonth<1||DOBmonth>12) // validating month to not exceed more than 12
month
{

cout<<"\n Wrong Entry!!:";
cout<<"\n Enter a number between 1 to 12 \n:";
cin>>DOBmonth;
cin.ignore();
}
Month of birth
To ensure any number from 1 to 31 is entered.
if(DOBday<1||DOBday>31) // validating the days to be between 1 to 31
{

cout<<"\n Wrong Entry!!:";
cout<<"\n Enter a number between 1 to 31\n :";
cin>>DOBday;
cin.ignore();

Year of birth
To ensure the age of employee is above eighteen years old during registration.
if(DOByear<1900||DOByear>1991) // validating the year of birth to not to
be less than 18 yrs old
{

cout<<"\n Wrong Entry!! :";
cout<<"\n too young to get Employed \n :";
cin>>DOByear;
cin.ignore();
}


Employment day
To ensure any day from 1 to 31 is entered.
if(Employment_Day<1||Employment_Day>31) // validating the epmplotment day
{
//Employment_Day=0;
cout<<"\n Wrong Entry!!:";
cout<<"\n Enter a number between 1 to 31\n :";

cin>>Employment_Day;
cin.ignore();
}

PCPP Assignment Page 16

16
Employment month
To ensure month of employment is from 1 to 12.
if(Employment_Month<1||Employment_Month>12) // validating month to not
exceed more than 12 month
{
//Employment_Month=0;
cout<<"\n Wrong Entry!!:";
cout<<"\n Enter a number between 1 to 12\n :";
cin>>Employment_Month;
cin.ignore();
}
Employment year
if(Employment_Year<2000||Employment_Year>2012) // year vlaidation
{
//Employment_Year=0;
cout<<"\n Wrong Entry!! :";
cout<<"\n Enter a date between 2000 to 2012 \n :";
cin>>Employment_Year;
cin.ignore();
}

Department selection
Using switch statement to reduce user error and simplifying system use.
switch(depart)
{
case 1: // if the value is 1 department = Managing director
department="Managing Director";
case 2: // if the value is 2 department = senior manager
department="Senior Manager";
break;
case 3: // if the value is 3 department = Manager
department="Manager";
break;
case 4: // if the value is 4 department = Senior Executive
department="Senior Executive";
break;
case 5: // if the value is 5 department = Executive
department="Executive";
break;
case 6: // if the value is 6 department = Junior Executive
department="Junior Executive"; // show the statment under department
break;

default:
cout<<"No such department exists!!\n";

department="None";// setting department value to None
}


PCPP Assignment Page 17

17
Gender
Using Switch statement to prevent user entering wrong gender.
switch(gendersw)
{
case 1:
Gender ="Male";
break;
case 2:
Gender ="Female";
break;
default:
cout<<"Wrong Entry!!\n";
cout<<"\nEnter gender";
cout<<"\n 1 --> male | 2 --> female
cin>>gendersw;
} // end switch

General navigation
switch (choice_file)
{

case 1:
{
StaffObject.DisplayRecords();
cout<<"**************************************************************
\n";
cout<<"Press (1) To continue\n";
cout<<"Press (2) To previous menu\n";
cout<<"press (3) To Exit\n\n";
cin>>continu;
system ("cls");
cin.ignore();break;
}
default:
{
exit(1);
}
}
}

Checking access

if((user_input.compare(Admin_user)==0&&pass_input.compare(Admin_passw
ord)==0)
||(user_input.compare(Hr_user)==0&&pass_input.compare(Hr_password)==0)
||(user_input.compare(Staff_user)==0&&pass_input.compare(Staff_passwo
rd)==0))

{

if(user_input=="admin") // if user name is = adimin then load Admin
menu
{
cout<<"\n\t\t************************************************\n";
cout<<"\n\t\t\t\tWELCOME ADMINSTRATOR\n";
cout<<"\n\t\t************************************************\n";
AccessOption=1;

PCPP Assignment Page 18

18
}

else if(user_input=="hr") // if the input was hr then load hr menu
{
cout<<"\n\t\t************************************************\n";
cout<<"\n\t\t\tWELCOME HUMAN RESOURCE PERSONNEL\n\n";
cout<<"\n\t\t************************************************\n";
AccessOption=2;
}
else if(user_input=="staff") // if the input was staff then load
staff menu
{
cout<<"\n\t\t************************************************\n";
cout<<"\n\t\t\t\tWELCOME STAFF\n\n";
cout<<"\n\t\t************************************************\n";
AccessOption=3;
}}
else
{
if(UserTries<3){ // checking number of wrong user tries
UserTries++;
system("cls");
start();
}else
{
exit(1);}
}}
















PCPP Assignment Page 19

19
Test plan

Admin
Test Case Criteria Expected result Actual result
Login Login with admin
account.
Displays admin
menu.
As expected
View Record User select my
account
Display users
particulars.
As expected.
User search for a staff
and select staff from the
search result.
Display the staffs
particulars.
As expected
Edit Record User select Edit to edit
particulars.
Prompt for field to
edit, store changes
and display edited
field in user
information.
As expected
Delete Record User search for a staff
and select Delete from
search result choice
menu.
Removes the staff
relation and re-
display the new
search results
As expected
Search Record User select Search Prompt for user
search string or
ID, then display
search result,
prompt for user
search hit staff
choice
As expected
Add new account User select Add Human
Resource or Add Staff
Prompt for fields
entry, validate
entry, create new
employee ID and
display, store new
employee, display
registration
success
As expected







PCPP Assignment Page 20

20
Human Resource
Component Criteria Expected result Actual result
Login Login with human
resource staff account.
Displays human
resource staff
menu.
As expected
View Record User select my
account
Display users
particulars.
As expected
User search for a staff
and select staff from the
search result.
Display the staffs
particulars.
As expected
Edit Record User select Edit to edit
particulars.
Prompt for field to
edit, store changes
and display edited
field in user
information.
As expected
Delete Record User search for a staff
and select Delete from
search result choice
menu.
Removes the staff
relation and re-
display the new
search results
As expected
Search Record User select Search Prompt for user
search string or
ID, then display
search result,
prompt for user
search hit staff
choice
As expected
Add new account User select Add Staff Prompt for fields
entry, validate
entry, create new
employee ID and
display, store new
employee, display
registration
success
As expected
Staff
Component Criteria Expected result Actual result
Login Login with staff account. Displays staff
menu.
As expected
View Staff Information Search staff information
by name or ID
Display staff
particulars and
infos.
As expected


PCPP Assignment Page 21

21
Conclusion
Team members effort in this assignment finally led to development of Staff management
system. Despite facing all problems and hardships regarding understanding and application of
object oriented concepts throughout this assignment we have realized we still havent gained
enough knowledge to develop slightly complicated applications. As we have realized C++
has many features to be learned and once it is learnt it could possibly lead to more powerful
applications. In conclusion this subject has given us a basic understanding of C++ and
especially OOP concepts since we had difficulty to understand it in Java and VB. Finally not
to forget to appreciate lecturers effort in making this subject more understandable for the
students and solving their problem without hesitation.


















PCPP Assignment Page 22

22
References

Joyce Farrell (2009). Object-Oriented Programming Using C++ . 4th ed. Boston,USA:
Course Technology. 223-451.
Joyce Farrell (2009). Object-Oriented Programming Using C++ . 4th ed. Boston,USA:
Course Technology. 615-670
Harvey Deitel, Paul J. Deitel (2010). C++ How to Program . 7th ed. USA: Pearson
education. 68-102, 345-377,395-509, 572-620.
Gregory Satir, Doug Brown (1995). C++: the core language. USA: Oreilly. 141-165.
Stephen R. Davis (2009). C++ for Dummies. 6th ed. USA: Willey. 159-273, 293-311.
Sanchit Karve . (2004). Polymorphism Tutorial. Available:
http://www.dreamincode.net/forums/topic/9872-polymorphism-tutorial/. Last accessed 1 Feb
2011
Sanchit Karve. (2005). POLYMORPHISM with C++ - OBJECT ORIENTED
PROGRAMMING. Available: http://www.programmers-corner.com/tutorial/36. Last
accessed 1 Feb 2011.
Juan Soulie. (2010). Friendship and inheritance. Available: www.. Last accessed 2 Feb 2010.
Juan Soulie. (2010). input/Output with files. Available:
http://www.cplusplus.com/doc/tutorial/files/. Last accessed 5 Feb 2011.
Juan Soulie. (2010). Polymorphism. Available:
http://www.cplusplus.com/doc/tutorial/polymorphism/. Last accessed 1 Feb 2011.
Juan Soulie. (2010). Classes (I). Available: http://www.cplusplus.com/doc/tutorial/classes/.
Last accessed 1 Feb 2011.
Martin Fowler (2003). UML distilled: a brief guide to the standard object modeling
language . 3rd ed. USA: Pearson education. 35-84.
Joseph Schmuller (2004). Sams teach yourself UML in 24 hours . 3rd ed. USA: Sams. 31-89.

S-ar putea să vă placă și