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