SlideShare a Scribd company logo
//Classes(or Libraries)
#include
#include
#include
#include
#include
//Used to shorten console commands
using namespace std;
//Programmer defined encapsulation of data and functions
class Department
{
private:
string DepartmentName, DepartmentHeadName, DepartmentID;
public:
// Constructors
Department()
{
}
Department(string id, string name)
{
DepartmentID = id;
DepartmentName = name;
DepartmentHeadName = "";
}
Department(string id, string name, string hn)
{
DepartmentID = id;
DepartmentName = name;
DepartmentHeadName = hn;
}
//Setter and getters(Accsesors)
string getDepId()
{
return DepartmentID;
}
string getDepartmentName()
{
return DepartmentName;
}
string getDepHeadName()
{
return DepartmentHeadName;
}
void setDepId(string DepId)
{
DepartmentID = DepId;
}
void setDepName(string DepName)
{
DepartmentName = DepName;
}
void setDepHead(string DepHead)
{
DepartmentHeadName = DepHead;
}
};
//Programmer defined encapsulation of data and functions
class Employee
{
private:
string employeename, employeeID, employeeDepartmentID;
int employeeage;
doubleemployeesalary;
public:
// constructors
Employee() {}
Employee(string id, string name)
{
employeeID = id;
employeename = name;
}
Employee(string id, string name, int age)
{
employeeID = id;
employeename = name;
employeeage = age;
}
Employee(string id, string name, int age, double salary)
{
employeeID = id;
employeename = name;
employeeage = age;
employeesalary = salary;
}
Employee(string id, string name, int age, double salary, string
departmentid)
{
employeeID = id;
employeename = name;
employeeage = age;
employeesalary = salary;
employeeDepartmentID = departmentid;
}
// Accessors
string getEmpID()
{
return employeeID;
}
string getEmpName()
{
return employeename;
}
string getEmpDepID()
{
return employeeDepartmentID;
}
int getEmpAge()
{
return employeeage;
}
double getEmpSal()
{
return employeesalary;
}
void setEmpID(string empId)
{
employeeID = empId;
}
void setEmpName(string empName)
{
employeename = empName;
}
void setEmpDepID(string empDepId)
{
employeeDepartmentID = empDepId;
}
void setEmpAge(int empAge)
{
employeeage = empAge;
}
void setEmpSalary(double empsal)
{
employeesalary = empsal;
}
};
//Function prototypes
void ShowMenu();
void choices();
int main()
{
ShowMenu();
choices();
return 0;
}
//Display Function
void ShowMenu()
{
cout << "nnn";
cout << "1-Create Departmentn";
cout << "2-Creat employeen";
cout << "3-Write the data to the filen";
cout << "4-Retrive the data from the filen";
cout << "5-Display Reportn";
cout << "6-Exitn n n";
}
// Choice function
void choices()
{
// Creating array objects
Department dep[3];
Employee emp[7];
string depid, empid, empdepid, depname, dephead, empname,
depnamefile, depdeadfile;
int empage;
double empsalary;
int choice;
ifstream file_in, file_in2;
ofstream file_out, file_out2;
char again; //Used to loop the entire program
int counter, empcounter, depcounter;
bool id3 = false;
int a; //used for getting age from file
double s; //used for getting salarry from file
string info; // getting lines from file
size_t pos; //position
double sal1, sal2, sal3; //Salaries for calculation
do {
cout << "Please enter a number from the menu:";
cin >> choice;
switch (choice)
{
case 1:
cout << "Please enter Department ID:";
cin >> depid;
//Loop to not get a duplicate
for (int i = 0; i < 3; i++)
{
while (dep[i].getDepId() == depid)
{
cout << "The Department ID that you entered exist. Try again:";
cin >> depid;
}
}
//Condition to make sure not over arrays
if (depcounter < 3)
{
cout << "Please enter the department name:";
cin >> depname;
cout << "Please enter the department head:";
cin >> dephead;
dep[depcounter].setDepId(depid);
dep[depcounter].setDepName(depname);
dep[depcounter].setDepHead(dephead);
depcounter++;
}
else
cout << "Array is full.n";
ShowMenu();
break;
case 2:
cout << "Please enter the employee ID:";
cin >> empid;
//Loop to not get duplicate
for (int i = 0; i < 7; i++)
{
while (emp[i].getEmpID() == empid)
{
cout << "The Employee ID that you entered exist. Try again:";
cin >> empid;
}
}
//condition to not go over arrays sizes
if (empcounter < 7) {
cout << "Please enter the employee department ID:";
cin >> empdepid;
for (int i = 0; i < 7; i++)
{
if (dep[i].getDepId() == empdepid)
{
id3 = true;
break;
}
}
if (id3)
{
cout << "Please enter the employee Name:";
cin >> empname;
cout << "Please enter the employee Age:";
cin >> empage;
cout << "Please enter the employee salary:";
cin >> empsalary;
emp[empcounter].setEmpID(empid);
emp[empcounter].setEmpName(empname);
emp[empcounter].setEmpDepID(empdepid);
emp[empcounter].setEmpAge(empage);
emp[empcounter].setEmpSalary(empsalary);
empcounter++;
}
else
cout << "Department not foundn";
}
else
cout << "Array is full.n";
ShowMenu();
break;
case 3:
//condition to mmake sure objects are compelted, the
write to file
if (depcounter == 3 && empcounter == 7)
{
file_out.open("dep.txt");
for (int counter = 0; counter < 3; counter++)
{
file_out << "Department ID: " << dep[counter].getDepId() <<
endl;
file_out << "Department Name: " <<
dep[counter].getDepartmentName() << endl;
file_out << "Department Head Name: " <<
dep[counter].getDepHeadName() << endl;
file_out << endl << endl;
}
file_out.close();
file_out2.open("emp.txt");
for (int counter = 0; counter < 7; counter++)
{
file_out2 << "Employee ID: " << emp[counter].getEmpID() <<
endl;
file_out2 << "Employee Name: " <<
emp[counter].getEmpName() << endl;
file_out2 << "Employee Age: " << emp[counter].getEmpAge()
<< endl;
file_out2 << "Employee Salary: " << emp[counter].getEmpSal()
<< endl;
file_out2 << "Employee Department ID: " <<
emp[counter].getEmpDepID() << endl;
file_out2 << endl << endl;
}
//Making sure user doesn't close the program without
saving data
cout << "File not saved. Do you want to save the file? (Y/N)n";
cin >> again;
if (toupper(again) == 'Y')
file_out.close();
file_out2.close();
}
else
cout << "Arrays not complete. Can't write into files.n" << endl
<< endl;
ShowMenu();
break;
case 4:
file_in.open("dep.txt");
if (file_in)
{
int counter;
// getting department data from file
while (getline(file_in, info) && counter < 3)
{
pos = info.find(": ");
dep[counter].setDepId(info.substr(pos + 2));
getline(file_in, info);
pos = info.find(": ");
dep[counter].setDepName(info.substr(pos + 2));
getline(file_in, info);
pos = info.find(": ");
dep[counter].setDepHead(info.substr(pos + 2));
getline(file_in, info);
getline(file_in, info);
counter++;
}
file_in.close();
}
else cout << "File Dep not found." << endl;
file_in2.open("emp.txt");
if (file_in2)
{
int counter;
//getting employee data from file
while (getline(file_in2, info) && counter < 7)
{
pos = info.find(": ");
emp[counter].setEmpID(info.substr(pos + 2));
getline(file_in2, info);
pos = info.find(": ");
emp[counter].setEmpName(info.substr(pos + 2));
getline(file_in2, info);
pos = info.find(": ");
istringstream flow(info.substr(pos + 2));
flow >> a;
emp[counter].setEmpAge(a);
getline(file_in2, info);
pos = info.find(": ");
istringstream flow1(info.substr(pos + 2));
flow1 >> s;
emp[counter].setEmpSalary(s);
getline(file_in2, info);
pos = info.find(": ");
emp[counter].setEmpDepID(info.substr(pos + 2));
getline(file_in2, info);
getline(file_in2, info);
counter++;
}
file_in2.close();
}
else cout << "File Emp not found." << endl;
ShowMenu();
break;
case 5:
//Linear search through arrays
for (int i = 0; i < 7; i++)
{
if (emp[i].getEmpDepID() == dep[0].getDepId())
{
sal1 = sal1 + emp[i].getEmpSal();
}
if (emp[i].getEmpDepID() == dep[1].getDepId())
{
sal2 = sal2 + emp[i].getEmpSal();
}
if (emp[i].getEmpDepID() == dep[2].getDepId())
{
sal3 = sal3 + emp[i].getEmpSal();
}
}
//displaying report
cout << showpoint << fixed << setprecision(2);
cout << "DepartmenttSalaryreportn";
cout << dep[0].getDepartmentName() << "tt" << sal1 << "n";
cout << dep[1].getDepartmentName() << "tt" << sal2 << "n";
cout << dep[2].getDepartmentName() << "tt" << sal3 << "n";
ShowMenu();
break;
case 6:
cout << "Exiting the program. Thank you." << endl;
break;
default:
cout << "Invalid selection. Please Try again" << endl;
ShowMenu();
break;
}
} while (choice != 6);
}
The purpose of this project is to take your Midterm project and
implement it using Random Access Binary Files.
As you recall, the Midterm project used text files to store the
data. Here in the final exam project,
you will be storing the data in Random Access Binary File.
Also, in the Midterm project you used Arrays to temporarily
hold the data in the memory until the user
decides to write the data to file. Here you will not be using
Arrays and instead writing the
data directly to Random Access Binary File. Please read the
chapter Advance File and I/O operations
before attempting this.
Here is the full description of the Final exam project.
Modify your Midterm Exam Project to:
1. Replace Employee and Department classes with Employee
and Department Structures.
2. Inside each structure, replace all string variables with array
of characters.
3. Make Employee and Department editable. That means, the
user should be able to edit a given Employee and Department.
4. Do not allow the user to edit the Employee ID and
Department ID.
5. Use Random Access Files to store the data in Binary Form.
This means, you should not use an Arrays to
store the data in the memory. Instead, when the user wants to
create a new Employee/Department,
you write it to the file right away. Also when the user says
he/she wants to edit
an Employee/Department, ask the user to enter
EmployeeID/DepartmentID.
Read the data from the file and display it to the user.
Allow the user to enter new data and write it back to the file in
the same position inside the file.
Please read the chapter . Advance File/IO operations which has
examples on how to do this.
Classes(or Libraries)#include #include #include #include.docx

