Navigation Bar

Showing posts with label class. Show all posts
Showing posts with label class. 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 class car using setter, getter, destructor in OOP



#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
class car
{
                public :
                int model;
                char company;
                char color;
                int price;
                void get()
                {
                cout<<"Enter car model year: ";
                cin>>model;
                cout<<"Enter company name: ";
                cin>>company;
                cout<<"Enter color: ";
                cin>>color;
                cout<<"Enter Price: ";
                cin>>price;
                }
                void set(int mod,char comp, char clr,int pr)
                {
                                model = mod;
                                company = comp;
                                color = clr;
                                price = pr;                           
                }
void show()
                {
                                cout<<"Car Model = "<<model<<endl;
                                cout<<"Car manufacture = "<<company<<endl;
                                cout<<"Car color = "<<color<<endl;
                                cout <<"Car = "<<price<<endl<<endl;
                }
                void accelerator()
                {
                                cout<<"Car is accelerating"<<endl;
                }
                void start()
                {
                                cout<<"Car is starting"<<endl;
                }
                int getprice()
                {
                                return price;
                }
                ~car()
                {
                                cout<<"\n\tPlease lock the Car"<<endl;
                }
};
int main()
{
                car s, s1;
                s.get();
                s1.set(2016,'T','R',255000);
                cout<<"\tSpecifications of both Cars"<<endl;
                s.show();
                s1.show();
                cout<<"\tHigh Price Cars is"<<endl;
                if(s.getprice()>s1.getprice())
                                s.show();
                else
                 s1.show();
                 s.start();
                s.accelerator();
                getch();
}

Output