-
February 16th, 2012, 06:19 AM
#1
Auto-increment number
Hello,
This code is for (hospital management system).
This code allow you to add patients.
There are two types of patients. which is:
1. Normal patient.
2. Critically ill patient.
once you added any patient. You will be able to show all patient using "ShowAllPatient;" method. -> i want the Auto-increment ID Number to appear for each patient has been added.
And you will be able to call a patient to provide a hospital services for him/her using "GetNextPatient;" method.
I need to generate an Auto-increment Number for each (patient) has been added. (Auto-increment Number) but it just should be different for each patient. For example the first patient will have 1, The second patient will have 2. etc. The Auto-increment number should appear for each patient.
i really tired a lot but i could not find a solution.
Last edited by general07z; February 19th, 2012 at 01:38 AM.
-
February 16th, 2012, 06:33 AM
#2
Re: How to generate an auto ID (or Auto Number)
-
February 16th, 2012, 06:57 AM
#3
Re: How to generate an auto ID (or Auto Number)
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!
Victor Nijegorodov
-
February 16th, 2012, 08:31 AM
#4
Re: How to generate an auto ID (or Auto Number)
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.
-
February 16th, 2012, 08:39 AM
#5
Re: How to generate an auto ID (or Auto Number)
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.
Victor Nijegorodov
-
February 16th, 2012, 09:32 AM
#6
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";
}
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
February 16th, 2012, 09:44 AM
#7
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.
Last edited by general07z; February 16th, 2012 at 09:47 AM.
-
February 16th, 2012, 09:57 AM
#8
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:
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
February 16th, 2012, 10:17 AM
#9
Re: How to generate an auto ID (or Auto Number)
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
Last edited by general07z; February 16th, 2012 at 10:27 AM.
-
February 16th, 2012, 11:07 AM
#10
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...
Victor Nijegorodov
-
February 16th, 2012, 11:43 AM
#11
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();
}
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
February 16th, 2012, 11:57 AM
#12
Re: How to generate an auto ID (or Auto Number)
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.
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
-
February 16th, 2012, 12:17 PM
#13
Re: How to generate an auto ID (or Auto Number)
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
Last edited by general07z; February 16th, 2012 at 12:23 PM.
-
February 16th, 2012, 02:42 PM
#14
Re: How to generate an auto ID (or Auto Number)
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.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
February 16th, 2012, 11:28 PM
#15
Re: How to generate an auto ID (or Auto Number)
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|