الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

سؤال .. اتمنى الاجابه عليه سريعا

مغلق
بدأه المستانسه في 4 يناير 2007 · 5 رد · 676 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته :)

انا طالبه في الحاسب وعندي مشروع صغير .. عباره عن برنامج لـ hospital

حليت كل البرنامج وبقي لي جزئيه بسيطه حاولت فيه اكثر من مره وما ادري وين الخطأ فيه

انا عندي ..

class Patient

class Doctor

class Person

class Hospital

الكلاس Patient و الكلاس Doctor

inherits from the class Person

المشكله اللي عندي في الكلاس Hospital

هذا الهيدر فايل

#ifndef HOSPITAL_H
#define HOSPITAL_H


#include "Doctor.h"
#include "Patient.h"
#include "Date.h"

class Hospital{

public:

	Hospital();

	bool addPatient(Patient&);
	Patient& getPatient(int id);
	Patient*[] getPatients(string name);
	void removePatient(int id);


	bool addDoctor(Doctor&);
	Doctor& getDoctor(int id);
	Doctor*[] getDoctors(string name);
	void removeDoctor(int id);

	//Returns an array of pointers to Person, pointing to objects of Doctors 
	//and Patients with the given name
	Person*[] getAll(string name);



private:
	Patient* patients[50];
	Doctor* doctors[5];
};

#endif

وهذا cpp

#include "Hospital.h"

#include <iostream>
using namespace std;

Hospital::Hospital()
{
	for (int i = 0; i < 50; i++){
			patients= NULL;
		}
	for (int j = 0; j < 5; j++){
		doctors[j] = NULL;
	}
}



bool Hospital::addPatient(Patient& p)
{
	Patient* pp = p;
	for (int i = 0; i < 50; i++)
	{
		if (patients== NULL)
		{
			patients = pp;
			cout << "Adding successful." << endl;
			return true;
		}
	}

	cout << "Sorry, we can't add more patients" << endl;

	return false;
}

Patient& Hospital::getPatient(int id)
{
	for (int i = 0; i < 50; i++){

		if (patients!= NULL && patients->id == id) 
			return *patients;
	}


}

Patient*[] Hospital::getPatients(string name){

	int j = 1;
	Patient** array;
	array = new Patient*[j];

	for (int i = 0; i < 50; i++){
		if (patients->getForename() == name){
			array[j] = patients;
			j++;
		}
	}
	return array;
}



void Hospital::removePatient(int id)
{
	for (int i = 0; i < 50; i++)

		if (patients!= NULL && patients->id == id)

			patients = NULL;

}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

bool Hospital::addDoctor(Doctor& d)
{
	Doctor* dd = d;
	for (int i = 0; i < 5; i++)
	{
		if (doctors== NULL)
		{
			doctors = dd;
			cout << "Adding successful." << endl;
			return true;
		}
	}

	cout << "Sorry, we can't add more doctors" << endl;

	return false;
}

Doctor& Hospital::getDoctor(int id)
{
	for (int i = 0; i < 5; i++){

		if (doctors!= NULL && doctors->id == id) 
			return *doctors;
	}


}

Doctor*[] Hospital::getDoctors(string name){

	int j = 1;
	Doctor** array;
	array = new Doctor*[j];

	for (int i = 0; i < 5; i++){
		if (doctors->getForename() == name){
			array[j] = doctors;
			j++;
		}
	}
	return array;
}


void Hospital::removeDoctor(int id)
{
	for (int i = 0; i < 5; i++)

		if (doctors!= NULL && doctors->id == id)

			doctors = NULL;

}

//////////////////////////////////////////////////////////////////////////

Person*[] Hospital::getAll(string name){

	int j = 1;
	Person** array;
	array = new Person*[j];

	for (int i = 0; i < 5; i++){
		if (doctors->getForename() == name){
			array[j] = doctors;
			j++;
		}
	}

	for (int i = 0; i < 50; i++){
		if (patients->getForename() == name){
			array[j] = patient;
			j++;
		}
	}

	return array;

}

///////////////////////////////////////////////////////////////////////////////

الايرورز كلها تطلع لي في

Patient*[] getPatients(string name);

Doctor*[] getDoctors(string name);

Person*[] getAll(string name);

ومشكورين مقدما :)

تم تعديل هذه المشاركة بواسطة المستانسه في 4 يناير 2007 في 15:25

#2

15 مشاهده .. وولا رد !!

يا ليت احد يجاوبني بسرعه لاني لازم اسلم المشروع بعد كم يوم

..

انا سؤالي بالضبط .. هل اقدر اخلي القيمه اللي ارجعها من الفنكشن array ؟

واذا ما يصلح ,, وش احط ؟ لاني جربت اخلي القيمه المرجعه pointer to pointer ونفس الشي طلع لي errors

#3

سيتم الاطلاع على المشكلة وابلاغك قريبا عن الحلو ل الممكنة

تم تعديل هذه المشاركة بواسطة time1 في 4 يناير 2007 في 23:17

llback.jpg

اشهد ان لا إله إلا الله وان محمدا ً رسول الله

#4

اعطينا وش الايرور الي جاك لأن الكود ما نقدر نطبقه ؟

#5

ياختي انا مدري وش تسوين ؟؟؟؟؟

bool Hospital::addPatient(Patient& p)

شوفي ياختي هالميثود ؟؟؟؟!!!!!!

انت مستقبل باي ريفيرنس ؟ حلو كيف تسندينها لـ pointer ؟ ؟ غلط

#6

مشكورين على الردود جميعا ..

انا خلاص عرفت المشكله وين بالضبط وحليتها

في الـ functions

getPatients

getDoctors

getAll

خليت القيمه المرجعه عباره عن pointer to pointer

وهذا هو الكود لـ functions بعد التعديل .. وشغلت البرنامج واشتغل معي صح

Patient** Hospital::getPatients(string name){

	int j = 0;
	Patient** array;
	array = new Patient*[50];



	for (int i = 0; i < 50; i++){
			if (patients != NULL)
		if (patients->getForename() == name){
			array[j] = patients;
			j++;
		}
	}
	return array;
}

Doctor& Hospital::getDoctor(int id)
{
	for (int i = 0; i < 5; i++){

		if (doctors!= NULL && doctors->id == id) 
			return *doctors;
	}


}

person** Hospital::getAll(string name){

	int j = 0;
	person **array;

	array = new person*[55];

	for (int i = 0; i < 5; i++){
		if (doctors != NULL)
		if (name == doctors->getForename())
		{
			array[j] = doctors;
			j++;
		}
	}


	for (int e = 0; e < 50; e++){
			if (patients[e] != NULL)

		if (patients[e]->getForename() == name)
		{
			array[j] = patients[e];
			j++;
		}
	}

	return array;

}

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…