Answer to Question #175108 in C++ for KAVIN MUKILAN

Question #175108

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-24T05:21:06-0400
#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;
}

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