-
plz,need some help
hey,i need help here....i need codes on how to auto generate id ...
Code:
#include <iostream>
#include <string>
#include <fstream>
#include "staffDetails.h"
using namespace std;
void staffDetails::getStaffInfo()
{
char yes;
cout<<"Please enter staff's name:";
cin>>name>>endl;
cout<<"Please enter staff's address:";
cin>>address>>endl;
cout<<"Please enter staff's ID number:";
cin>>SID>>endl;
cout<<"Please enter staff's c number:";
cin>>c_no>>endl;
save();
}
void staffDetails::save()
{
fstream instaff;
instaff.open("staff.dat",ios::in|ios::app);
if(instaff.fail())
{
cerr<<"File opening error!";
exit(-1);
}
instaff>>name>>address>>SID>>c_no;
instaff.close();
}
>
-
staff member id = number_of_staff_members + 1
something like that?
-
What do you want the ID to look like? All numbers, a mix of letters and numbers? Do you do want their realname to be involved somehow (ie contains their initials)?
Look into <ctime> and the rand() function, that should put you on the right track.
-
-
thanx
yea..maybe a mix of characters and numbers would be good
for example,
id=csd001
i should use a for loop rite?
-
With the letters you're going to have to use rand() to get their ascii values then convert them to characters. Go to http://www.lookuptables.com they have an ascii chart. If you don't want it random, consider that the letters could be the employees initials.
-
hey
what if i want the id to be in numbers only?
-
Again, what numbers do you want? Random numbers? If so then use the rand() function. If you want it based on other data, such as the number of employees you have then you can use that.
-
numbers 0-9 = ascii 48-57
so use:
Code:
int blaat = rand() % (57 - 48) +48;
-
No, no. You don't need ascii values for numbers. Because rand returns an integer.
Code:
#include <cstdlib>
#include <ctime>
/* cstdlib for srand() and rand() and ctime to seed srand() */
using namespace std;
int main() {
srand(time(NULL));
int randomNum = rand() % 9 + 1; // A random number between 1 and 9.
return 0;
}