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 12:38 AM.
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 LITE 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.
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 LITE 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.
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:
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.
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...
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
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?
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 11:23 AM.
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
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
Code:
List[i].ID
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 ?
Bookmarks