Sie sind auf Seite 1von 6

(Done by S M OHIDUL ALAM,FCSIT,UNIVERSITY MALAYSIA SARAWAK)

Write a C++ program that able to manage a companys employee


records. The feature set for this program includes the following.
The ability to add an employee
The ability to fire an employee
The ability to promote an employee
The ability to view all employees, past and present
Extension
The ability to view all current employees
The ability to view all former employees

Algorithm of the Program


1.Firstly,class name has been declared and inside the class there are two
section devided.
2.In private section,variables for the class have been declared and in public
section,functions are declared for the class.Private variables are only
accessable by the class functions only.
3.Constructors have been build outside the class.When the compiler will be
asked to run the program,the constructors will be read by the compiler but
wont be run untill the constructors have been called by the main function
directly or indirectly.
4.Main function is the function where execution of the program will be done.

Source Code:

/***********************************************
* Editor: S M OHIDUL ALAM
MATRIC NO:40254
*
* Subject: Data Structure and Algorithm
*
* Terms: Copyright protected
*
***********************************************/
#include <iostream>
#include <string>
using namespace std;

//declaring standard

class OHD
//class declaration
{
private:
//private member for class only
string firstname,secondname; //declaring string variable
int num=0,opt,age;
//declaring integer variable
int sallary,i,fireid=0;
public:
void menu();
//declaring function
void addemp();
void fireemp();

void promoteemp();
void currentemp();
void allemp();
}emp[30];

//declaring class variable

void OHD::menu()
//constructor
{
int opt;
initiate:
cout<<"\n************ OHD Enterprise LTD ******************"<<endl;
cout<<"1.Add employee"<<endl;
cout<<"2.Fire employee"<<endl;
cout<<"3.Promote employee"<<endl;
cout<<"4.Current employee"<<endl;
cout<<"5.All Employee(Present&Past)"<<endl;
cout<<"6.Exit "<<endl;
cout<<"**************************************************"<<endl;
cout<<"Enter a option(1-6): ";
cin>>opt;
cout<<"\n\n"<<endl;
sub:
switch(opt)
{
case 1:
OHD::addemp();
goto initiate;
break;
case 2:
OHD::fireemp();
goto initiate;
break;
case 3:
OHD::promoteemp();
goto initiate;
break;
case 4:
OHD::currentemp();
goto initiate;
break;
case 5:
OHD::allemp();
goto initiate;
break;
case 6:
cout<<"Thank you!!for using my application. :-)"<<endl;
break;
default:
cout<<"Wrong input,Try again: ";
cin>>opt;
goto sub;
break;
}
}
void OHD::addemp()
{
cout<<"Enter the employee number you want to add(30 max): ";
cin>>num;
cout<<"\n";
for(i=1;i<=num;i++)
//looping
{
cout<<"Enter the First Name of the Employee "<<i<<" (No space): ";
cin>>emp[i].firstname;
cout<<"Enter the Second Name of the Employee "<<i<<" (No space): ";
cin>>emp[i].secondname;
cout<<"Enter the Age of the employee "<<i<<" (Number digit only): ";
cin>>emp[i].age;

cout<<"Enter the sallary of the employee "<<i<<" (Number digit only):


";
cin>>emp[i].sallary;
cout<<"The ID of the employee is "<<i<<".";
cout<<"\n"<<endl;
}
cout<<"Records have been saved successfully!!\n\n"<<endl;
}
void OHD::fireemp()
{
cout<<"Enter an ID to fire employee(You can only fire one employee in
every program execution): ";
cin>>fireid;
cout<<"\n";
con:
if((fireid>1)&&(fireid<num))
//condition
{
cout<<"The Employee(ID: "<<fireid<<") has been fired from job\n\n"<<endl;
cout<<"\n**************Updated Employee List******************"<<endl;
cout<<"NAME \t\t"<<" ID \t\t"<<" AGE \t\t"<<" Sallary"<<endl;
for(i=1;i<fireid;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
for(i=fireid+1;i<=num;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
cout<<"\n"<<endl;
}
else if(fireid==1)
{
cout<<"The Employee(ID: "<<fireid<<") has been fired from
job\n\n"<<endl;
cout<<"\n**************Updated Employee List******************"<<endl;
cout<<"NAME \t\t"<<" AGE \t\t"<<" Sallary"<<endl;
for(i=2;i<=num;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
cout<<"\n"<<endl;
}
else if(fireid==num)
{
cout<<"The Employee(ID: "<<fireid<<") has been fired from
job\n\n"<<endl;
cout<<"\n**************Updated Employee List******************"<<endl;
cout<<"NAME \t\t"<<" AGE \t\t"<<" Sallary"<<endl;
for(i=1;i<num;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
cout<<"\n"<<endl;
}
else

{
cout<<"Wrong input,Try again: ";
cin>>fireid;
goto con;
}
}
void OHD::promoteemp()
{
int id,amnt=0;
cout<<"Enter an ID to promote employee: ";
cin>>id;
cout<<"\n"<<endl;
cout<<"Enter the amount to be increased: ";
cin>>amnt;
cout<<"\n"<<endl;
for(i=id;i<=id;i++)
{
emp[i].sallary=emp[i].sallary+amnt;
cout<<"The Employee(id:"<<id<<") is promoted to sallary:
"<<emp[i].sallary<<" .Congratulations!!\n"<<endl;
}
}
void OHD::currentemp()
{
cout<<"\n**************Current Employee******************"<<endl;
cout<<"NAME\t\t"<<" ID\t\t"<<" AGE \t\t"<<" Sallary"<<endl;
if((fireid>1)&&(fireid<num))
{
for(i=1;i<fireid;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
for(i=fireid+1;i<=num;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
cout<<"\n"<<endl;
}
else if(fireid==1)
{
for(i=2;i<=num;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
cout<<"\n"<<endl;
}
else if(fireid==num)
{
for(i=1;i<num;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
cout<<"\n"<<endl;

}
else if(fireid==0)
{
for(i=1;i<=num;i++)
{
cout<<emp[i].firstname<<"
"<<emp[i].secondname<<"\t\t"<<i<<"\t\t"<<emp[i].age<<"\t\t"<<emp[i].sallary<<e
ndl;
}
cout<<"\n"<<endl;
}
}
void OHD::allemp()
{
cout<<"********************All Employee***********************"<<endl;
cout<<"*
Name
|
ID
|
Age
| Sallary *"<<endl;
cout<<"*******************************************************\n"<<endl;
for(i=1;i<=num;i++)
{
cout<<i<<". "<<emp[i].firstname<<" "<<emp[i].secondname<<"
"<< i <<"
"<<emp[i].age<<"
"<<emp[i].sallary<<endl;
cout<<"\n"<<endl;
}
}
int main()
//main function
{
OHD obj;
//class object declaration
obj.menu(); //class function execution
return 0;

Screen ShotS:

***
(Done by S M OHIDUL ALAM,FCSIT,UNIVERSITY MALAYSIA SARAWAK)

Das könnte Ihnen auch gefallen