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

jonsca commented: Don't post the same thing in multiple forums of the site -1

The easiest way to do this might be to use an array of structs, where the struct was prototyped right below the include files, with members like int ID; char name[50]; etc.

Then in main() create an array of those structs with struct student students[50] (for say, 50 students). Each field can be accessed with the dot operator -
students[0].ID, or students[2].name, for instance.

Wikipedia has an extensive page on all those kinds of sorts, and Google is always your friend, as well.

I hope you're not waiting for someone to do it for you - that (almost) never happens on this forum. We help you - but don't do it for you.

Post up your code and tell us what has you stumped. But don't wait for someone to do this for you, on this forum.

I couldn't get your page to display, btw. Generally always better to post it, directly. Linked stuff tends to be easily ignored.

Cheers! ;)

Take a look at something like http://www.sorting-algorithms.com/ to get the gist of the sorting algorithms. Give at least one or two of them a try (with code, we don't provide code, that's your job) and post back. Bubble is probably the most intuitive, so start with that one, swap elements until the smallest is at the end, and then swap until the second smallest is second from the end, etc.

i have done this so far now plz guide me how to sort them with respect to age and patient number

#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;

}

Please use code tags [code] //code goes here [/code].

Your cin statement for name will not work because your patients have a first name and surname separated by a space.

Can you sort an array of integers via a bubble sort? Have a look at that site that I indicated, and make a separate program to try that first. Then, incorporate that program into your main one and use it to sort your array based on the patient number.

@shanebond you seriously started off on wrong foot in this forum.
1. Creating multiple posts on some question (C, C++ and Computer Science)
2. Not sing code tags when posting
3. Now this is action you need to take ==>> READ FORUM RULES

commented: Yes +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.