Design a class Calendar to calculate number of years, months and days. The member variables are nds, years, months and days. The member functions are d() which accepts number of days and display() to display total number of years, months and days.
#include <iostream>
using namespace std;
class Date{
int nds;
int days;
int months;
int years;
public:
void display(){
cout << "Years : " << this->years << "\nMonths : " << this->months << "\nDays : " <<
this->days;
}
void d(int nds){
this->nds = nds;
this->years = nds / 365;
if(this->years > 0){
this->months = (nds/ 30) - (12* this->years);
nds = nds - 365*this->years;
this->days = nds%30;
}
else{
this->months = (nds/ 30);
this->days = nds - (months * 30);
}
}
};
int main()
{
Date date;
date.d(366);
date.display();
return 0;
}
Comments
Leave a comment