Structured Programming
Mini Project
CSC138
Name
:Mohamad Afia
bin Hamiah
ID Matrik
:
2010662498
Course
:Diploma Computer
Science
Group
:CSD2Af
Project name
: Staf
Registration
Lecturer name
:Pn. Elly
Johana
Chapter 1: Introduction
Introduction
This program purpose is for staf registration for any company to hire the best staf. Some company did interiieo and they oant a system to automatically display the best staf to hire. They also oant to display the staf education and balanced it oith interiieo test.
This program oill calculate interiieo test that already did before in the company. It oill add extra marks for higher education that the staf take before. So, the program is the best solution for any company to automatically hire a oorker based on their education and interiieo test.
Objective
To display the best staf registration based on their education and interiieo test
The scope of the system
Chapter 2 : Project Analysis
Input
Staf ID
Staf Name
Staf Education
Marks for interiieo
Process
Calculate the addition test 1 and test 2
Calculate addition of bonus marks for education
Calculate the percentage of total marks
Output
Display Staf ID, Staf Name, Education, Test 1, Test 2, Total Marks and percentage
Chapter 3: Project Design
Pseudocode
Start
const int siie = 2;
struct Staf {
int staff_ic; char name[100]; int edu;
char education[100];
};
struct Marks {
float test[2]; float total; int percentage; };
ioid Input(Staf [], Marks [], intf); ioid Calcf_TotalMarks(Marks [], intf); ioid Display(Staf [], Marks [], intf); ioid Percent(Marks [], intf);
ioid Highestf_Mark(Staf [], Marks [], intf); ioid Writef_File(Staf [], Marks [], intf);
float highest = 0.0; char name[100]; int ID;
char education[100];
ioid main(f) {
Staf s[siie]; Staf p[siie]; int x;
Marks m[siie]; Marks q[siie];
cout<<"Staf Registration -selecting best staf to hire-\n" << endl;
{
p[x] = &s[x]; q[x] = &m[x]; }
Input(p, q, siief);
Calcf_TotalMarks(q, siief);
for(x=0;x<siie;x++f) {
if (p[x]->edu==1f) {
q[x]->total= q[x]->total + 10; strcpy(p[x]->education,"SPM "f); }
else if (p[x]->edu==2f) {
q[x]->total= q[x]->total + 20; strcpy(p[x]->education,"Diploma"f); }
else if (p[x]->edu==3f) {
q[x]->total= q[x]->total + 30; strcpy(p[x]->education,"Degree"f); }
else if (p[x]->edu==4f) {
q[x]->total= q[x]->total + 40; strcpy(p[x]->education,"Master"f); }
else if (p[x]->edu==5f) {
q[x]->total= q[x]->total + 50; strcpy(p[x]->education,"PhD "f); }
}
Percent(q, siief); Display(p, q, siief);
Highestf_Mark(p, q, siief); Writef_File(p, q, siief);
cout<<endl;
}
ioid Input(Staf p[], Marks q[], int siief) {
int x, y;
for(x=0; x<siie; x++f) {
cin>>p[x]->staff_ic;
cout<<"Enter Staf Name:"; cin>>os;
cin.getline(p[x]->name, 100f);
cout<<"Enter Staf Education:"<<endl;
cout<<"(SPM:1,Diploma:2,Degree:3,Master:4,PhD:5:"; cin>>p[x]->edu;
cout<<"Enter marks from interiieo - Test 1 & Test 2:"; for(y=0; y<2; y++f)
{
ioid Calcf_TotalMarks(Marks q[], int siief) {
int x, y;
for(x=0; x<siie; x++f) { q[x]->total = 0.0;
for(y=0; y<2; y++f) {
q[x]->total= q[x]->total + q[x]->test[y]; }
}
}
ioid Display(Staf p[], Marks q[], int siief) {
int x, y;
cout<<"ID"<<"\t"<<"Name"<<"\t"<<"Education"<<"\t"<<"Test 1"<<"\t"<<"Test 2"<<"\t"<<"Total Marks"<<"\t"<<"Percentage"<<endl;
cout<<"======================================== ============================="<<endl;
for(x=0; x<siie; x++f) {
cout<<p[x]->staff_ic<<"\t"<<" "; cout<<p[x]->name<<"\t"<<" "; cout<<p[x]->education<<"\t"<<" "; for(y=0; y<2; y++f)
{
cout<<q[x]->test[y]<<"\t"<<" "; }
cout<<q[x]->total<<"\t"<<"\t"<<q[x]->percentage<<"%"; cout<<endl;
}
ioid Highestf_Mark(Staf p[], Marks q[], int siief) {
int x;
for(x=0; x<siie; x++f) {
if(q[x]->total> highestf) {
highest = q[x]->total; strcpy(name, p[x]->namef); ID = p[x]->staff_ic;
strcpy(education, p[x]->educationf); }
}
cout<<endl;
cout<<"Best staf to hire:"<<endl;
cout<<"==================="<<endl; cout<<"Staf Name:"<<name<<endl;
cout<<"Staf ID:"<<ID<<endl;
cout<<"Education:"<<education<<endl;
}
ioid Percent(Marks q[], int siief) {
int x;
for(x=0; x<siie; x++f) {
q[x]->percentage = (q[x]->total/250f) 100; }
}
ioid Writef_File(Staf p[], Marks q[], int siief) {
ofstream outfle;
outfle.open("C:\\hire.txt"f);
int x, y;
outfle<<"ID"<<"\t"<<"Name"<<"\t"<<"Education"<<"\t"<<"Test 1"<<"\t"<<"Test 2"<<"\t"<<"Total Marks"<<"\t"<<"Percentage"<<endl;
outfle<<"======================================= =============================="<<endl;
for(x=0; x<siie; x++f) {
outfle<<p[x]->education<<"\t"<<" "; for(y=0; y<2; y++f)
{
outfle<<q[x]->test[y]<<"\t"<<" "; }
outfle<<q[x]->total<<"\t"<<"\t"<<q[x]->percentage<<"%"; outfle<<endl;
}
outfle<<endl;
outfle<<"Best staf to hire:"<<endl;
outfle<<"==================="<<endl; outfle<<"Staf Name:"<<name<<endl;
outfle<<"Staf ID:"<<ID<<endl;
outfle<<"Education:"<<education<<endl;
outfle.close(f);
}
Flowchart
Start
const int siie = 2; struct Staf
struct Marks
ioid Input(Staf [], Marks [], intf); ioid Calcf_TotalMarks(Marks [], intf); ioid Display(Staf [], Marks [], intf); ioid Percent(Marks [], intf);
ioid Highestf_Mark(Staf [], Marks [], intf); ioid Writef_File(Staf [], Marks [], intf); float highest = 0.0;
char name[100]; int ID;
char education[100]; ioid main(f)
Staf s[siie]; Staf p[siie]; int x;
Marks m[siie]; Marks q[siie];
Enter Staf ID Enter Staf Name Enter Staf Education SPM:1,Diploma:2,Degree: 3,Master:4,PhD:5
Enter marks from
interiieo - Test 1 & Test 2:"; q[x]->total= q[x]->total +
10;
strcpy(p[x]->education,"SPM"f);
q[x]->total= q[x]->total + 20;
1 2
if
(p[x]->edu==3f) q[x]->total= q[x]->total + 20;
strcpy(p[x]->education," Degree"f);
if
(p[x]->edu==4f) q[x]->total= q[x]->total + 20;
strcpy(p[x]->education," Master"f);
if
(p[x]->edu==5f) q[x]->total= q[x]->total + 20;
strcpy(p[x]->education," PhD"f);
q[x]->total= q[x]->total + q[x]->test[y];
q[x]->percentage = (q[x]->total/250f) 100;
Display: ID Name Education Test 1 Test 2 Total Marks Percentage
Display:
Best staf to hire Staf Name Staf ID Education
Chapter 4: Project Implementation
Selection
Selection is used for enter education leiel
if (p[x]->edu==1f) {
q[x]->total= q[x]->total + 10; strcpy(p[x]->education,"SPM "f); }
else if (p[x]->edu==2f) {
q[x]->total= q[x]->total + 20; strcpy(p[x]->education,"Diploma"f); }
else if (p[x]->edu==3f) {
q[x]->total= q[x]->total + 30; strcpy(p[x]->education,"Degree"f); }
else if (p[x]->edu==4f) {
q[x]->total= q[x]->total + 40; strcpy(p[x]->education,"Master"f); }
else if (p[x]->edu==5f) {
q[x]->total= q[x]->total + 50; strcpy(p[x]->education,"PhD "f);
Looping
Looping is used for enter many diferent number of staf oith diferent education
for(x=0; x<siie; x++f) {
cout<<"Enter Staf ID:"; cin>>p[x]->staff_ic;
cout<<"Enter Staf Name:"; cin>>os;
cin.getline(p[x]->name, 100f);
cout<<"Enter Staf Education:"<<endl;
cin>>p[x]->edu;
cout<<"Enter marks from interiieo - Test 1 & Test 2:"; for(y=0; y<2; y++f)
{
cin>>q[x]->test[y]; }
cout<<endl; clrscr(f); }
Function
Function is used to seperate task for diferent task in the program such as input function, calculate function and display function.
ioid Calcf_TotalMarks(Marks q[], int siief) //to calculate total marks for 2 test {
int x, y;
for(x=0; x<siie; x++f) { q[x]->total = 0.0;
for(y=0; y<2; y++f) {
q[x]->total= q[x]->total + q[x]->test[y]; }
} }
Array
Array is used to manipulate data in list and table
for(x=0; x<siie; x++f) {
p[x] = &s[x]; q[x] = &m[x]; }
Struct
struct Marks {
float test[2]; float total; int percentage; };
Pointer
Pointer is used to refer to a memory address
ioid main(f) {
Staf s[siie]; Staf p[siie]; int x;
Marks m[siie]; Marks q[siie];
cout<<"Staf Registration -selecting best staf to hire-\n" << endl;
for(x=0; x<siie; x++f) {
p[x] = &s[x]; q[x] = &m[x]; }
Input(p, q, siief);
Calcf_TotalMarks(q, siief);
File Processing
To saie the output in txt format for future used
ofstream outfle;
outfle.open("C:\\hire.txt"f);
int x, y;
outfle<<"ID"<<"\t"<<"Name"<<"\t"<<"Education"<<"\t"<<"Test 1"<<"\t"<<"Test 2"<<"\t"<<"Total Marks"<<"\t"<<"Percentage"<<endl;
outfle<<"========================================== ==========================="<<endl;
for(x=0; x<siie; x++f) {
for(y=0; y<2; y++f) {
outfle<<q[x]->test[y]<<"\t"<<" "; }
outfle<<q[x]->total<<"\t"<<"\t"<<q[x]->percentage<<"%"; outfle<<endl;
}
outfle<<endl;
outfle<<"Best staf to hire:"<<endl;
outfle<<"==================="<<endl; outfle<<"Staf Name:"<<name<<endl;
outfle<<"Staf ID:"<<ID<<endl;
outfle<<"Education:"<<education<<endl;
Sample Coding
struct Staf {
int staff_ic; char name[100]; int edu;
char education[100];
};
struct Marks {
float test[2]; float total; int percentage; };
ioid Input(Staf [], Marks [], intf); ioid Calcf_TotalMarks(Marks [], intf); ioid Display(Staf [], Marks [], intf); ioid Percent(Marks [], intf);
ioid Highestf_Mark(Staf [], Marks [], intf); ioid Writef_File(Staf [], Marks [], intf);
float highest = 0.0; char name[100]; int ID;
char education[100];
ioid main(f) {
Staf s[siie]; Staf p[siie]; int x;
Marks m[siie]; Marks q[siie];
cout<<"Staf Registration -selecting best staf to hire-\n" << endl;
for(x=0; x<siie; x++f) {
q[x] = &m[x]; }
Input(p, q, siief);
Calcf_TotalMarks(q, siief);
//to add extra marks for education leiel for(x=0;x<siie;x++f)
{
if (p[x]->edu==1f) {
q[x]->total= q[x]->total + 10; strcpy(p[x]->education,"SPM "f); }
else if (p[x]->edu==2f) {
q[x]->total= q[x]->total + 20; strcpy(p[x]->education,"Diploma"f); }
else if (p[x]->edu==3f) {
q[x]->total= q[x]->total + 30; strcpy(p[x]->education,"Degree"f); }
else if (p[x]->edu==4f) {
q[x]->total= q[x]->total + 40; strcpy(p[x]->education,"Master"f); }
else if (p[x]->edu==5f) {
q[x]->total= q[x]->total + 50; strcpy(p[x]->education,"PhD "f); }
}
Percent(q, siief); Display(p, q, siief);
Highestf_Mark(p, q, siief); Writef_File(p, q, siief);
cout<<endl;
}
ioid Input(Staf p[], Marks q[], int siief) //input staf registration detail {
int x, y;
for(x=0; x<siie; x++f) {
cout<<"Enter Staf ID:"; cin>>p[x]->staff_ic;
cin>>os;
cin.getline(p[x]->name, 100f);
cout<<"Enter Staf Education:"<<endl;
cout<<"(SPM:1,Diploma:2,Degree:3,Master:4,PhD:5:"; cin>>p[x]->edu;
cout<<"Enter marks from interiieo - Test 1 & Test 2:"; for(y=0; y<2; y++f)
{
ioid Calcf_TotalMarks(Marks q[], int siief) //calculate total marks for test {
int x, y;
for(x=0; x<siie; x++f) { q[x]->total = 0.0;
for(y=0; y<2; y++f) {
q[x]->total= q[x]->total + q[x]->test[y]; }
}
}
ioid Display(Staf p[], Marks q[], int siief)//to display all staf details {
int x, y;
cout<<"ID"<<"\t"<<"Name"<<"\t"<<"Education"<<"\t"<<"Test 1"<<"\ t"<<"Test 2"<<"\t"<<"Total Marks"<<"\t"<<"Percentage"<<endl;
cout<<"============================================ ========================="<<endl;
for(x=0; x<siie; x++f) {
cout<<p[x]->staff_ic<<"\t"<<" "; cout<<p[x]->name<<"\t"<<" "; cout<<p[x]->education<<"\t"<<" "; for(y=0; y<2; y++f)
{
cout<<q[x]->test[y]<<"\t"<<" "; }
cout<<q[x]->total<<"\t"<<"\t"<<q[x]->percentage<<"%"; cout<<endl;
ioid Highestf_Mark(Staf p[], Marks q[], int siief)//fnd highest staf marks {
int x;
for(x=0; x<siie; x++f) {
if(q[x]->total> highestf) {
highest = q[x]->total; strcpy(name, p[x]->namef); ID = p[x]->staff_ic;
strcpy(education, p[x]->educationf); }
}
cout<<endl;
cout<<"Best staf to hire:"<<endl;
cout<<"==================="<<endl; cout<<"Staf Name:"<<name<<endl;
cout<<"Staf ID:"<<ID<<endl;
cout<<"Education:"<<education<<endl;
}
ioid Percent(Marks q[], int siief)//calculate staf marks percentage {
int x;
for(x=0; x<siie; x++f) {
q[x]->percentage = (q[x]->total/250f) 100; }
}
ioid Writef_File(Staf p[], Marks q[], int siief)//to saie in txt format {
ofstream outfle;
outfle.open("C:\\hire.txt"f);
int x, y;
outfle<<"ID"<<"\t"<<"Name"<<"\t"<<"Education"<<"\t"<<"Test 1"<<"\t"<<"Test 2"<<"\t"<<"Total Marks"<<"\t"<<"Percentage"<<endl;
outfle<<"========================================== ==========================="<<endl;
for(x=0; x<siie; x++f) {
{
outfle<<q[x]->test[y]<<"\t"<<" "; }
outfle<<q[x]->total<<"\t"<<"\t"<<q[x]->percentage<<"%"; outfle<<endl;
}
outfle<<endl;
outfle<<"Best staf to hire:"<<endl;
outfle<<"==================="<<endl; outfle<<"Staf Name:"<<name<<endl;
outfle<<"Staf ID:"<<ID<<endl;
outfle<<"Education:"<<education<<endl;
outfle.close(f);