0

Can you help me on this project of mine?
Here's the problem.

It's a payroll system where the employee can enter his/her record. After entering his/her record it will be stored in a file. If their might be changes the employee might want to change he/she can be able to edit the record. Since it is a payroll system their will be many employees, so you must be able to add other records.

To sum it all up the main objective is to:
Make a payroll system, where you can enter, edit, display, and add a record.

Please help me out on this.

3
Contributors
6
Replies
7
Views
10 Years
Discussion Span
Last Post by n.aggel
0

heres the code i made
but then some parts work i only have a problem with the edit part and how i can input many records

#include<iostream.h>
#include<fstream.h>
class Employee
{
private:
    char EmpID[10];
    char EmpName[25];
    char Pos[50];
    int BASIC, COLA, SSS, WTax, OT, Gross, NET;

public:
    void print()
    {
        cout<<"Employee's details\n";
        cout<<"ID number: " << EmpID << endl;
        cout<<"Name: " << EmpName << endl;
        cout<<"Position: " << Pos << endl;
        cout<<"Basic Salary: " << BASIC << endl;
        cout<<"Cost of Living Allowance: " << COLA << endl;
        cout<<"SSS: " << SSS << endl;
        cout<<"With holding Tax: " << WTax <<endl;
        cout<<"Overtime: " << OT <<endl;
        cout<<"Gross: " << Gross <<endl;
        cout<<"NET: " << NET << endl;
    }

    void get()
    {
        cout<<"ID number: ";
        cin>> EmpID;
        cin.ignore();
        cout<<"Name: ";
        cin.getline(EmpName,25);
        cout<<"Position: ";
        cin.getline(Pos,50);
        cout<<"Basic Salary: ";
        cin>> BASIC;
        cout<<"Cost of Living Allowance: ";
        cin>> COLA;
        cout<<"SSS: ";
        cin>> SSS;
        cout<<"With holding Tax: ";
        cin>> WTax;
        cout<<"Overtime: ";
        cin>> OT;
        cout<<"Gross: ";
        cin>> Gross;
        cout<<"NET: ";
        cin>> NET;
    }
};

int main()
{
    int ch;
    char Filename;
    Employee object;
    while(1)
    {
        cout<<"\t\t\t\tPayroll System\n\n";
        cout<<"\t\t 0. Exit \n\n";
        cout<<"\t\t 1. Enter Employee Details \n\n";
        cout<<"\t\t 2. Display all records \n\n";
        cout<<"\t\t 3. Edit a record \n\n";
        cout<<"\t\t    Enter your choice (0-2)";
        cin>>ch;

        if(ch==1)
        {
            cout<<"\nEnter ID number of employee record to be entered:\n";
            cout<<"\t\t:";
            cin>>Filename;
            ofstream ofile(Filename);
            char reply ='y';
            while(reply == 'Y' || reply == 'y')
            {
                cout <<"\n\nEnter Employee details \n"<<endl;
                object.get();
                ofile.write((char *)&object,sizeof(object));
                cout<<"Do you wish to add another detail?(Y/N)";
                cin>>reply;
            }
            ofile.close();
        }
        
        if(ch==2)
        {
            cout<<"\nEnter ID number of the employee you wish to view:\n";
            cout<<"\t\t:";
            cin>>Filename;
            ifstream ifile(Filename);
            ifile.read((char *)&object,sizeof(object));
            while(ifile)
            {
                object.print();
                ifile.read((char *)&object,sizeof(object));
            }
            ifile.close();
        }
        
        if(ch==3)
        {
            char edit;
            cout<<"\nEnter ID number of employee you wish to edit: ";
            cout<<"\t\t:";
            cin>>Filename;
            ifstream ifile(Filename);
            ifile.seekg(((sizeof(obj))*(Filename-1)),ios::beg);
            ifile.read((char*)&obj,sizeof(obj));

            obj.print();
            ifile.close();

            cout<<"\n\nDo you want to edit another record? [Y/N]";
            cin>>edit;
            if(edit=='Y' || edit=='y')
            {
                ofstream ofile(Filename,ios::out);
                obj.get();
                ofile.write((char*)&obj,sizeof(obj));

                ofile.close();
            }
        }

        if(ch==0)
            break;
    }
    return 0;
}
0

You can start by trashing out those old iostream.h and fstream.h headers and start using the modern ones:

#include <iostream>
#include <fstream>
using namespace std;

You'll also want to edit in your code tags as i described in my previous post (assuming it's not too late to edit by the time you read this).

I don't quite get your problem. You say there's a problem entering multiple records. What exactly do you mean by this? Post any error messages that occur, which lines cause them (if you know) and such.

0

The program must accept multiple records. Meaning i can input may records as long as i want. It's required. The problem with my program is it only accepts one record. Which does not fit the requirement.

0

The program must accept multiple records. Meaning i can input may records as long as i want. It's required. The problem with my program is it only accepts one record. Which does not fit the requirement.

Hmm... I don't see why you're having a problem. The while(1) statement will keep the whole menu system rolling until the user exits, so what exactly is stopping you?

Just tried compiling your code; it has a couple of errors:

int main()
{
    int ch;
    char Filename; // make this into an array so it can hold more than 1 char!

And here:

if(ch==3)
        {
            char edit;
            cout<<"\nEnter ID number of employee you wish to edit: ";
            cout<<"\t\t:";
            cin>>Filename;
            ifstream ifile(Filename);
            // you never declared 'obj'; perhaps you meant 'object'?
            ifile.seekg(((sizeof(obj))*(Filename-1)),ios::beg);
            ifile.read((char*)&obj,sizeof(obj));
            
            obj.print();
0

hi,
basically if this is a school project, i guess that you need to improve your object oriented design.For example you can create a class Employee and then a class EmployeeDataBase which will have a vector containing Employee objects.This will enable you to add as many records you like, plus {i think} it is better than implementing everything in one class...{i could be wrong because i just started learning OOP:)]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.