can someone PLEASE KINDLY help me on how to add new records to input fie( in this case its "datafile.dat"). i want to add new employee records to my "datafile.dat"
Also, How can i delete an employee record from the datafile? i understand that it needs a matching name for delete purpose, but HOW do i insert that match funtion into my program?
PLEASE CHECK IF I HAVE ANY OTHER MISTAKES IN MY CODE. I WUD B XTREMELY GRATEFUL
THANX A LOT!!!!!!!!!
#include <stdio.h>
#include < iostream.h>
#include < iomanip.h>
#include < fstream.h>
#include < string.h>
#include "employee.h"
void main()
{
EmployeeList *List = new EmployeeList;
char NewName[50];
char NewDepartment[50];
int NewSalary;
ifstream In;
fstream datafile;
Employee result;
char get;
// Open the data file for reading
In.open("datafile.dat");
//Get the first line to check if it is 'done'
In >> NewName;
// Add employees to the list until they enter 'done'
while(strcmp(NewName, "done") != 0)
{
cout <<"Please choose one of the following menu selections:\n";
cout <<"A. Add a record \n";
cout <<"B. Delete a record \n";
cout <<"C. Display all records \n";
cout <<"D. Exit \n";
cin>>get;
switch(get)
{
case 'A' : result.AddEmployee(); break;
case 'B' : result.DeleteEmployee(); break;
case 'C' :result.DisplayEmployee;
break;
case 'D' : NewName == "done" ; break;
break;
}
// Get the remaining data for the employee
In >> NewDepartment >> NewSalary;
// Create the employee and assign the values
Employee *NewEmployee = new Employee(NewName, NewDepartment, NewSalary);
List->Add(NewEmployee);
// Get the next name or 'done'
In >> NewName;
}
In.close();
}
"datafile.dat"
Raj Computer 90000
Ayesha Accounting 95000
Jr.Raj Operational 140000
Ali Business 50000
Zainab Accountin 45000
done x 0