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 Calendar{
public:
int nds, years, months, days;
Calendar(){}
Calendar(int x){
this->nds = x;
}
void d(){
this->years = this->nds / 365;
this->months = (this->nds - this->years * 365) / 30;
this->days = this->nds - this->years * 365 - this->months * 30;
}
void display(){
cout<<"Years: "<<this->years;
cout<<"\nMonths: "<<this->months;
cout<<"\nDays: "<<this->days;
}
};
int main(){
int n;
cout<<"Input number of days: ";
cin>>n;
Calendar C(n);
C.d();
C.display();
return 0;
}
Comments
Leave a comment