【发布时间】:2013-08-01 16:14:26
【问题描述】:
我对向量很陌生。我有一个项目分配,我随机分配病人到病床。我需要做到这一点,这样我每张床只能有一个病人。我的问题是如何让一名患者被随机分类并分配到一张床位?
这是一个大小适中的程序,代码位于多个文件中,请多多包涵。如果您有不明白的地方,请告诉我,我会尽力解决它。
这是我在一张床位上只分配一名患者。这个功能很可能是我的问题。
string Hospital::assignRandPatientToBed()
{
for(int i=0;i<2;i++)
{
for(unsigned int pi=0;pi<vBeds.size();pi++)
{
if(rand()%2)
{
//bigRand is a function: numberToString=9
vPatients[bigRand()%vPatients.size()].bedId; ///MORE THAN LIKELY WRONG
}
}
}
return "Random Beds assigned to Patients.\n";
}
我的主要课程的私人部分,hospital.h
private:
int nextPatientIDtoBeUsed;
vector<Patient> vPatients;
map<int,int> PatientIDIndex;
map<string,int>PatientNameIndex;
map<string,int>PatientCategoryIndex;
int nextDoctorIDtoBeUsed;
vector<Doctor> vDoctors;
map<int,int> DoctorIDIndex;
int nextBedIDtoBeUsed;
vector<Bed> vBeds;
map<int, int> BedIDIndex;
};
Bed.h 的头文件
class Bed
{
friend class Hospital;
public:
private:
int id;
string location;
string bedType;
int patientID;
};
patient.h 的头文件部分(我只为此目的使用私有部分,它是一个大头文件)。
private:
int id;
vector<int> doctorIDs;
int bedId;
};
我必须修复的输出。床位由500分配,病人是8927号码。
500 CDDIUTEIOJ
892795431 Muw, Eziel (174) 094-8824
892795431 Muw, Eziel (174) 094-8824
892795431 Muw, Eziel (174) 094-8824
892795431 Muw, Eziel (174) 094-8824
892795431 Muw, Eziel (174) 094-8824
501 CMPSAJLFVG
892795431 Muw, Eziel (174) 094-8824
892795431 Muw, Eziel (174) 094-8824
892795431 Muw, Eziel (174) 094-8824
892795431 Muw, Eziel (174) 094-8824
892795431 Muw, Eziel (174) 094-8824
它使用随机创建的名字并将其分配给床。对于输出,我选择将 5 个患者添加到 5 张病床,但我在 2 之后将其切断,因为它只是重复了 5 次。
【问题讨论】: