Re: How to generate an auto ID (or Auto Number)
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
general07z
Hello,
This code is for (hospital management system).
This code allow you to add patients.
Please, edit your post adding Code tags around your code snippets.
Otherwise your code is absolutely unreadable!
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
VictorN
Please, edit your post adding Code tags around your code snippets.
Otherwise your code is absolutely unreadable!
Thanks, but i guess there are a lot of code tags around my code.
Not for each line, but almost for each line. enough to be understood.
Thanks again.
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
general07z
Thanks, but [хл]i guess there are a lot of code tags around my code[/хл].
Not for each line, but almost for each line. enough to be understood.
Your "guess" is wrong! And I strongly recommend you first read the Announcement: Before you post.... and only then you may or may not "guess".
But if you don't care where someone will read your unformatted and absolutely unreadable code snippet then you can ignore my post. :cool:
Re: How to generate an auto ID (or Auto Number)
We aren't talking about //comments, but phpBB [CODE][/CODE] tags
You put them around your code, and it looks readable:
This:
[CODE]#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
}[/CODE]
Becomes:
Code:
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
}
Re: How to generate an auto ID (or Auto Number)
Alright, i have added [code][/ code] tags around my code.
hope my code is readable now.
Re: How to generate an auto ID (or Auto Number)
There are generally two ways two ways to generate unique IDs:
- Incremental generation: You have a static service you can query for an ID. This service will incrementally generate numbers, and will guarantee each entry is unique.
- Unicity through scarcity: This is the UUID approach: The basic idea is that if you generate random 128 bit numbers, they id will be statistically unique.
On a side note, you may want to consider using actual C++ containers, instead of rolling out your own. You want to look at:
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
monarch_dodra
There are generally two ways two ways to generate unique IDs:
- Incremental generation: You have a static service you can query for an ID. This service will incrementally generate numbers, and will guarantee each entry is unique.
- Unicity through scarcity: This is the UUID approach: The basic idea is that if you generate random 128 bit numbers, they id will be statistically unique.
On a side note, you may want to consider using actual C++ containers, instead of rolling out your own. You want to look at:
hey,
Thanks for your reply.
Now the problem is not of generating an ID, the problem is how can i specific the ID that has been generated for a patient, i mean how can i appear the number more than once for the same patient? and sometimes i will be having more than a patient. because the auto ID should be saved in the queue. so whenever i want to view all the patient, the same ID will appear for the right patient.
i got a lot of codes for generating an Number, but the problem is how to appear the same number that has been generated for the patient when i want call him/her.
for example this code:
unique ID for objects
Code:
class IDGenerator {
public:
static IDGenerator * instance ();
uint32_t next () { return _id++; }
private:
IDGenerator () : _id(0) {}
static IDGenerator * only_copy;
uint32_t _id;
}
IDGenerator *
IDGenerator::instance () {
if (!only_copy) {
only_copy = new IDGenerator();
}
return only_copy;
}
and i will be able to get a unique ID at any time by doing:
Code:
IDGenerator::instance()->next ()
But i don't know how to apply it on my code.
any help? how to apply it on my code.
regards
Re: How to generate an auto ID (or Auto Number)
Did you consider using a simple free database (like MS Access) to save your data? DB generates unique ID for you and assigns it to every new record in a table...
Re: How to generate an auto ID (or Auto Number)
Isn't this a little simpler? No need to 'new' anything.
Code:
uint32_t NextID()
{
static uint32_t _id = 0;
return _id++;
}
int main()
{
uint32_t id = NextID();
}
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
VictorN
Did you consider using a simple free database (like MS Access) to save your data? DB generates unique ID for you and assigns it to every new record in a table...
No, im not using any database. just black screen
Thanks for your reply.
Quote:
Originally Posted by
JohnW@Wessex
Isn't this a little simpler? No need to 'new' anything.
Code:
uint32_t NextID()
{
static uint32_t _id = 0;
return _id++;
}
int main()
{
uint32_t id = NextID();
}
Yes. looks simpler. but how to apply it on my code?
looking forward for your assistance,
Thanks a lot
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
VictorN
Did you consider using a simple free database (like MS Access) to save your data? DB generates unique ID for you and assigns it to every new record in a table...
The problem if i want to use a database, i have to change a lot of things and almost start over with my code.
But if there is a way to use the database to save only the Auto Numbers. That is will be great.
As the code is saving the new records in queue. but i'm able to view the records at any time. but the records will be removed once the program is closed or restart.
So no need to save the other records in the database, IF there is a way to save only the Auto ID in the database -> But i know that it will be heavy work and header to me to do it.
i really appreciate
Best regards
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
general07z
But i don't know how to apply it on my code.
any help? how to apply it on my code.
regards
In your code, each patient has a first name, last name and an ID. Shouldn't the ID be used to identify each patient then? The only problem I see, is that your ID is a string now, whereas you want it to be a number.
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
D_Drmmr
In your code, each patient has a first name, last name and an ID. Shouldn't the ID be used to identify each patient then? The only problem I see, is that your ID is a string now, whereas you want it to be a number.
hey,
The ID in my code is defined as a "Phone Number", as showing here:
Code:
cout << "Phone Number : " << List[i].ID<<endl<<endl;
You see here So, We have to define another structure to the code for the auto ID, . For example "generated_ID;".
OR, since the "ID;" function is for the "Phone number", is it possible to change it for generating the Auto ID? it should be easier for us if we did that right ?
Regards