More Related Content

Similar to Classes(or Libraries)#include #include #include #include.docx (20)

PPTX
CP 04.pptx
RehmanRasheed3
 
PDF
Capstone ms2
TanishGupta44
 
PDF
in C++ Design a class named Employee The class should keep .pdf
adithyaups
 
PDF
I need help to modify my code according to the instructions- Modify th.pdf
pnaran46
 
PPTX
Operator overload rr
Dhivya Shanmugam
 
PPTX
Oops presentation
sushamaGavarskar1
 
DOCX
programing fundamentals complete solutions.docx
ZAMANYousufzai1
 
DOCX
please code in c#- please note that im a complete beginner- northwind.docx
AustinaGRPaigey
 
PDF
C++ Nested loops, matrix and fuctions.pdf
yamew16788
 
DOCX
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
joellemurphey
 
PPTX
Develop an App with the Odoo Framework.pptx
ManuelVega464531
 
PDF
c++ practical Digvajiya collage Rajnandgaon
yash production
 
PDF
To write a program that implements the following C++ concepts 1. Dat.pdf
SANDEEPARIHANT
 
PDF
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
exxonzone
 
PPTX
12Structures.pptx
Aneeskhan326131
 
PPT
COW
永泉 韩
 
PDF
Programming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdf
ssuser6254411
 
