Navigation Bar

Showing posts with label constructor. Show all posts
Showing posts with label constructor. Show all posts

Program of class Person using constructor, destructor, resolution operator in OOP



#include<iostream>
#include<conio.h>
using namespace std;
class person
{
                public :
                                char name[30], fname[30], contact[13], address[40];
                person() //Constructor
                {
                                cout<<"Enter Person Name: ";
                                gets(name);
                                cout<<"Enter person's FName: ";
                                gets(fname);
                                cout<<"Enter Contact No: ";
                                gets(contact);
                                cout<<"Enter Address: ";
                                gets(address);
                }
                void show();
                void sleep()
                {
                                cout<<"Person is Sleeping"<<endl;
                }
                void wake_up()
                {
                                cout<<"Person is Wakeup"<<endl;
                }
                void walk()
                {
                                cout<<"Person  is Walking"<<endl;
                }
                void run()
                {
                                cout<<"Person is Running"<<endl;
                }
                ~person() //destructor
                {
                                cout<<"\nAt the End Person Die";
                }
};
void person::show()//Resolution operator Method
{
                cout<<"\nPerson Name = "<<name<<endl;
                cout<<"Father Name ="<<fname<<endl;
                cout<<"Contact= "<<contact<<endl;
                cout<<"Address= "<<address<<endl<<endl;
}
int main()
{
                person s;
                s.show();
                s.sleep();
                s.wake_up();
                s.walk();
                s.run();
                getch();
}

Output

Program of House class using OOP



#include<iostream>
#include<conio.h>
using namespace std;
class house
{
public :

char name[30], area[40],owner[30],address[50];
house()
{
cout<<"Enter House Name : ";
gets(name);
cout<<"Enter Area : ";
gets(area);
cout<<"Enter Owner Name : ";
gets(owner);
cout<<"Enter Address : ";
gets(address);

}
void show();
void buy()
{

cout<<"House is Purchased"<<endl;

}
void sale()
{

cout<<"House is for Sale"<<endl;

}
void rent()
{

cout<<"House is for Rent\n"<<endl;

}
~house() //destructor
{
                cout<<"\tHouse Closed"<<endl;
}
};
void house::show()
{
cout<<"\nHouse Name = "<<name<<endl;
cout<<"Area "<<area<<" Marla"<<endl;
cout<<"Owner Name ="<<owner<<endl;
cout<<"Its Address ="<<address<<endl<<endl;
}
int main()
{
house s;
s.show();
s.buy();
s.sale();
s.rent();
getch();
}