1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include<iostream>
#include<stdlib.h>
using namespace std;
class date
{
public:
void display();
void setday(int i);
void setmonth(int i);
void setyear(int i);
int getday();
int getmonth();
int getyear();
//c0nstruct0r
//we used constructor overloading in tht programe
date(); //defauLt/simpLe c0nstruct0r:tAkes n0 argument
date(int); //parametrized:with 1 argument
date(int,int);//parametrized:with 2 arguments
date(int,int,int); //Parametrized c0nstructor: takes 3 argument
//destruct0r
~date();//destructor ~ with cLasss name is kaLLed destruct0r
private:
int Day,Month,Year;
};
//constructor definati0n
date::date()
{
Day=01;
Month=4;
Year=425;
cout<<"the simpLe/defauLt c0nstruct0r iz kaLLed\n";
}
date::date(int day1)
{
Day=day1;
Month=4;
Year=425;
cout<<"the pArametrized c0nstruct0r with 1 argument iz kaLLed\n";
}
date::date(int day1,int month1)
{
Day=day1;
Month=month1;
Year=812;
cout<<"the pArametrized c0nstruct0r with 2 argument iz kaLLed\n";
}
date::date(int day1,int month1,int year1)
{
Day=day1;
Month=month1;
Year=year1;
cout<<"the pArametrized c0nstruct0r with 3 argument iz kaLLed\n";
//u kan kaLL more arguments but the c0nditi0n iz tht,"the n0 of arguments or"
//the n0 of type of arguments must be different(function ovrLoading k0ncept)
}
//destructor
date::~date()
{
cout<<"0bject iz destroyed i.e..the destruct0r iz kaLLed\n";
}
//dispLying funct0nz
void date::display() //dispLay date
{
cout<<"daT iz :"<<getday()<<"-"<<getmonth()<<"-"<<getyear()<<endl;
}
//set day,month,year
void date::setday(int i)
{
Day=i;
}
void date::setmonth(int i)
{
Month=i;
}
void date::setyear(int i)
{
Year=i;
}
//getting the vaLues of day,m0nth,Year
int date::getday()
{
return Day;
}
int date::getmonth()
{
return Month;
}
int date::getyear()
{
return Year;
}
//mAin pr0gramme
int main()
{
//taking objects of cLAss date
date Date1,Date2(05),Date3(20,06),Date4(25,10,2011);
//other signs than coma in datee patrren wiLL sh0w err0r
//date5 wiLL sh0w the year by the c0nstructor we used 2020
//dispLaY dAte
Date1.display();
Date2.display();
Date3.display();
Date4.display();
system("pause");
}
|