i try to write a program using class that take number of particulars of sibling and take the name and age of each particulars from user and allocated seats. but my program has some error and does not compile and run. my code is:
//header files
#include<iostream.h>
#include<conio.c>
//class definition
class Sibling
{
//hidden part
private:
//for Sibling's name
char name[25];
//for Sibling's age
int age;
//for Sibling's seat number
int pass_seat_num;
//for keeping track of alloted seats
static int seat_num;
//interface
public:
//constructor
Sibling();
//setter for Sibling name
void set_name(char* name);
//setter for sibling age
void set_age(int age);
//getter for Sibling name
char* get_name();
//getter for sibling age
int get_age();
//display function
void display();
//destructor
~Sibling(){}
};
//initializing static data member
int Sibling::seat_num = 0;
//constructor
Sibling::Sibling()
{
name[25]='\0';
pass_seat_num = ++seat_num;
}
//setting name
void Sibling::set_name(char* name1)
{
for(int i=0;i<25;i++)
name=name1;
}
//getting name
char* Sibling::get_name()
{
return name;
}
void Sibling::set_age(int age1)
{
for(int i=0; i<50;i++)
age=age;
}
//getting age
int Sibling::get_age()
{
return age;
}
//display function to display passengers names and age w.r.t alloted seat numbers
void Sibling::display()
{
cout<<get_name()<<" alloted "<<pass_seat_num;
}
//main function
int main()
{
//for number of Sibling
int num=0;
//for name
char name[25];
//taking input of number of Sibling
cout<<"Please enter the number of Sibling: ";
cin>>num;
cout<<"Please enter the particulars eachs of Sibling: "<<endl;
//declaring Sibling object
Sibling* p;
//creating array of objects
p= new Sibling[num];
//declaring Sibling object
Sibling temp;
//taking input for the name of all Sibling
for(int i=0;i<num;i++)
{
cout<<endl<<"Please enter the particulars of Sibling: "<<i+1;
cout<<endl<<"\n\t\tName: ";
gets(name);
p.set_name(name);
cout<<endl<<"\n\t\tAge: ";
gets(age);
p.set_age(age);
}
//calling display w.r.t each object
for(int i=0;i<num;i++)
{
cout<<"\n\n\t\t";
p.display();
}
//deleting array of objects
delete []p;
getch();
return 0;
}