//destructor
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class book
{
private:
int page;
float price;
char tittle[50];
public:
void setdata()
{
cout<<"enter tittle ";
gets(tittle);
cout<<"enter pages ";
cin>>page;
cout<<"enter price ";
cin>>price;
}
void showdata()
{
cout<<"tittle "<<tittle;
cout<<"\npages "<<page;
cout<<"\nprice "<<price;
}
book()
{
cout<<"the beginning"<<endl; //constructer is always executed first while
getch(); //destructer is always executed last regardless
} //of their position in the class
~book() //destructor
{
cout<<"\n\nobject destroyed";
getch();
}
};
void main()
{
book b1;
b1.setdata();
book b2(b1);
book b3=b1;
cout<<"\n\ndetails of book b1\n\n";
b1.showdata();
cout<<"\n\ndetails of book b2\n\n";
b2.showdata();
cout<<"\n\ndetails of book b3\n\n";
b3.showdata();
getch();
}
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class book
{
private:
int page;
float price;
char tittle[50];
public:
void setdata()
{
cout<<"enter tittle ";
gets(tittle);
cout<<"enter pages ";
cin>>page;
cout<<"enter price ";
cin>>price;
}
void showdata()
{
cout<<"tittle "<<tittle;
cout<<"\npages "<<page;
cout<<"\nprice "<<price;
}
book()
{
cout<<"the beginning"<<endl; //constructer is always executed first while
getch(); //destructer is always executed last regardless
} //of their position in the class
~book() //destructor
{
cout<<"\n\nobject destroyed";
getch();
}
};
void main()
{
book b1;
b1.setdata();
book b2(b1);
book b3=b1;
cout<<"\n\ndetails of book b1\n\n";
b1.showdata();
cout<<"\n\ndetails of book b2\n\n";
b2.showdata();
cout<<"\n\ndetails of book b3\n\n";
b3.showdata();
getch();
}
0 comments:
Post a Comment