Computer Science Canada sorting technique c/c++ code |
Author: | shanebond [ Thu Nov 18, 2010 3:15 am ] |
Post subject: | sorting technique c/c++ code |
Hello everyone i'm new to this kind of things plz help me to solve this , if anyone can post the c/c++ code also i shall be thankfull to you An eccentric doctor visits his patients in order of decreasing age. Patients entering the waiting list specify not only their names but also their ages. Each time the doctor wants to visit a patient, the oldest is selected and removed from the list (so children may have to wait a very long time). Write a program, based on elementary sorting techniques to sort this list on first on Age and then on Patient ID, which this doctor can use. Before PatientID Name Age P102 Arif Taj Mairza 50 P203 Sadar Khan 65 P546 Afsheen Bano 34 P605 Kai Whong 45 P340 Hanah Duong 23 P391 Usman Habib 65 P200 Alina Shah 34 After PatientID Name Age P203 Sadar Khan 65 P391 Usman Habib 65 P102 Arif Taj Mairza 50 P605 Kai Whong 45 P200 Alina Shah 34 P546 Afsheen Bano 34 P340 Hanah Duong 23 Solve this problem by applying four different elementary sorting techniques that are a) Selection sort b) Bubble sort c) Insertion sort d) Shell sort |
Author: | rdrake [ Thu Nov 18, 2010 4:11 am ] |
Post subject: | Re: sorting technique c/c++ code |
I kept deleting your threads, but they just kept popping up. Since I deleted yet another one of your duplicate threads with a response this time, let me quote it here. A.J wrote: A: Never make multiple threads in different places. This is actually where it belongs.
As was said above, we will not do your work. We can, of course, point you in the right direction.
B: We don't do your work for you. Steer you in the right direction, perhaps, but nothing more. I realize you are new here, so I am merely letting you know how things work around here before other people get offended. An enterprising copy paster should be able to find C++ implementations of all the required sorting algorithms on Google. Of course, this does not appear to be the case. You appear to be doing a very poor job of cheating on your assignment. Attempt to solve it yourself and post back if you get stuck. |
Author: | shanebond [ Thu Nov 18, 2010 6:51 am ] |
Post subject: | RE:sorting technique c/c++ code |
i have done this so far , now plz guide me how to sort this with respect to patient id and age #include <iostream> using namespace std; typedef struct { char name[100]; int patientno; int age; } Input; int main (int argc, char *argv[],int pno) { int i; int NUMBER_OF_PATIENTS; cout<<"Enter number of patients:"; cin>>NUMBER_OF_PATIENTS; Input input[NUMBER_OF_PATIENTS]; int patientno; for (i=0; i < NUMBER_OF_PATIENTS; ++i) { cout<<"Enter patient no: "; cin>>input[i].patientno; cout<<"Enter patient name:"; cin>>input[i].name; cout<<"Enter patient age:"; cin>>input[i].age; } for (i=0; i<NUMBER_OF_PATIENTS; ++i) { cout<<"P"<<input[i].patientno<<" "<<input[i].name<<" "<<input[i].age<<endl; } system("pause"); return 0; } |
Author: | OneOffDriveByPoster [ Fri Nov 19, 2010 1:12 am ] |
Post subject: | Re: RE:sorting technique c/c++ code |
shanebond @ Thu Nov 18, 2010 6:51 am wrote: int main (int argc, char *argv[],int pno) What is this "pno". Why do you use it? Does your research indicate that it is portable?
shanebond @ Thu Nov 18, 2010 6:51 am wrote: int NUMBER_OF_PATIENTS; This is not a constant. I do not think all-caps reflects that.
shanebond @ Thu Nov 18, 2010 6:51 am wrote: Input input[NUMBER_OF_PATIENTS]; VLAs are not part of the C++ Standard.
shanebond @ Thu Nov 18, 2010 6:51 am wrote: system("pause"); Are you getting this from iostream? Should you be?
I suspect that the assignment came with suggestions on how the sorting should be done. I see no attempt at sorting here. Think about what you need to do the sorting: you probably need to do comparisons and you probably need some way of reordering the data. |