Monday 27 August 2012

defining a class in C++


#include<iostream>

#include<conio.h>

using namespace std;

class Date

{

private :

       int day, month, year;      //__ Three private data members ___

public:

       //__ Member Functions ___
      
       void set_data(int temp_1, int temp_2, int temp_3)
       {
              day = temp_1;

              month = temp_2;
             
              year = temp_3;

       }      //__ Set the values of the data members __

       void get_data()
       {
              cout << "\nDay : " << day;

              cout << "  Month : " << month;

              cout << "  Year : " << year;

       }      //___ Print the data on the screen ___

};

int main()    //__ Main function to test the class ___
{
       Date d1;      //__ Creating the object of the Date class

       d1.set_data(11,12,2012);   //__ Setting the data by passing the values___

       d1.get_data();       //__ Printing the data by calling the member function of the Date class __

       getch();

       return 0;
}

No comments:

Post a Comment