Google Answers Logo
View Question
 
Q: A C++ program, I need help urgent( probably easy for some) ( No Answer,   0 Comments )
Question  
Subject: A C++ program, I need help urgent( probably easy for some)
Category: Computers > Programming
Asked by: ngvepforever-ga
List Price: $30.00
Posted: 05 Nov 2003 17:11 PST
Expires: 06 Nov 2003 15:23 PST
Question ID: 273023
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 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 and I repeat I cannot use strings or arrays in this
problem. I need it for tonight or tomorrow morning, I will need the
source code and the file to be read it from should be a dat or txt
file, it's very urgent
Regards

Clarification of Question by ngvepforever-ga on 05 Nov 2003 17:47 PST
In case you don't understand what I am asking, here is the problem itself

I am the owner of a small business and am in need of a simple system
to keep track of information about my employees. The system needs to
store the employee?s name(first, last) their employee number ( a 5
digit number) the department they work in and the annual salary. The
system should also be able to compare two employees and warn me  if I
am trying to create two identical employees. Currently there are a
maximum of ten employees in the organization.

I would like for you to provide a text based user interface to allow
me to add a new employee  to the system, delte a current employee, or
update an existing employee?s information. I am on a tight budget, so
please minimize the cost of the system by reusing any parts from
existing systems wherever possible. I would like to call the system
EmployeeTracker and would like it to save the data in a file
(employee.dat) when shutdowm and retrieve the data from the file when
started. The format of the file should be as follows, one employee per
line.


99999 Firstname Lastname Departmentname $10,000


And again, I cannot use strings or arrays :(
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy