473,383 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Qustion about (random function) ?

Hi ...
I want to create Student class that including their id, which is an automatic number issued by the system ..

do I need to use random method ? or is there another simple way to make the id generated by the system -not input by the user - ?

i hope that you undarstand what do i mean .....

thanks !
Nov 16 '07 #1
8 1398
Meetee
931 Expert Mod 512MB
Hi ...
I want to create Student class that including their id, which is an automatic number issued by the system ..

do I need to use random method ? or is there another simple way to make the id generated by the system -not input by the user - ?

i hope that you undarstand what do i mean .....

thanks !
Why you want to use random number? It is better if you increment a number every time new student is created! What is your criteria regarding student id?
Nov 16 '07 #2
you mean it is enough to Increase the id in the constructer
Expand|Select|Wrap|Line Numbers
  1. id++;
Nov 16 '07 #3
Meetee
931 Expert Mod 512MB
you mean it is enough to Increase the id in the constructer
Expand|Select|Wrap|Line Numbers
  1. id++;
Yeah, but that depends on your criteria. Why you want to take random numbers?
Nov 16 '07 #4
it just an idea because i think that increasing the number is not enough to make that !
thanks alot ..
Nov 16 '07 #5
JosAH
11,448 Expert 8TB
it just an idea because i think that increasing the number is not enough to make that !
thanks alot ..
Have a static member of your class, say 'id' and increment and assign it to your
student id every time you create one; so in the Student constructor you'd do:

Expand|Select|Wrap|Line Numbers
  1. myId= id++;
  2.  
Note that this approach is not thread safe and when you restart your program,
the static id variable will be reset again.

kind regards,

Jos
Nov 16 '07 #6
Have a static member of your class, say 'id' and increment and assign it to your
student id every time you create one; so in the Student constructor you'd do:

Expand|Select|Wrap|Line Numbers
  1. myId= id++;
  2.  
Note that this approach is not thread safe and when you restart your program,
the static id variable will be reset again.

kind regards,

Jos
thanks alot , i undarstand your explanation
so , i will declare "id" as static member
what about "myId"
can i declare it as const ?!!
Nov 16 '07 #7
JosAH
11,448 Expert 8TB
thanks alot , i undarstand your explanation
so , i will declare "id" as static member
what about "myId"
can i declare it as const ?!!
No; the variable 'myId' should be an ordinary (private?) member variable for all
the Student objects; it represents the unique id of a student.

kind regards,

Jos
Nov 16 '07 #8
it is clear
Thank you Jos ..
Nov 16 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: JNY | last post by:
I am using random to generate random numbers, thus: int x,y; for (y = 0;y < 5;y++) { x = random(50); cout << x; }
3
by: TaTonka | last post by:
hi! how can i manage it (html or jscript with css) that everytime a user loads or refreshes a page, the page has a new bgcolor. i want to put it in a single file, so that all my pages have the...
4
by: Greg Strong | last post by:
Hello All, Is it possible to create multiple random numbers in a query where there are numerous records? I've created a custom function. When I use it in a query it creates the same random...
13
by: Jon Agiato | last post by:
Hello, I am sure this problem is easy to spot but I have been at this project all day and the frustration has finally overcome me. I am using this function in order to produce a standard normal...
10
by: Leon | last post by:
I know by default the random number generator use the time, but what is the best seed I can used in my web application? The Program generate 6 unique random numbers and load each of them in a...
3
by: JoelPJustice | last post by:
I am working through a VBA book by myself to help and try and improve my skills. However, the book does not give you solutions to certain problems. I have worked through this problem up until bullet...
9
by: key9 | last post by:
Hi all My question is why the code CAN pass the compiler , and all the resoult is right? I means in my mind the reffoo(3,*test); should not pass compiler. #include <stdio.h>
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
3
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: *************************************************...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.