-
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.
-
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
-
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
general07z
The ID in my code is defined as a "Phone Number", as showing here:
If you want to store a phone number, then declare your variable as "Phone_Number"!
"as shown here": We can only read so much code to try to understand what you are doing. We can't read your mind.
-
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
monarch_dodra
If you want to store a phone number, then declare your variable as "Phone_Number"!
"as shown here": We can only read so much code to try to understand what you are doing. We can't read your mind.
Yes that is true,
So i hope to change that variable to make it for generating an ID. i don't want any more "Phone number" Generating the Auto ID is more important than Phone number.
So now the program shouldn't ask for entering the ID, directly when the patient is successfully added the Auto ID should appear with the entered information.
for example:
First Name:
John
Last Name:
Jobs
ID:
001
Regards
-
Re: How to generate an auto ID (or Auto Number)
So why not just go to the end of your queue, or what ever your container is, look up the last ID and add 1 to it?
Does this data need to be persistent between runs of the program?
-
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
GCDEF
So why not just go to the end of your queue, or what ever your container is, look up the last ID and add 1 to it?
Does this data need to be persistent between runs of the program?
Hey,
How can i do that?
Is your idea, the number will be auto increase when i added another patient?
If yes, Please where do i have to change in my code.
I just need the ID to be increasing when i added another patient
like the first patient will have ID number 1
the second patient will have number 2.........
So i don't want the the program to ask me for Entering ID.
But when i add it. he should have the ID.
Thanks
-
Re: How to generate an auto ID (or Auto Number)
Hey,
I have added
Code:
int main(){
int Auto_ID =0;
}
than Added
Code:
cout<<"ID"<<p.Auto_ID++<<endl;
but it showing me an error
Code:
"see declaration of 'main'"
I just need the easiest way to make this ID works
Thanks
-
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
general07z
Hey,
I have added
Code:
int main(){
[hl]int Auto_ID[/hl =0;
}
than Added
Code:
cout<<"ID"<<p.Auto_ID++<<endl;
but it showing me an error
Code:
"see declaration of 'main'"
And What is "p" in this context? :confused:
-
Re: How to generate an auto ID (or Auto Number)
hey, it is a pointer
Code:
// define class for queue
class queue
{
public:
queue (void);
int RegisterPatien (patient p);
int RegisterPatientAtBeginning (patient p);
patient GetNextPatient (void);
int CancelAll (patient * p);
void OutputList (void);
char DepartmentName[50];
private:
int ShowAllPatient;
patient List[MAXPATIENTS];
};
So what is the problem with:
Code:
int main(){
int Auto_ID =0;
}
Is there any other method to do auto-increment number?
-
Re: How to generate an auto ID (or Auto Number)
HI friends I'm actually new to C++..and wanted to know how to add a auto numbering code to my First ever program..guys would you mind helping me..how should this be coded?
-
Re: How to generate an auto ID (or Auto Number)
What is "a auto numbering code"?
What is it supposed to do?
-
Re: How to generate an auto ID (or Auto Number)
Well its suppose to increase the number..example: 1st Customer ID would be Cust001, 2nd Customer Id would be Cust002..
-
Re: How to generate an auto ID (or Auto Number)
actually this is for a Bank and when a new member is added his/her Bank Number should be delivered automatically..example:
Account Number: 001 //this should be automatically generated
Name : J_Freak //the person has to type
Age : 21 //the person has to type
so on....
-
Re: How to generate an auto ID (or Auto Number)
If it "or a Bank" then you should (maybe just must!) use some type of database. And a database will generate all these IDs for you for each new added account.
-
Re: How to generate an auto ID (or Auto Number)
Well this is really really a basic "BASIC" programming..just a console application with 4 options (New account, Withdraw, Deposit & Balance inquiry) and some basic validations..so when the "New account" is selected the user must be able to fill the application..and the account number should be generated automatically..and the details will be saved in a notepad..
Account Number: 001 //this should be automatically generated
Name : J_Freak //the person has to type
Age : 21 //the person has to type
So..I actually need to know how to do this "auto numbering" thinggy...
-
Re: How to generate an auto ID (or Auto Number)
Are you going to supply such a "a basic "BASIC" ... console application with 4 options" to some Bank?
As for "auto numbering" in a real application (not just a a basic "BASIC" one) - see my previous post.
-
Re: How to generate an auto ID (or Auto Number)
Nah nah..just a basic program for my school project..:)
-
Re: How to generate an auto ID (or Auto Number)
Your previous post? which one?
-
Re: How to generate an auto ID (or Auto Number)
This Forum is not for kidding! :mad:
So, please choose: either
Quote:
Originally Posted by
J_Freak
Nah nah..just a basic program for my school project..:)
or
Quote:
Originally Posted by
J_Freak
actually this is for a Bank
-
Re: How to generate an auto ID (or Auto Number)
Ahhh so sorry if I was not clear..its actually a project/assignment for school..and the assignment is about a bank..I've done everything else but couldn't figure out on how to do the "auto numbering" part..
-
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
J_Freak
Ahhh so sorry if I was not clear..its actually a project/assignment for school..and the assignment is about a bank..I've done everything else but couldn't figure out on how to do the "auto numbering" part..
Well, didn't you read the whole thread from the very begin?
-
Re: How to generate an auto ID (or Auto Number)
ha..thanx alot I've figured out the way...but now caught up with another mess..
all these details are suppose to be written to a "notepad" and this is the coding that I used for it
void write_account()
{
account ac;
ofstream outFile;
outFile.open("Customer.txt",ios::in|ios::binary|ios::app);
ac.new_account();
outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
outFile.close();
}
but I'm not getting the output properly..its like jumbled with unknown characters...
What's the issue here?
-
Re: How to generate an auto ID (or Auto Number)
Quote:
Originally Posted by
J_Freak
that I used for it
Code:
void write_account()
{
account ac;
ofstream outFile;
outFile.open("Customer.txt",ios::in|ios::binary|ios::app);
ac.new_account();
outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
outFile.close();
}
but I'm not getting the output properly..its like jumbled with unknown characters...
P Lease, use Code tags. Otherwise your code is hard to read/understand.
What is account? And why do you cast account* to char*?