473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Plz Help Me To Debug This Prog!!!!

momotaro
357 100+
This is what am i asked to do:

Implement a priority queue to manage patients in an emergency room
You MUST use the files “patient.h” and “ER.c” as given.
You should write the files “patientqueue.c” and “patientqueue.h” so that they work correctly with the two files above.
For most credit:
Submit two implementations of patientqueue.c, using the two approaches described above.
Make sure that the queue is never full, by allowing it to grow

And this is my prog:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4. #define MAXQ 20
  5.  
  6. typedef struct patient
  7. {
  8.     char name[30];
  9.     int patientID,
  10.         severity,
  11.         ArrivalTime;
  12. }Patient;
  13.  
  14. typedef Patient QueueEntry;
  15.  
  16. typedef struct queue
  17. {
  18.     int count,
  19.         rear,
  20.         front,
  21.         Maxseverity;
  22.     QueueEntry entry[MAXQ];
  23. }PatientQueue;
  24.  
  25. void getPatient(Patient *newPatient) ;
  26. int PQFull(PatientQueue *q);
  27. int PQEmpty(PatientQueue *q);
  28. void PQAppend(Patient p, PatientQueue *q);
  29. void getPatient(Patient *newPatient) ;
  30. void PQMaxServe(QueueEntry *item,PatientQueue *q);
  31. void PQPrint(PatientQueue *q);
  32. PatientQueue *newPQ(int Maxseverity);
  33.  
  34. int time = 0;
  35.  
  36. // Main program, reads one patient, and then processes patients until
  37. // the queue is empty.int main() {
  38.  
  39. int main() {
  40.     PatientQueue *theQueue = newPQ(4);
  41.     Patient thePatient;
  42.     char action;
  43.     int time = 0;
  44.  
  45.     getPatient(&thePatient);
  46.     PQAppend(thePatient, theQueue);
  47.     while(!PQEmpty(theQueue)){
  48.         printf("Enter an action; 'a' for arrive, 'n' for next: ");
  49.         getchar();
  50.         scanf("%c", &action);
  51.  
  52.         switch(action) {
  53.             case 'a':
  54.                 if(PQFull(theQueue)) {
  55.                     printf("Too many patients!  Go somewhere else.\n");
  56.                     break;
  57.                     }
  58.                 else{
  59.                     getPatient(&thePatient);
  60.                     PQAppend(thePatient, theQueue);
  61.                     break;
  62.                 }
  63.             case 'n':
  64.                 if(PQEmpty(theQueue)) {
  65.                     printf("No patients!  Take a break.\n");
  66.                     break;
  67.                     }
  68.                 PQMaxServe(&thePatient, theQueue);
  69.                 printf("Patient %s (%d, severity %d) helped after waiting %d.\n",
  70.                     thePatient.name, thePatient.patientID,
  71.                     thePatient.severity, time - thePatient.ArrivalTime);
  72.             }
  73.         printf("Queue at time %d:\n", time++);
  74.         PQPrint(theQueue);
  75.     }
  76. }
  77. //TOP DOWN FUNCTIONS
  78.  
  79. void PQMaxServe(QueueEntry *item,PatientQueue *q){
  80.     if(PQEmpty(q))
  81.         printf("The queue is empty!\n");
  82.     else{
  83.         *item=q->entry[q->front];
  84.         q->front=(q->front+1)%MAXQ;
  85.         q->count--;
  86.     }
  87. }
  88.  
  89.  
  90. void getPatient(Patient *newPatient) {
  91.     printf("Enter patient name:  ");
  92.     scanf("%s", newPatient->name);
  93.     printf("Enter patient ID:    ");
  94.     scanf("%d", &newPatient->patientID);
  95.     printf("Enter severity (1-4):");
  96.     scanf("%d", &newPatient->severity);
  97.     newPatient->ArrivalTime = time;
  98.     }
  99.  
  100. void PQAppend(Patient p, PatientQueue *q)
  101. {
  102.     int i=q->rear;
  103.     if(PQFull(q))
  104.         printf("queue is full(PQappendfunction)");
  105.     else if(p.severity > q->Maxseverity)
  106.         printf("wrong severity\n");
  107.     else if(PQEmpty(q)){
  108.         printf("Qempty case\n");
  109.         q->rear++;
  110.         strcpy(q->entry[q->rear].name,p.name);
  111.         q->entry[q->rear].patientID=p.patientID;
  112.         q->entry[q->rear].ArrivalTime=p.ArrivalTime;
  113.         q->entry[q->rear].severity=p.severity;
  114.         q->count++;
  115.  
  116.     }
  117.     else{
  118.         while(1){
  119.             if(p.severity > q->entry[i].severity)
  120.                 q->entry[i+1] = q->entry[i];
  121.             else{
  122.                 strcpy(q->entry[i+1].name,p.name);
  123.                 q->entry[i+1].patientID=p.patientID;
  124.                 q->entry[i+1].ArrivalTime=p.ArrivalTime;
  125.                 q->entry[i+1].severity=p.severity;
  126.                 q->count++;
  127.                 q->rear = (q->rear+1)%MAXQ;
  128.                 printf("Apended\n\a");
  129.                 break;
  130.                 }
  131.                 i--;
  132.             }
  133.         }
  134.     }
  135.  
  136.  
  137. PatientQueue *newPQ(int Maxseverity)
  138. {
  139.     PatientQueue *New = (PatientQueue*)malloc(sizeof(PatientQueue));
  140.     New->count = 0;
  141.     New->front = 0;
  142.     New->rear = -1;
  143.     New->Maxseverity = Maxseverity;
  144. return New;
  145. }
  146.  
  147. int PQEmpty(PatientQueue *q)
  148. {
  149.     return q->count <= 0;
  150. }
  151.  
  152. int PQFull(PatientQueue *q)
  153. {
  154.     return q->count >= MAXQ;
  155. }
  156. /*
  157. patient *newPatient() {
  158.     patient *newpatient = (patient *) malloc (sizeof(patient));
  159.     printf("Enter patient name:  ");
  160.     scanf("%s", newpatient->name);
  161.     printf("Enter patient ID:    ");
  162.     scanf("%d", &newpatient->patientID);
  163.     printf("Enter severity (1-4):");
  164.     scanf("%d", &newpatient->severity);
  165.     newpatient->arrivaltime = time;
  166.     return newpatient;
  167.     }*/
  168. void PQPrint(PatientQueue *q){
  169.     int i;
  170.     if(PQEmpty(q))
  171.         printf("Queue is Empty, nothing to print\n");
  172.     else{
  173.         for(i=0;i<q->count;i++){
  174.             printf("Patient %d: %s \nPatientID: %d\nseverity: %d\nArrivalTime: %d\n\n\n",i,q->entry[(q->front+i)%MAXQ].name,
  175.                 q->entry[(q->front+i)%MAXQ].patientID,q->entry[(q->front+i)%MAXQ].severity,q->entry[(q->front+i)%MAXQ].ArrivalTime);
  176.     }
  177.     }
  178. }

