- Oct 19, 2003
- 1,269
- 0
- 0
Hi I have been working in this program( C++). The program is a system that
stores an employee's firstname , lastname, five digit number, the
department they work in and their annual salary. There are a maximum
of teen employees in the organization.
The program should allow me to add an employee , but it should warn me
if I am trying to create two identical employees, it should be able to
delete a current employee or update an existing employee's
information. The data is saved in the file "employee2.txt" when shutdown
and retrieves the data from the same file when started. The format of
the file is
11111 Firstname Lastname Departmentname $10,000
Now up to this point I am able to add a new employee, but where the
problem comes is when trying to delete, update or compare an employee.
I think I should use a loop to search thru the file in order to get
the name of the employee to delete, or to update, if this works , the
loop should also allow me to compare two employees. But I am confused
becasue I don't know if I should use the get function in order to do
that. I cannot use arrays pointers or strings because in my class I haven't gotten to that point
. Right now I am using simple classes to do this problem
This is what I got so far
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
class INFO
{
private:
int memberid;
char firstname[10];
char lastname[10];
char departname[15];
char annualsalary[10];
public:
void addemployee(ofstream& out_stream, INFO employee);
void update(ofstream& out_stream, ifstream& in_stream, INFO
employee);
};
int main()
{
ifstream in_stream;
in_stream.open("employment2.txt");
ofstream out_stream;
out_stream.open("employment2.txt",ios::app);
INFO employee;
char choice;
cout<<"Enter your choice of preference.\n";
cin>>choice;
switch(choice)
{
case'A':
employee.addemployee(out_stream, employee);
break;
case 'B':
employee.update(out_stream, in_stream, employee);
break;
}
out_stream.close();
return 0;
}
//Uses iostream
//Uses fstream
//Uses uses iomanip
void INFO::addemployee(ofstream& out_stream, INFO employee)
{
cout<<"Please enter a new employee to be written in the file.\n";
cout<<"in this format 99999 firstname lastname departmentname
$10,000.\n";
cin>>employee.memberid;
cin>>employee.firstname;
cin>>employee.lastname;
cin>>employee.departname;
cin>>employee.annualsalary;
cout<<employee.memberid<<setw(10)<<employee.firstname<<setw(10)<<employee.lastname<<setw(15)<<employee.departname<<setw(10)<<employee.annualsalary<<endl;
out_stream<<employee.memberid<<setw(10)<<employee.firstname<<setw(10)<<employee.lastname<<setw(15)<<employee.departname<<setw(10)<<employee.annualsalary<<endl;
}
//Uses iostream
//Uses fstream
//Uses iomanip
void INFO::update(ofstream& out_stream, ifstream& in_stream, INFO
employee)
{//This is where I have the problem!
}
I need the function definitions to compare that I am not creating two similar employees and the function to update and delete a current employee, I also need to include constructors to initiliaze my variable employee
Regards and thanks again...this is my second post in Anandtech.
stores an employee's firstname , lastname, five digit number, the
department they work in and their annual salary. There are a maximum
of teen employees in the organization.
The program should allow me to add an employee , but it should warn me
if I am trying to create two identical employees, it should be able to
delete a current employee or update an existing employee's
information. The data is saved in the file "employee2.txt" when shutdown
and retrieves the data from the same file when started. The format of
the file is
11111 Firstname Lastname Departmentname $10,000
Now up to this point I am able to add a new employee, but where the
problem comes is when trying to delete, update or compare an employee.
I think I should use a loop to search thru the file in order to get
the name of the employee to delete, or to update, if this works , the
loop should also allow me to compare two employees. But I am confused
becasue I don't know if I should use the get function in order to do
that. I cannot use arrays pointers or strings because in my class I haven't gotten to that point
This is what I got so far
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
class INFO
{
private:
int memberid;
char firstname[10];
char lastname[10];
char departname[15];
char annualsalary[10];
public:
void addemployee(ofstream& out_stream, INFO employee);
void update(ofstream& out_stream, ifstream& in_stream, INFO
employee);
};
int main()
{
ifstream in_stream;
in_stream.open("employment2.txt");
ofstream out_stream;
out_stream.open("employment2.txt",ios::app);
INFO employee;
char choice;
cout<<"Enter your choice of preference.\n";
cin>>choice;
switch(choice)
{
case'A':
employee.addemployee(out_stream, employee);
break;
case 'B':
employee.update(out_stream, in_stream, employee);
break;
}
out_stream.close();
return 0;
}
//Uses iostream
//Uses fstream
//Uses uses iomanip
void INFO::addemployee(ofstream& out_stream, INFO employee)
{
cout<<"Please enter a new employee to be written in the file.\n";
cout<<"in this format 99999 firstname lastname departmentname
$10,000.\n";
cin>>employee.memberid;
cin>>employee.firstname;
cin>>employee.lastname;
cin>>employee.departname;
cin>>employee.annualsalary;
cout<<employee.memberid<<setw(10)<<employee.firstname<<setw(10)<<employee.lastname<<setw(15)<<employee.departname<<setw(10)<<employee.annualsalary<<endl;
out_stream<<employee.memberid<<setw(10)<<employee.firstname<<setw(10)<<employee.lastname<<setw(15)<<employee.departname<<setw(10)<<employee.annualsalary<<endl;
}
//Uses iostream
//Uses fstream
//Uses iomanip
void INFO::update(ofstream& out_stream, ifstream& in_stream, INFO
employee)
{//This is where I have the problem!
}
I need the function definitions to compare that I am not creating two similar employees and the function to update and delete a current employee, I also need to include constructors to initiliaze my variable employee
Regards and thanks again...this is my second post in Anandtech.