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

Question #172849

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-19T08:02:34-0400
#include <iostream> 
using namespace std; 
 
class Calendar
{
private:
  int nds;         // number of days
  int months;
  int year;
  int days;
 
public: 
//default constructor
  Calendar(){
    nds  = 0;       // number of days
    months= 0;
    year = 0;
    days = 0;   
  }
// The member functions: accepts number of days 
  void d ();
 
// The member functions: display number of years, months and days
  void Display ();
  };
 
void Calendar::d () 
{
  cout << "Please Input the number of days : ";
  cin >> nds;
 
  year = nds / 365;                 // number of years
  months = (nds%365)/30;   // number of months
  days = (nds%365)%30;      // number of days
 
}
 
void Calendar::Display ()
{
   cout << "Years: " << year << "\nMonths: " << months << "\nDays: " <<
   days<<endl<<endl;
}
 
int main ()
{
// Create an object myCalendar of Class Calendar
  Calendar myCalendar;       
  myCalendar.Display (); // display default number of years, months and days
 
  myCalendar.d ();        // accepts number of days 
  myCalendar.Display (); // display number of years, months and days
  
  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