PLZ HELP!!!
Mar 18 '07 #1
2 1397
willakawill
1,646 1GB
You need to read the posting guidelines particulary with reference to assignments
Mar 18 '07 #2
DeMan
1,806 1GB
It is not entirely clear exactly what you would like help with. Rather than posting the assignment question, could you please try to explain what sort of problems you are having. Try to include
what the actual program/class is supposed to do
how/why the behaviour of your program is not what is expected
any ideas you might have on why this is the case
Mar 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Yannick | last post by:
Hi, I have a small app in VB that implements a C++ OCX I would like to debug the OCX from VB prog or even better debug both at once ! I was able to do this in visual studio 6 by referencing the...
2
by: SorceCode | last post by:
Hey guys, good old > Debug Assertion Failed! > File: dbgdel.cpp > Line: 47 > Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Rears its ugly head agian! Ok heres what Im up to..
2
by: w3r3w0lf | last post by:
hello! can anyone explain this to me? I get a "debug assertion failed" msg after some time in my prog...: file fclose.c, stream!=null thanks!
0
by: jhorner | last post by:
I am writing a c# app and need the ability to drag a file onto the icon - this should then run the app and do something with the file. I made the assumption that doing so would call the app with...
6
by: Boni | last post by:
Dear all, I have following problem. I created a static libruary (mylib.lib). I compiled it with Multithreaded DLL runtime in release mode. Now I want to give out this library. But users who...
2
by: msnews.microsoft.com | last post by:
We are deploying a large .NET 1.1 web app. We are using SP1 of the .NET 1.1 framework. Our build system compiles all of our components in release mode. We deploy on Windows Server 2003 Enterprise...
1
by: ניר | last post by:
Hello, I've already sent such a messege, hopping to be answered shortly this time. I am practicing c/c++ programming using microsoft visual c++ express 2005 express edition. Anyway, unlike other...
4
momotaro
by: momotaro | last post by:
when I give the prog the first data it crushs !!!! and give me this message: Unhandled exception at 0x004114c5 in CallocMalloc.exe: 0xC0000005: Access violation reading location 0x00000002. ...
1
by: davy zhang | last post by:
I mean every process attach like thread in wingide like thread or tasklet in wingide :) maybe I asked toooo much:D
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.