how to write function which assigned ID for members in registration system

im writing program supposed to manage conference , i need at the beginning to allow the user of this system to register as members , then they can log in and using the facilities in the system , what i need is the way to assign IDs to these members after they register.

i have class for user contain method register , so any user object can use this method to register , after that he will be member , at member class which inherit the user class , there is additional attribute named ID , this ID value should be assigned using the system , how ? what is the function ? any idea ?
ID must be unique
any idea
hi all
i have 2 classes , 1 of them use the other as below

the student class which use course class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef _STUDENT_H_
#define _STUDENT_H_
#include <iostream>
#include <string>
#include "Course.h"

using namespace std;
class Student
{
    int id;
    string name;
    string matrixNo;
    Course* course;
public:
	Student();
    Student(int, string, string);
    void registerCourse(Course&);
};

#endif 


course class below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef _COURSE_H_
#define _COURSE_H_
#include <iostream>
#include <string>

using namespace std;
class Course
{
    int id;
    string name;
    string code;
public:
	Course();
    Course(int, string, string);
};

#endif 


can u help me , i wanna know how to access the course which is used in student class ?
example i wanna print the course which registered by student .

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include "Course.h"
#include "Student.h"

using namespace std;
int main()
{
	Student student1(1,"Ahmad","BIT1234");
	Course course1(1,"Bachelor in IT","BIT");
	student1.registerCourse(course1);
	cout<<student1.id<<"\n"<<student1.name<<"\n"<<student1.matrixNo<<"\n"<<student1.course<<"\n";/////my problem here 
	system("PAUSE");
}


it print the address of course , not the value
student1.course is just pointing to (I'm assuming) an instance of Course that was created in the registerCourse() function. If you want to access the members use this notation:

student.course->id // Course.id
student.course->name // Course.name

etc...
i wonder how you can get access to Student fields?if you want to print information about Student make a method print or etc..
or you can overload << operator. but don't forget do it in Course class too
You can use a static variable to keep track of the number of students.
Then use this as the student id

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Student
{
   static int nextid;
    int id;
    string name;
    string matrixNo;
    Course* course;
public:
    Student()
    {
        id = nextid;
        ++nextid;
    }
};


You will need to initialise the static variable in the cpp file

 
int Student::nextid = 1;


Thank u all .
Texan40 , it works correctly now , i know i face troubles in understanding pointers .
mike2718, thank u very much it was helpful idea , thank u all .
i hope 1 day i can be professional like u and i can help others.
Topic archived. No new replies allowed.