Source code for workers

This is a discussion on Source code for workers within the C++ Programming forums, part of the General Programming Boards category; #include<iostream.h> #include<stdlib.h> #include<string.h> #define BUFSIZE 20 class worker{ char *name; double hoursworked,hourpay,overpay,bsalary,tax,nsalary; char status; public: worker():hoursworked(0.0),hourpay(0.0),overpay(0.0 ),status('s'), bsalary(0.0),tax(0.0),nsalary(0.0) {} void ...

  1. #1
    Unregistered
    Guest

    Post Source code for workers

    #include<iostream.h>
    #include<stdlib.h>
    #include<string.h>
    #define BUFSIZE 20

    class worker{
    char *name;
    double hoursworked,hourpay,overpay,bsalary,tax,nsalary;
    char status;
    public:
    worker():hoursworked(0.0),hourpay(0.0),overpay(0.0 ),status('s'),
    bsalary(0.0),tax(0.0),nsalary(0.0)
    {}
    void readdata(void);
    void calculate(void);
    char* getname(void){return name;}
    void showdata(void);
    };

    void worker::readdata(void) /* Function for input of a workers data */
    {
    char buffer[BUFSIZE];
    cout << "WORKER'S NAME: ";
    cin.getline(buffer,BUFSIZE); // input: worker's name
    if(!buffer[0])
    buffer[0]='?',buffer[1]='\0';
    name=new char[strlen(buffer)+1];
    if(name!=NULL)
    strcpy(name,buffer);
    else exit(1);
    do{ // input: hours worked, make sure you get a value
    cout << "HOURS WORKED: ";
    cin.getline(buffer,BUFSIZE);
    if(buffer[0]=='0')
    {hoursworked=0.0; break;}
    hoursworked=atof(buffer); /* atof returns zero, if a string cant be converted
    to a 'double' value */
    }while(!hoursworked);
    do{ // input: fee/hour
    cout << "FEE / HOUR: ";
    cin.getline(buffer,BUFSIZE);
    if(buffer[0]=='0')
    {hourpay=0.0; break;}
    hourpay=atof(buffer);
    }while(!hourpay);
    do{ // input: fee/overtime
    cout << "FEE / OVERTIME: ";
    cin.getline(buffer,BUFSIZE);
    if(buffer[0]=='0')
    {overpay=0.0; break;}
    overpay=atof(buffer);
    }while(!overpay);
    do{ // input: fee/hour
    cout << "STATUS (marriaged, single m/s): ";
    cin.getline(buffer,BUFSIZE);
    status=buffer[0];
    }while(status!='s' && status!='m');
    } // End of readdata

    void worker::calculate(void)
    {
    hoursworked<=40 ? (bsalary=hoursworked*hourpay) :
    (bsalary=(hoursworked-40)*overpay+40*hourpay);
    status=='s' ? (tax=bsalary*0.3) : (tax=bsalary*0.25);
    nsalary=bsalary-tax;
    }

    void worker::showdata(void)
    {
    cout << "NAME: " << name << '\n' << "STATUS: " << status
    << '\n' << "SALARY: " << nsalary << '/' << bsalary
    << " (TAX: " << tax << ')' << '\n' << '\n';
    }

    void main()
    {
    char buffer[BUFSIZE];
    int howmany=0;
    do{
    cout << "How many workers ? >> ";
    cin.getline(buffer,BUFSIZE);
    howmany=atoi(buffer);
    }while(!howmany);
    howmany=(howmany<0 ? -howmany : howmany);
    worker *wkptr=new worker[howmany];
    if(wkptr==NULL) // HEAPOVERFLOW, NULL is def in stdlib
    {cout << "HEAP !!!"; exit(1);}
    for(int i=0;i<howmany;i++){
    wkptr[i].readdata();
    wkptr[i].calculate();
    cout.put('\n');
    } // End of for
    cout.put('\n');
    do{
    cout << "Input name of a worker\nto see his data: ";
    cin.getline(buffer,BUFSIZE);
    if(buffer[0]=='\0')
    {buffer[0]='?'; buffer[1]='\0';}
    for(i=0;i<howmany;i++){
    if(!(strcmp(buffer,wkptr[i].getname())))
    {wkptr[i].showdata();break;}}
    if(i==howmany)
    cout << "NOT FOUND\n";
    cout << "ANY KEY OR e FOR END >> ";
    cin.getline(buffer,BUFSIZE);
    if(buffer[0]=='e')
    break;
    }while(1);
    } // End of main, delete is done automatically

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    and?
    Monday - what a way to spend a seventh of your life

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    this code is of no use whatsoever

    I mean that in the nicest possible way.

    did you mean to ask a question too?
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    he probably just wanted to show people his prog (which is pretty good)...what's wrong with that?

  5. #5
    Unregistered
    Guest

    Why ...

    I've tried to send the source code to an other message board
    before - as a possible answer to a question. Unfotunately it was
    too long. I promised him/her to publish it here, so that he/she could copy it. That's it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seven Kingdoms I: Ancient Adversaries for Linux
    By MIH1406 in forum Projects and Job Recruitment
    Replies: 13
    Last Post: 01-17-2010, 05:03 PM
  2. How do you call another source code file?
    By nifear4 in forum C Programming
    Replies: 2
    Last Post: 10-28-2008, 01:16 PM
  3. DxEngine source code
    By Sang-drax in forum Game Programming
    Replies: 5
    Last Post: 06-26-2003, 06:50 PM
  4. Lines from Unix's source code have been copied into the heart of Linux????
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 05-19-2003, 04:50 PM
  5. Source Code Beautifier
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-05-2002, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21