+ 1

Cpp program

How can i make a unique id for the single name on reservation system using c++ program

19th Jun 2018, 6:30 PM
bereket mekurya
bereket mekurya - avatar
2 ответов
+ 1
Please explain your question in a plain manner.
19th Jun 2018, 7:21 PM
Dlite
Dlite - avatar
+ 1
By using a pseudo random number generator and a map container (really convenient for pairs and also it has some mechanism to check duplicate keys (IDs)) like this snippet. #include <map> #include <random> #include <string> //... random_device rd; mt19937 gen( rd() ); int main() { string names[10] = {"boo","doo","koo","moo","joo","foo","loo","zoo","xoo","roo"}; map <int, string> rec; uniform_int_distribution<> ID(1000, 9999); for (auto i = 0; i < 10; ++i) rec.insert( make_pair(ID(gen), names[i]) ); } insert won't replace already added keys (IDs)
19th Jun 2018, 8:47 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar