skip to main
|
skip to sidebar
C++ Programs
Based on cusat cs 3rd sem 2009 lab cycle
Sunday, December 5, 2010
Add two date using operator overloading
#include<iostream.h> #include<conio.h> class date { int dd,mm,yy; public: void getdata() { cout<<"\nEnter date(dd mm yyyy) "; cin>>dd>>mm>>yy; } void putdata() { cout<<"\nDate(dd mm yyyy) "<<dd<<"/"<<mm<<"/"<<yy; } date operator+(date); }; date date::operator+(date t1) { date temp; int a=0,b=0,c=0,a1,b1,c1,a2,b2,c2,f=0; a1=dd; b1=mm; c1=yy; a2=t1.dd; b2=t1.mm; c2=t1.yy; while(a!=a1||b!=b1||c!=c1) { a++; if(b==2) { if(c%4!=0||(c%100==0&&c%400!=0)) f=28; else f=29; } else if(b==4||b==6||b==9||b==11) f=30; else f=31; if(a>f) { b++; a=1; } if(b>12) { c++; b=1; } a2++; if(b2==2) { if(c2%4!=0||(c2%100==0&&c2%400!=0)) f=28; else f=29; } else if(b2==4||b2==6||b2==9||b2==11) f=30; else f=31; if(a2>f) { b2++; a2=1; } if(b2>12) { c2++; b2=1; } } temp.dd=a2; temp.mm=b2; temp.yy=c2; return temp; } void main() { clrscr(); date d1,d2,d3; d1.getdata(); d2.getdata(); d3=d1+d2; cout<<"\nDate after addition "; d3.putdata(); getch(); }
No comments:
Post a Comment
Older Post
Home
Subscribe to:
Post Comments (Atom)
Home
8085 programming
Datastructure
Graphics programming
8086 Programming
LEX, YACC and parsers
Operating System
Programzz!
Add two date using operator overloading
Add two date using class
Decrement time by one using operator overloading(E...
Add two time using operator overloading(External q...
Compare two string. use operator overloading(Exter...
Matrix multiplcation(External Questn-2009)
Difference between two dates
Generic programming
File manipulation
Pure Virtual Function
Virtual Function
Multipath Inheritance
Hybrid Inheritance
Hierarchical inheritance
Addition of two distances using friend function
Class to class conversion
Basic to class and class to basic conversion
Operator functions as friend functions
Function overloading.
Static & Constant function
User defined string functions
Complex numbers using operator overloading.
Inline function
Add two time
Differnt temprature scale(Farenheit/celsius/kelvin).
Students details- using class
Students details- using structure
Check whether a date is valid or not
pass by value, pass by address, pass by refrence
Followers
Blog Archive
▼
2010
(29)
▼
December
(2)
Add two date using operator overloading
Add two date using class
►
October
(4)
►
July
(1)
►
May
(22)
About Me
Arun Ramesh
View my complete profile
No comments:
Post a Comment