Function to allow multiple "Clock Ins"

Im writing a program that simulates a clock in device such as those normally used in a workplace. I want my program to be able to clock-in multiple employees instead of just one. Every time I have my program clock someone in, it pretty much overwrites whoever was clocked in before. What function should I use to allow for several clock-ins?

#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <time.h>
using namespace std;

class clockIn
{
private:
int empID[30], newNUM;
string clkNAM[30],newNAM;
int mainMENU, clockIn, clockOut, repeat;
int i=0, ii=0, flag=0, flagTwo=0, e=0;
string line;
time_t start, end, now = time(0);

public:
void getData();
void mainMenu();
};

void clockIn::getData()
{
int i=0;
ifstream empNUM, clokNAM;
empNUM.open("/Users/lepelch23alex/Dropbox/School/Computer Programming/New Clock in Device/Employee ID's.txt");
for(i=0; i<3; i++)
{
empNUM >> empID[i];

}
empNUM.close();
clokNAM.open("/Users/lepelch23alex/Dropbox/School/Computer Programming/New Clock in Device/CLock NAMes.txt");
for(i=0; i<3; i++)
{
clokNAM >> clkNAM[i];
}
clokNAM.close();
}

void clockIn::mainMenu()
{
std::cout << "Welcome to LePelch Corporations\n";
std::cout << "What can I do for you today?\n\n";
std::cout << "1) Clock in\n" << "2) Clock out\n" << "3) Create Employee ID\n" << "4) Nothing, exit." << endl;
std::cin >> mainMENU;

while(mainMENU!=4)
{ if(mainMENU==1)
{ std::cout << "\nWelcome to the Clock-In menu, please enter your employee ID, or enter '0' to exit to menu.\n" << endl;
std::cin >> clockIn;

while (clockIn!=0)
{
if (empID[e]==clockIn)
{
std::cout << "You are already clocked in!" << endl;
break;
}
for(i=0; i<3; i++)
{
if(empID[i]==clockIn)
{
e=i;
flag=1;
i=ii;
break;
}
}
if(flag==1)
{
time (&start);
std::cout << clkNAM[e] << endl;
std::cout << "Clock-in accepted.\n" << endl;
break;
}
else std::cout << "\nERROR! Please try again\n" << endl;
break;
}
}
else if(mainMENU==2)
{
std::cout << "\nWelcome to the Clock-Out menu, please enter your employee ID, or enter '0' to exit to menu.\n" << endl;
std::cin >> clockOut;

while (clockOut!=0)
{
for(i=0; i<3; i++)
{
if(empID[i]==clockOut and empID[i]==clockIn)
{
i=e;
flagTwo=1;
i=ii;
break;
}
}
if(flagTwo==1 and flag==1)
{
time (&end);
std::cout << clkNAM[e] << endl;
std::cout << "Clock-out accepted.\n" << endl;
double dif = difftime (end,start);
double minutes = dif/60;
double hours = minutes/60;
std::cout << "You have worked " << setprecision(3) << hours << " hours today. Have a nice day!\n" << endl;
break;
}
else if(flagTwo==1 and flag!=1)
{
std::cout << "\nERROR! You have not clocked in yet. Please clock-in before clocking-out. Thank you.\n" << endl;
}

else std::cout << "\nERROR! Please try again\n" << endl;
break;
}
}
else if(mainMENU==3)
{
std::cout << "Welcome. Punch in number to create new employee ID" << endl;
std::cin >> newNUM;
string line;
fstream empNUM,clokNAM;
empNUM.open("/Users/lepelch23alex/Dropbox/School/Computer Programming/New Clock in Device/Employee ID's.txt");

while (!empNUM.eof())
{
getline(empNUM, line);
empNUM << newNUM << endl;
}
empNUM.close();
clockIn::getData();

std::cout << "Input name 'Last,First'" << endl;
std::cin >> newNAM;

clokNAM.open("/Users/lepelch23alex/Dropbox/School/Computer Programming/New Clock in Device/CLock NAMes.txt");

while (!clokNAM.eof())
{
getline(clokNAM,line);
clokNAM << newNAM << endl;
}
clokNAM.close();
clockIn::getData();




}

else
std::cout << "Invalid Entry!...Please try again" <<std::endl;
std::cout << "What can I do for you today?\n\n";
std::cout << "1) Clock in\n" << "2) Clock out\n" << "3) Create Employee ID\n" << "4) Nothing, exit." << endl;
std::cin >> mainMENU;

}
std::cout << "Goodbye and have a nice day!" << endl;
}

int main(int argc, const char * argv[])
{

clockIn clock;
clock.getData();
clock.mainMenu();
return 0;
}
Last edited on
I suggest to use std::map<int, ClockTime> inside your clock class.
ClockTime is defined as: using ClockTime = std::pair<int, int> (or pair of strings, or time_point, or whichever you use to represent time)

usage:
1
2
3
4
5
6
7
8
9
Clock::clockIn(int ID)
{
    EmplMap[ID].first = Clock::currentTime();
}

Clock::clockOut(int ID)
{
    EmplMap[ID].second= Clock::currentTime();
}
Topic archived. No new replies allowed.