• 0

c++ Error


Question

Hi. I get an error when running my program. It says:

Assignment3.exe has encountered a problem and needs to close.

Then aother window pops up and says:

Debug ERROR!
Program: blah blah /assignment3.exe
DAMAGE: After normal block (#44) at 0x00491BE0

What does all this mean??

I will post my program:

#include "pqueuebh.cpp"

#include <iostream>

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

class Patient

{

private:

int itsPatientNumber;

int itsPriority;

int itsTime;

int itsMisdiagnose;

public:

Patient ();

~Patient ();

void setPriority (int priority);

int getPriority ();

void setTime (int time);

int getTime ();

void setMisdiagnose (int misdiagnose);

int getMisdiagnose ();

void setPatientNumber (int patientNumber);

int getPatientNumber ();

bool operator < (const Patient &P) const

{

?if (itsPriority < P.itsPriority)

? return true;

?else if (itsPriority > P.itsPriority)

? return false;

?else if (itsTime < P.itsTime)

? return false;

?else

? return true;

}

};

Patient::Patient ()

{

itsPriority = itsTime = itsMisdiagnose, itsPatientNumber = 0;

}

Patient::~Patient ()

{

}

void Patient::setPriority (int priority)

{

itsPriority = priority;

}

int Patient::getPriority()

{

return itsPriority;

}

void Patient::setTime (int time)

{

itsTime = time;

}

int Patient::getTime ()

{

return itsTime;

}

void Patient::setMisdiagnose (int misdiagnose)

{

itsMisdiagnose = misdiagnose;

}

int Patient::getMisdiagnose ()

{

return itsMisdiagnose;

}

void Patient::setPatientNumber (int patientNumber)

{

itsPatientNumber = patientNumber;

}

int Patient::getPatientNumber ()

{

return itsPatientNumber;

}

int main()

{

using namespace std;

using std::cout;

using std::cin;

// variable declarations

int randomPriority, randomTime, treatTime, priority, i,j, misdiagnosed, theTime, miss, waysMisdiagnosed;

// set evil seed (initial seed), i found this on a site, it

// stated that this would make it more random

srand(static_cast<unsigned>(time(0)));

PQueue <Patient> PQ;

Patient patient[25];

Patient P;

for(i=0; i<26; i++)

{

?

?patient.setPatientNumber(i);

?randomPriority = (int) (5) * rand() / (RAND_MAX + 1.0);

?

?patient.setPriority(randomPriority);

?

?j++;

}

for(i=0; i<26; i++)

{

?randomTime = (int) (15 + (16) * rand() / (RAND_MAX + 1.0));

?

?patient.setTime(randomTime);

}

for(i=0; i<25; i++)

{

?PQ.Insert(patient);

}

for(i=0; i<25; i++)

{

?PQ.DeleteMin(P);

?

?cout<< "Patient " << P.getPatientNumber() << ?" has priority "<< P.getPriority() << endl;

}

return 0;

}

Okay here is the weird part. The code in red is the one that seems to give me those problems. I figured it out by commenting it out and when it was commented out it would print out the answer. But when I leave it in I get an error message mentioned above. I don't understand why though! What is wrong with:

patient.setPatientNumber(i);

this code? Or could it be something wrong with my Patient class?? Help please! Thanks! By the way "PQueue <Patient> PQ;" is just setting up a priority queue. The class for the priority queue has been written by my prof already and works fine. Also please feel free to give me suggestions on how to improve my patient class, such as my constructor and also other things I could add, I do not know really how to use the const keyword so feel free to tell me where to add it. Thank u.

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

holy crap I feel dumb. Ok. that seemed to fix it. Could anybody by the way give me suggestions on how to improve my patient class?

Link to comment
Share on other sites

  • 0
holy crap I feel dumb. Ok. that seemed to fix it. Could anybody by the way give me suggestions on how to improve my patient class?

Can't say I have any since it looks to be mostly get and set functions. Not to mention I don't know what it's supposed to do.

Link to comment
Share on other sites

  • 0
Fixed :p

Note: Use quote tags when you're using other tags inside (Y)

:no: gameguy - you didn't fix the bigger code tag.... :no:

Link to comment
Share on other sites

  • 0
Can't say I have any since it looks to be mostly get and set functions. Not to mention I don't know what it's supposed to do.

It seems that it is a class to handle patients. A typical extention of the elementary person class..... :sleep:

Link to comment
Share on other sites

  • 0
It seems that it is a class to handle patients. A typical extention of the elementary person class..... :sleep:

Yeah, that much I figured, but beyond that, I have no clue what kind of patient stuff it's supposed to handle.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.