Categories
- 4th semester (27)
- 5th semester (3)
- ADA (13)
- Assembly Level Language (12)
- BE (45)
- C Language Programming (5)
- C language (20)
- C++ Language (5)
- CCP Lab programing (3)
- Computer Programming Lab (3)
- DAA Lab Programming (13)
- Data Structure and C++ laboratory Program (6)
- Data Structure and C++ labotary Program (5)
- Design and Analysis of algorithm (14)
- First Year (5)
- MASM (12)
- Microprocessor (12)
- Microprocessor lab program (12)
- System Software & OS Laboratory (5)
- Unix program (4)
- bachelor of engineering (30)
- basic (1)
- basic mathematics (2)
- beginners (10)
- c++ program (9)
- calculations (7)
- computer science (30)
- downloadable (5)
- engineering syllabus (4)
- simple program (6)
Trend Posts
Blogger news
Author
Followers
Blog Archive
-
▼
2014
(37)
-
▼
July
(20)
- Unix Child Execution Program|System Software & OS ...
- Program to Multiply two Matrice by Using C Language
- How to Read A Matrix and Display it by Using C Lan...
- Program to Read a String by Using C Language
- Lab Program:DATE|Second Year|Data structure and OO...
- QuickSort Program|Design and Analysis of algorithm...
- Warshall Program|Design and Analysis of algorithms...
- Topological Ordering|Design and Analysis of algori...
- Travaling Salesperson Problem With Optimal Solutio...
- Traveling Sales person in the approximation method...
- Subset Program|Design and Analysis of algorithms|4...
- Dijkstra's Algorithm |Design and Analysis of algor...
- Floyd's Algorithm|Design and Analysis of algorithm...
- DFS Method Program|Design and Analysis of algorith...
- BFS Method Program|Design and Analysis of algorith...
- Kruskal's Algorithm|Design and Analysis of algorit...
- Prim's Algorithm|Design and Analysis of algorithms...
- Knapsack Dynamic Program|Design and Analysis of al...
- N Queen's Problem Program|Design and Analysis of a...
- Mergesort Program|Design and Analysis of Algorithm...
-
▼
July
(20)
Monday, July 21, 2014
Design,develop and execute a program in c++ to create a class called DATE with methods to accept two valid dates in the form dd/mm/yy and to implement the following operation by overloading the operators + and – After every operation the results are to be displayed by overloading the operator<<
i.no_of_days=d1-d2;where d1 and d2 are DATE objects,d1>=d2 and no_of_days is an integer.
ii.d2=d1+no_of_days;where d1 is a DATE object and no_of_days is an integer.
#include<iostream.h>
#include<conio.h>
class date
{
int dd;
int mm;
int yy;
int a[13];
public:
date()
{
a[1]=31;a[2]=28;a[3]=31;a[4]=30;a[5]=31;a[6]=30;a[7]=31;a[8]=31;a[9]=30;
a[10]=31;a[11]=30;a[12]=31;dd=0;mm=0;yy=0;
}
date operator+(int n);
int operator-(date d2);
friend ostream& operator<<(ostream &print,date d1);
void read();
int isleap(date d1);
};
date date::operator+(int n)
{
int i;
for(i=1;i<=n;i++)
{ dd++;
if(isleap(*this))
{
a[2]=29;
}
if(dd>a[mm])
{
dd=1;
++mm;
}
if(mm>12)
{
mm=1;
++yy;
}
}
return (*this);
}
int date::operator-(date d2)
{ int count=0;
while(!((mm==d2.mm)&&(dd==d2.dd)&&(yy==d2.yy)))
{ count++;
d2.dd++;
if(isleap(d2))
{
d2.a[2]=29;
}
if(d2.dd>d2.a[d2.mm])
{
d2.dd=1;
d2.mm++;
}
if(d2.mm>12)
{
d2.mm=1;
d2.yy++;
}
}
return count;
}
void date::read()
{
cout<<"enter the date"<<endl;
cout<<"dd="<<endl;
cin>>dd;
cout<<"mm="<<endl;
cin>>mm;
cout<<"yy="<<endl;
cin>>yy;
}
int date::isleap(date d1)
{
if((d1.yy%4==0)&&(d1.yy%100!=0))
{
return 1;
}
else
return 0;
}
ostream& operator<<(ostream &print,date d1)
{
print<<d1.dd<<"/"<<d1.mm<<"/"<<d1.yy<<endl;
return print;
}
void main()
{
int no_of_days=0;
date d1,d2,d3;
clrscr();
d1.read();
cout<<"date1="<<d1;
cout<<"temp="<<endl;
cin>>no_of_days;
d3=d1+no_of_days;
cout<<"date3="<<d3;
d2.read();
cout<<"date2="<<d2;
no_of_days=d1-d2;
cout<<"no_of_days="<<no_of_days<<endl;
getch();
}
//program end
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment
You are very Important to Us...
STAY TUNE...