Академический Документы
Профессиональный Документы
Культура Документы
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];
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<<"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)