Answer to Question #174147 in C++ for Raj Kumar

Question #174147

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-22T01:58:57-0400
#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;

}


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