Answer to Question #174177 in C++ for Sharath kumar

Question #174177

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.


1
Expert's answer
2021-03-23T16:18:37-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS