Would someone be able to compose the following program to be written in C++, alo
ID: 3874438 • Letter: W
Question
Would someone be able to compose the following program to be written in C++, along with a constructed text file to run with it. If you could most importantly comment your code, that would be helpful to a beginner. Just need something neat, and efficient. Showing sample output to confirm it will compile is important. Please see code snippet below:
Your assignment is to implement a singly linked pointer based list using an employee class. The employee class should contain the empl oy ee information listed in the "input" section below. The program should contain all functions listed in the functionality section below. Input Data about current employees should be on the file "Employee.txt". You will need to create your own employee file and submit it with the final project Each employee should have the following attributes: Integer String String Integer .Employee_Number Employee Last_Name . Employee_First Name Employee_Years_of Service 3 employees must be loaded from the Employee.txt file on program start up. Functionality Command ADD REMOVE COUNT PRINT QUIT Processing Select table columnle user to "Add" an employee to the list ows the user to "Remove" an emplovee from the list Returns the number of emplovees in the list Prints the emplovee information in the list to the console Stops processin Output All output should be on the console. Data Structures This program should utilize a singly linked pointer based list.Explanation / Answer
Employee.cpp
#include<iostrem.h>
#include<fstream.h>
#include<stdlib.h>
#include<iomanip.h>
#include<string.h>
#include<stdio.h>
const char* fName="Emp.txt";
Class Emp
{
private;
int ids;
char names[50],position[50],depta[10];
float sal;
public;
void readDat();
int getId();
void dispRec();
char* getDept();
};
void Emp::readDat()
{
cout<<endl<<“Employee ids:”;
cin>>ids;
cout<<“Employee Name:”;
cin>>names;
cout<<“Employee’s position:”;
cin>>position;
cout<<“Employee’s depta:”;
cin>>depta;
cout<<“Salary:”;
cin>>sal;
}
void Emp::dispRec()
{
cout<<endl<<“_______________________________”;
cout<<endl<<setw(5)<<ids<<setw(15)<<names<<setw(15)<<position<<setw(15)<<depta<<setw(8)<<sal;
}
int Emp::getId()
{
return ids;
}
char* Emp::getDept()
{
return depta;
}
void main()
{
Emp emp,ee;
char choice,cho,depta[50];
int ids,found;
fstream fl;
fl.open(fName,ios::ate|ios::in|ios::out|ios::binary);
do
{
cout<<********Menu********;
cout<<endl<<“Enter your option”;
cout<<endl<<“1 => Add a new record”;
cout<<endl<<“2 => Search record from Emp id”;
cout<<endl<<“3 => List Emp of particular department”;
cout<<endl<<“4 => Display all employee”;
cout<<endl<<“5 => Update record of an employee”;
cout<<endl<<“6 => Delete record of particular employee”;
cout<<endl<<“7 => Exit from the program”<<endl;
cout<<“********************”<<endl;
cin>>choice;
switch(choice)
{
case ‘1’:
emp.readDat();
fl.seekg(0,ios::beg);
found=0;
fl.read((char*)&ee,sizeof(ee));
while(!fl.eof())
{
if(ee.getId()==emp.getId())
{
cout<<“This ids already exist…Try for another ID”;
found=1;
break;
}
fl.read((char*)&ee,sizeof(ee));
}
if(found==1)
break;
fl.clear();
fl.seekp(0,ios::end);
fl.write((char*)&emp, sizeof(emp));
cout<<endl<<“New record has been added successfully…”;
break;
case ‘2’:
found=0;
cout<<endl<<“Enter ids of an Emp to be searched:”;
cin>>ids;
fl.seekg(0,ios::beg);
fl.read((char*)&ee,sizeof(ee));
while(!fl.eof())
{
if(ee.getId()==ids)
{
cout<<endl<<“The record found….”<<endl;
cout<<endl<<setw(5)<<“ID”<<setw(15)<<“Name”<<setw(15)<<“Post”<<setw(15)<<“Department”<<setw(8)<<“Salary”;
ee.dispRec();
found=1;
break;
}
fl.read((char*)&ee,sizeof(ee));
}
fl.clear();
if(found==0)
cout<<endl<<“Data not found for Emp ids#”<<ids;
break;
case ‘3’:
found=0;
cout<<“Enter depta name to list Emp within it:”;
cin>>depta;
fl.seekg(0,ios::beg);
fl.read((char*)&ee,sizeof(ee));
while(!fl.eof())
{
if(strcmp(ee.getDept(),depta)==0)
{
cout<<endl<<“The record found for this department”<<endl;
cout<<endl<<setw(5)<<“ID”<<setw(15)<<“Name”<<setw(15)<<“Post”<<setw(15)<<“Department”<<setw(8)<<“Salary”;
ee.dispRec();
found=1;
break;
}
fl.read((char*)&ee,sizeof(ee));
}
fl.clear();
if(found==0)
cout<<endl<<“Data not found for department”<<depta;
break;
case ‘4’:
cout<<endl<<“Record for employee”;
fl.clear();
fl.seekg(0,ios::beg);
int cntr=0;
fl.read((char*)&ee,sizeof(ee));
while(!fl.eof())
{
cntr++;
if(cntr==1)
{
cout<<endl<<setw(5)<<“ID”<<setw(15)<<“Name”<<setw(15)<<“Post”<<setw(15)<<“Department”<<setw(8)<<“Salary”;
}
ee.dispRec();
fl.read((char*)&ee,sizeof(ee));
}
cout<<endl<<cntr<<“records found……”;
fl.clear();
break;
case ‘5’:
int recNo=0;
cout<<endl<<“File is being modified….”;
cout<<endl<<“Enter Emp ids to be updated:”;
cin>>ids;
found=0;
fl.seekg(0,ios::beg);
fl.read((char*)&ee,sizeof(ee));
while(!fl.eof())
{
recNo++;
if(ee.getId()==ids)
{
cout<<“The old record of Emp having ID”<<ids<< “is:”;
ee.dispRec();
found=1;
break;
}
fl.read((char*)&ee,sizeof());
}
if(idFound==0)
{
cout<<endl<<“Data not found for Emp ids#”<<ids;
break;
}
fl.clear();
int loc=(recNo-1)*sizeof(ee);
fl.seekp(loc,ios::beg);
cout<<endl<<“Enter new record for Emp having ID”<<ids;
ee.readDat();
fl.write((char*)&ee, sizeof(ee));
break;
case ‘6’:
recNo=0;
cout<<endl<<“Enter employment ids to be deleted:”;
cin>>ids;
found=0;
fl.seekg(0,ios::beg);
fl.read((char*)&ee,sizeof(ee));
while(!fl.eof())
{
recNo++;
if(ee.getId()==ids)
{
cout<<” The old record of Emp having ids “<<ids<< ” is: “;
ee.dispRec();
found=1;
break;
}
fl.read((char*)&ee,sizeof(ee));
}
char tempFile[]=”temp.txt”;
fstream temp(tempFile,ios::out|ios::binary);
if(found==0)
{
cout<<endl<<“Data not found for Emp ids#”<<ids;
break;
}
else
{
fl.clear();
fl.seekg(0,ios::beg);
fl.read((char*)&ee,sizeof(ee));
while(!fl.eof())
{
if(eGetID()!=ids)
temp.write((char*)&ee,sizeof(ee));
fl.read((char*)&ee,sizeof(ee));
}
fl.close();
temp.close();
temp.open(tempFile,ios::in|ios::binary);
fl.open(fName,ios::out|ios::binary);
temp.read((char*)&ee,sizeof(ee));
while(!temp.eof())
{
fl.write((char*)&ee,sizeof(ee));
temp.read((char*)&ee,sizeof(ee));
}
}
temp.close();
fl.close();
remove(tempFile);
fl.open(fName,ios::ate|ios::in|ios::out|ios::binary);
break;
case ‘7’:
exit(0);
break;
default:
cout<<“Invalid Options”;
}
cout<<“ Do you want to continue…..?y/n”;
cin>>cho;
}while(cho!=’n’);
}
Rate answer an upvote......Thankyou
Hope this helps.....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.