I am try to write a C++ program that tells the eldest and youngest sibling in a family. i try to write write a member function that overloads the > Operator to sort the Siblings according to their ages after making comparisons.but i am fail. please someone write this. thanks
my program files are given below:
Sibling.cpp

#include <iostream.h>
#include <string.h>
#include <conio.h>

#include "Sibling.h"

Sibling::Sibling(const Sibling &obj)
{
int len=strlen(obj.name);
name=new char(len+1);
strcpy(name,obj.name);
age=obj.age;
}

void Sibling::setname(char *SiblingName)
{
name= new char(strlen(SiblingName+1));
strcpy(name,SiblingName);
}
void Sibling::setage(int SiblingAge)
{
if (age<=0)
{
cout<<"negative age is not allowed";
age=0;
}
age=SiblingAge;
}
char *Sibling ::getname()
{
return name;
}
int Sibling:: getage()
{
return age;
}

mail.cpp

#include <iostream.h>
#include <conio.c>
#include <string.h>
#include "Sibling.h"

int main()
{
int a=0 ;
char *nameofsibling=NULL;
int ageofsibling=0;
cout<<"Plz enter the no. of Sibling";
cin>>a;
Sibling siblingobj[a];

for(a=1;a<=a;a++)
{
cout<<"plz enter the particular of Sibling"<<a<<endl;
cout<<"name:";
cin>>nameofsibling;
cout<<"age:";
cin>>ageofsibling;
siblingobj[a].setname(nameofsibling);
siblingobj[a].setage(ageofsibling);
}
>()
return 0;
}

Sibling.h

#ifndef "Sibling.h"
class Sibling{
private:
         char *name;
         int age;
public:
       Sibling(); //constructor
       Sibling(const Sibling &obj);//copy constructor
       void setname(char *);//setter functions
       void setage(int a);
       char *getname();    //getter functions
       int getage();
       Sibling Sibling:operator >( int *array, int arraysize)
{
  for (int pass=0; pass<arraysize;pass++)
     for(int i=0;i<arraysize;i++)
     if a[i]>a[i+1];
     {
     int *temp=a[i];
     a[i]=a[i+1];
     a[i+1]=*temp;
     }
     
}
      
       
       ~Sibling()//destructor
{
if (name)
         {
         delete[]name;
          }
}
       };
bool Siblinb::operator<( const Sibling &other )
{
    return age < other.age ;
}

...
#include <algorithm>
... 

  std::sort( siblingobj, siblingobj + num_siblings ) ;
...

Let's use the other thread.

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.