Struct inside class

I have a class called Patients, and inside this class there is a structure called procedure.

Now, one of my function calls purpose is to update the struct procedure with values that the user enters. However, I don't know how to access the variables in the structure.

So basically I am having a problem when I am making my update procedure function.

The class looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Patient
{
private:
	int ID;
	char firstName[15];
	char lastName[15];
	Date birthdate;
	int DoctorID;
	struct procedure
	{
		Date dateOfProcedure;
		int procedureID;
		int procedureProviderID;
	};

public:
	Patient(int ID, const char *, const char *, Date, int); //Put in default values 
	// just as in Date class
	Patient();
	//Use the set functions so input values are checked  
	Patient &setID(int);
	Patient & setFirstName(const char *); //check if length of name string is < 
	// 15, if not, shorten to 14 letters.
	Patient & setLastName(const char *);  //check if length of name string is < 
	// 15, if not, shorten to 14 letters.
	Patient & setBirthDate(Date);
	Patient & setPrimaryDoctorID(int);
	Patient & operator=(const Patient& a);

	int getID();
	const char * getFirstName();
	const char * getLastName();
	Date getBirthDate();
	int getPrimaryDoctorID();
	//tries to add a new entry to record array, returns 									
	//true if added, false if cannot be added
	bool enterProcedure(Date procedureDate, int procedureID, int procedureProviderID);
	void printAllProcedures();
	~Patient();

};


The function which I'm trying to update is:
 
bool enterProcedure(Date procedureDate, int procedureID, int procedureProviderID);


Here is how the function is being called:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void checkOut(Patient *&checkIn, Patient *&All, int &count, int Checksize)
{
	int checkID;
	int procID;
	int provID;
	int dd, mm, yy;
	
	cout << "Please enter the ID of the patient you wish to check out:" << endl;
	cin >> checkID;
	for (int i = 0; i < Checksize; i++)
	{
		if (checkID == checkIn[i].getID())
		{
			cout << "Patient found, please update the procedure..." << endl;
			cout << "Please enter the current date (mm/dd/yy): " << endl;
			cin >> mm; cout << "/"; cin >> dd; cout << "/"; cin >> yy; 
			cout << endl;
			Date Proc(mm, dd, yy);
			cout << "Enter the new procedure ID:" << endl;
			cin >> procID;
			cout << "Enter the new provider ID: " << endl;
			cin >> provID;
			checkIn[i].enterProcedure(Proc, procID, provID);
		}
	}
}



So when I pass the values as arguments into enterProcedure function, how do I set dateOfProcedure = Proc?

The problem is that you just have a type created but not a variable.
1
2
3
4
5
6
struct procedure
{
  Date dateOfProcedure;
  int procedureID;
  int procedureProviderID;
};


I would do it like this
1
2
3
4
5
6
typedef struct 
{
  Date dateOfProcedure;
  int procedureID;
  int procedureProviderID;
}Procedure;


Than you can create a variable in your patient class.

1
2
private:
  Procedure m_proc;


and set it with m_proc.procedureID = somevalue;
Topic archived. No new replies allowed.