私はベクトルにかなり慣れていません。患者を無作為にベッドに割り当てるプログラムの割り当てがあります。ベッドごとに患者が 1 人しか入らないようにする必要があります。私の質問は、1 人の患者をランダムに並べ替えて 1 つのベッドに割り当てるにはどうすればよいですか?
それはまともなサイズのプログラムであり、コードは複数のファイルに含まれているので、我慢してください。何かわからないことがあれば、私に知らせてください。できる限り解決しようとします。
これは、私が 1 つのベッドに 1 人の患者のみを割り当てていることです。この機能はおそらく私の問題です。
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;
};
患者のヘッダー ファイル部分。
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 つのベッドに追加することを選択しましたが、5 回繰り返すだけなので、2 でそれを切り捨てました。