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.i need this type of output
Please enter the number of siblings: 4
Please enter the particulars of each sibling:
Please enter the particulars of Sibling: 1
Name: Arif Age: 20
Please enter the particulars of Sibling: 2
Name: Sana Age: 16
Please enter the particulars of Sibling: 3
Name: Sobia Age: 13
Please enter the particulars of Sibling: 4
Name: Amna Age: 10
Arif, having age 20 is the eldest sibling whereas Amna, having age 10 is the youngest
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 Siblingperator >( 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;
}
}
};