السلام عليكم ورحمة الله وبركاته :)
انا طالبه في الحاسب وعندي مشروع صغير .. عباره عن برنامج لـ 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);
ومشكورين مقدما :)
