954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Urgent check this and help me.

I am try to write a C++ program that tells the eldest and youngest sibling in a family. I am write this program declaring a class.I write all code program but my program does not compiles and give oprator error. Please someone check this and make it correct.I need this type of output
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
My rogram source code is here
[HTML]#include
#include
#include

// defining the Sibling class
class Sibling
{
// hidden part of the class
private:
char *name; // for Sibling name
int age; // for Sibling age
// interface of the class
public:
Sibling(); //constructor
Sibling(const Sibling &obj);//copy constructor
void setname(char *);//setter function for name
void setage(int a); //setter function for age
char *getname(); //getter function for name
int getage(); //getter function for age
~Sibling(); //destructor
bool operator >(int *array int arraysize); // overloading assignment operator
};
bool Sibling::operator >( int *array, int arraysize)
{
for(int i=0;ia[i+1];
{
int *temp=a[i];
a[i]=a[i+1];
a[i+1]=*temp;
}
}
Sibling::~Sibling()//destructor
{
if (name)
{
delete[]name;
}
}

Sibling::Sibling(const Sibling &obj)
{
int len=strlen(obj.name);
name=new char(len+1);
strcpy(name,obj.name);
age=obj.age;
}
// setting the Sibling name
void Sibling::setname(char *SiblingName)
{
name= new char(strlen(SiblingName+1));
strcpy(name,SiblingName);
}
// setting the Sibling age
void Sibling::setage(int SiblingAge)
{
if (age<=0)
{
cout<<"Negative age is not allowed";
age=0;
}
age=SiblingAge;
}
// getting the Sibling name
char *Sibling ::getname()
{
return name;
}
// getting the Sibling age
int Sibling:: getage()
{
return age;
}

//Main program. We will take Sibling object

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

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

return 0;
getch();
}[/HTML]

iqbal
Newbie Poster
10 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

In overloading you need atleast one user defined type

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 
int main() {
    // ...

    return 0;
    getch();
}

Oops. :)

dwks
Posting Whiz in Training
269 posts since Nov 2005
Reputation Points: 185
Solved Threads: 28
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You