PDF
Object Oriented Programming (OOP) using C++ - Lecture 5
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
PDF
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 
DOC
Pl sql using_xml
Nayana Arewar
 
CP 04.pptx
RehmanRasheed3
 
Capstone ms2
TanishGupta44
 
in C++ Design a class named Employee The class should keep .pdf
adithyaups
 
I need help to modify my code according to the instructions- Modify th.pdf
pnaran46
 
Operator overload rr
Dhivya Shanmugam
 
Oops presentation
sushamaGavarskar1
 
programing fundamentals complete solutions.docx
ZAMANYousufzai1
 
please code in c#- please note that im a complete beginner- northwind.docx
AustinaGRPaigey
 
C++ Nested loops, matrix and fuctions.pdf
yamew16788
 
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
joellemurphey
 
Develop an App with the Odoo Framework.pptx
ManuelVega464531
 
c++ practical Digvajiya collage Rajnandgaon
yash production
 
To write a program that implements the following C++ concepts 1. Dat.pdf
SANDEEPARIHANT
 
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
exxonzone
 
12Structures.pptx
Aneeskhan326131
 
Programming For Big Data [ Submission DvcScheduleV2.cpp and StaticA.pdf
ssuser6254411
 
Object Oriented Programming (OOP) using C++ - Lecture 5
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 
Pl sql using_xml
Nayana Arewar
 

More from brownliecarmella (20)

DOCX
E C O N F O C U S T H I R D Q U A R T E R 2 0 1 3 31.docx
brownliecarmella
 
DOCX
E B B 3 5 9 – E B B S P o r t f o l i o V C o u r.docx
brownliecarmella
 
DOCX
e activityhttpsblackboard.strayer.edubbcswebdavinstitutionBU.docx
brownliecarmella
 
DOCX
Dynamics of Human Service Program ManagementIndividuals who .docx
brownliecarmella
 
DOCX
Dynamic Postural Assessment Name _____________________.docx
brownliecarmella
 
DOCX
Dylan (age 45, Caucasian) is a heroin addict who has been in and o.docx
brownliecarmella
 
DOCX
Dustin,A case study is defined by Saunders, Lewis, and Thornhi.docx
brownliecarmella
 
DOCX
DWPM    71713  1  543707.1  MEMBERSHIP A.docx
brownliecarmella
 
DOCX
DwightEvaluation       Leadership style assessments certainl.docx
brownliecarmella
 
DOCX
Dwight Waldo is known for his work on the rise of the administrative.docx
brownliecarmella
 
DOCX
Dwayne and Debbie Tamai Family of Emeryville, Ontario.Mr. Dw.docx
brownliecarmella
 
DOCX
DVWASetting up DAMN VULNERABLE WEB APPLICATIONSDam.docx
brownliecarmella
 
DOCX
Dusk of DawnDiscussion questions1. Explain when we call fo.docx
brownliecarmella
 
DOCX
Durst et al. (2014) describe the burden that some Romani experience .docx
brownliecarmella
 
DOCX
DuringWeek 4, we will shift our attention to the legislative.docx
brownliecarmella
 
DOCX
DuringWeek 3, we will examine agenda setting in more depth w.docx
brownliecarmella
 
DOCX
During  the course of this class you have learned that Latin Ameri.docx
brownliecarmella
 
DOCX
During WW II, the Polish resistance obtained the German encoding mac.docx
brownliecarmella
 
DOCX
During Week 5, we studied social stratification and how it influence.docx
brownliecarmella
 
DOCX
During this week you worked with the main concepts of Set Theory. Ch.docx
brownliecarmella
 
E C O N F O C U S T H I R D Q U A R T E R 2 0 1 3 31.docx
brownliecarmella
 
E B B 3 5 9 – E B B S P o r t f o l i o V C o u r.docx
brownliecarmella
 
e activityhttpsblackboard.strayer.edubbcswebdavinstitutionBU.docx
brownliecarmella
 
Dynamics of Human Service Program ManagementIndividuals who .docx
brownliecarmella
 
Dynamic Postural Assessment Name _____________________.docx
brownliecarmella
 
Dylan (age 45, Caucasian) is a heroin addict who has been in and o.docx
brownliecarmella
 
Dustin,A case study is defined by Saunders, Lewis, and Thornhi.docx
brownliecarmella
 
DWPM    71713  1  543707.1  MEMBERSHIP A.docx
brownliecarmella
 
DwightEvaluation       Leadership style assessments certainl.docx
brownliecarmella
 
Dwight Waldo is known for his work on the rise of the administrative.docx
brownliecarmella
 
Dwayne and Debbie Tamai Family of Emeryville, Ontario.Mr. Dw.docx
brownliecarmella
 
DVWASetting up DAMN VULNERABLE WEB APPLICATIONSDam.docx
brownliecarmella
 
Dusk of DawnDiscussion questions1. Explain when we call fo.docx
brownliecarmella
 
Durst et al. (2014) describe the burden that some Romani experience .docx
brownliecarmella
 
DuringWeek 4, we will shift our attention to the legislative.docx
brownliecarmella
 
DuringWeek 3, we will examine agenda setting in more depth w.docx
brownliecarmella
 
During  the course of this class you have learned that Latin Ameri.docx
brownliecarmella
 
During WW II, the Polish resistance obtained the German encoding mac.docx
brownliecarmella
 
During Week 5, we studied social stratification and how it influence.docx
brownliecarmella
 
During this week you worked with the main concepts of Set Theory. Ch.docx
brownliecarmella
 
Ad

Recently uploaded (20)

PPTX
Capitol Doctoral Presentation -July 2025.pptx
CapitolTechU
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PDF
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
PPTX
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
How to Create Rental Orders in Odoo 18 Rental
Celine George
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PPTX
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
PPTX
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
How to Manage Promotions in Odoo 18 Sales
Celine George
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
The-Beginnings-of-Indian-Civilisation.pdf/6th class new ncert social/by k san...
Sandeep Swamy
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPTX
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
Capitol Doctoral Presentation -July 2025.pptx
CapitolTechU
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
How to Create Rental Orders in Odoo 18 Rental
Celine George
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
How to Manage Promotions in Odoo 18 Sales
Celine George
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPT on the Development of Education in the Victorian England
Beena E S
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
The-Beginnings-of-Indian-Civilisation.pdf/6th class new ncert social/by k san...
Sandeep Swamy
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
Ad

Classes(or Libraries)#include #include #include #include.docx

  • 1. //Classes(or Libraries) #include #include #include #include #include //Used to shorten console commands using namespace std; //Programmer defined encapsulation of data and functions class Department { private: string DepartmentName, DepartmentHeadName, DepartmentID; public: // Constructors Department() { } Department(string id, string name) { DepartmentID = id; DepartmentName = name; DepartmentHeadName = ""; } Department(string id, string name, string hn) { DepartmentID = id; DepartmentName = name; DepartmentHeadName = hn; }
  • 2. //Setter and getters(Accsesors) string getDepId() { return DepartmentID; } string getDepartmentName() { return DepartmentName; } string getDepHeadName() { return DepartmentHeadName; } void setDepId(string DepId) { DepartmentID = DepId; } void setDepName(string DepName) { DepartmentName = DepName; } void setDepHead(string DepHead) { DepartmentHeadName = DepHead; } };
  • 3. //Programmer defined encapsulation of data and functions class Employee { private: string employeename, employeeID, employeeDepartmentID; int employeeage; doubleemployeesalary; public: // constructors Employee() {} Employee(string id, string name) { employeeID = id; employeename = name; } Employee(string id, string name, int age) { employeeID = id; employeename = name; employeeage = age; } Employee(string id, string name, int age, double salary) { employeeID = id; employeename = name; employeeage = age; employeesalary = salary; } Employee(string id, string name, int age, double salary, string departmentid) { employeeID = id; employeename = name;
  • 4. employeeage = age; employeesalary = salary; employeeDepartmentID = departmentid; } // Accessors string getEmpID() { return employeeID; } string getEmpName() { return employeename; } string getEmpDepID() { return employeeDepartmentID; } int getEmpAge() { return employeeage; } double getEmpSal() { return employeesalary; } void setEmpID(string empId) { employeeID = empId; } void setEmpName(string empName) { employeename = empName;
  • 5. } void setEmpDepID(string empDepId) { employeeDepartmentID = empDepId; } void setEmpAge(int empAge) { employeeage = empAge; } void setEmpSalary(double empsal) { employeesalary = empsal; } }; //Function prototypes void ShowMenu(); void choices(); int main() { ShowMenu(); choices(); return 0; } //Display Function void ShowMenu() {
  • 6. cout << "nnn"; cout << "1-Create Departmentn"; cout << "2-Creat employeen"; cout << "3-Write the data to the filen"; cout << "4-Retrive the data from the filen"; cout << "5-Display Reportn"; cout << "6-Exitn n n"; } // Choice function void choices() { // Creating array objects Department dep[3]; Employee emp[7]; string depid, empid, empdepid, depname, dephead, empname, depnamefile, depdeadfile; int empage; double empsalary; int choice; ifstream file_in, file_in2; ofstream file_out, file_out2; char again; //Used to loop the entire program int counter, empcounter, depcounter; bool id3 = false; int a; //used for getting age from file double s; //used for getting salarry from file string info; // getting lines from file size_t pos; //position double sal1, sal2, sal3; //Salaries for calculation do { cout << "Please enter a number from the menu:"; cin >> choice;
  • 7. switch (choice) { case 1: cout << "Please enter Department ID:"; cin >> depid; //Loop to not get a duplicate for (int i = 0; i < 3; i++) { while (dep[i].getDepId() == depid) { cout << "The Department ID that you entered exist. Try again:"; cin >> depid; } } //Condition to make sure not over arrays if (depcounter < 3) { cout << "Please enter the department name:"; cin >> depname; cout << "Please enter the department head:"; cin >> dephead; dep[depcounter].setDepId(depid); dep[depcounter].setDepName(depname); dep[depcounter].setDepHead(dephead); depcounter++; } else cout << "Array is full.n";
  • 8. ShowMenu(); break; case 2: cout << "Please enter the employee ID:"; cin >> empid; //Loop to not get duplicate for (int i = 0; i < 7; i++) { while (emp[i].getEmpID() == empid) { cout << "The Employee ID that you entered exist. Try again:"; cin >> empid; } } //condition to not go over arrays sizes if (empcounter < 7) { cout << "Please enter the employee department ID:"; cin >> empdepid; for (int i = 0; i < 7; i++) { if (dep[i].getDepId() == empdepid) { id3 = true; break; } } if (id3)
  • 9. { cout << "Please enter the employee Name:"; cin >> empname; cout << "Please enter the employee Age:"; cin >> empage; cout << "Please enter the employee salary:"; cin >> empsalary; emp[empcounter].setEmpID(empid); emp[empcounter].setEmpName(empname); emp[empcounter].setEmpDepID(empdepid); emp[empcounter].setEmpAge(empage); emp[empcounter].setEmpSalary(empsalary); empcounter++; } else cout << "Department not foundn"; } else cout << "Array is full.n"; ShowMenu(); break; case 3: //condition to mmake sure objects are compelted, the write to file if (depcounter == 3 && empcounter == 7) { file_out.open("dep.txt"); for (int counter = 0; counter < 3; counter++)
  • 10. { file_out << "Department ID: " << dep[counter].getDepId() << endl; file_out << "Department Name: " << dep[counter].getDepartmentName() << endl; file_out << "Department Head Name: " << dep[counter].getDepHeadName() << endl; file_out << endl << endl; } file_out.close(); file_out2.open("emp.txt"); for (int counter = 0; counter < 7; counter++) { file_out2 << "Employee ID: " << emp[counter].getEmpID() << endl; file_out2 << "Employee Name: " << emp[counter].getEmpName() << endl; file_out2 << "Employee Age: " << emp[counter].getEmpAge() << endl; file_out2 << "Employee Salary: " << emp[counter].getEmpSal() << endl; file_out2 << "Employee Department ID: " << emp[counter].getEmpDepID() << endl; file_out2 << endl << endl; } //Making sure user doesn't close the program without saving data cout << "File not saved. Do you want to save the file? (Y/N)n"; cin >> again;
  • 11. if (toupper(again) == 'Y') file_out.close(); file_out2.close(); } else cout << "Arrays not complete. Can't write into files.n" << endl << endl; ShowMenu(); break; case 4: file_in.open("dep.txt"); if (file_in) { int counter; // getting department data from file while (getline(file_in, info) && counter < 3) { pos = info.find(": "); dep[counter].setDepId(info.substr(pos + 2)); getline(file_in, info); pos = info.find(": "); dep[counter].setDepName(info.substr(pos + 2)); getline(file_in, info); pos = info.find(": "); dep[counter].setDepHead(info.substr(pos + 2)); getline(file_in, info); getline(file_in, info); counter++; }
  • 12. file_in.close(); } else cout << "File Dep not found." << endl; file_in2.open("emp.txt"); if (file_in2) { int counter; //getting employee data from file while (getline(file_in2, info) && counter < 7) { pos = info.find(": "); emp[counter].setEmpID(info.substr(pos + 2)); getline(file_in2, info); pos = info.find(": "); emp[counter].setEmpName(info.substr(pos + 2)); getline(file_in2, info); pos = info.find(": "); istringstream flow(info.substr(pos + 2)); flow >> a; emp[counter].setEmpAge(a); getline(file_in2, info); pos = info.find(": "); istringstream flow1(info.substr(pos + 2)); flow1 >> s; emp[counter].setEmpSalary(s); getline(file_in2, info); pos = info.find(": "); emp[counter].setEmpDepID(info.substr(pos + 2)); getline(file_in2, info); getline(file_in2, info);
  • 13. counter++; } file_in2.close(); } else cout << "File Emp not found." << endl; ShowMenu(); break; case 5: //Linear search through arrays for (int i = 0; i < 7; i++) { if (emp[i].getEmpDepID() == dep[0].getDepId()) { sal1 = sal1 + emp[i].getEmpSal(); } if (emp[i].getEmpDepID() == dep[1].getDepId()) { sal2 = sal2 + emp[i].getEmpSal(); } if (emp[i].getEmpDepID() == dep[2].getDepId()) { sal3 = sal3 + emp[i].getEmpSal(); } } //displaying report cout << showpoint << fixed << setprecision(2); cout << "DepartmenttSalaryreportn"; cout << dep[0].getDepartmentName() << "tt" << sal1 << "n"; cout << dep[1].getDepartmentName() << "tt" << sal2 << "n"; cout << dep[2].getDepartmentName() << "tt" << sal3 << "n";
  • 14. ShowMenu(); break; case 6: cout << "Exiting the program. Thank you." << endl; break; default: cout << "Invalid selection. Please Try again" << endl; ShowMenu(); break; } } while (choice != 6); } The purpose of this project is to take your Midterm project and implement it using Random Access Binary Files. As you recall, the Midterm project used text files to store the data. Here in the final exam project, you will be storing the data in Random Access Binary File. Also, in the Midterm project you used Arrays to temporarily hold the data in the memory until the user decides to write the data to file. Here you will not be using Arrays and instead writing the
  • 15. data directly to Random Access Binary File. Please read the chapter Advance File and I/O operations before attempting this. Here is the full description of the Final exam project. Modify your Midterm Exam Project to: 1. Replace Employee and Department classes with Employee and Department Structures. 2. Inside each structure, replace all string variables with array of characters. 3. Make Employee and Department editable. That means, the user should be able to edit a given Employee and Department. 4. Do not allow the user to edit the Employee ID and Department ID. 5. Use Random Access Files to store the data in Binary Form. This means, you should not use an Arrays to store the data in the memory. Instead, when the user wants to create a new Employee/Department, you write it to the file right away. Also when the user says he/she wants to edit an Employee/Department, ask the user to enter EmployeeID/DepartmentID. Read the data from the file and display it to the user. Allow the user to enter new data and write it back to the file in the same position inside the file. Please read the chapter . Advance File/IO operations which has examples on how to do this.