Answer to Question #172501 in C++ for Boopathi

Question #172501

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-18T21:13:01-0400
//********C++ class Calendar program to calculate *******//
//****************number of years, months and days.******//


#include <iostream>		//import header file library
using namespace std;		// allows the use of object names and variables from the standard library




//member variable declaration (nds, years, months, days and functions) includes datatype for each variable.
class Calendar
{
public:
  int nds;
  int months;
  int year;
  int days;
  void d ();
  void Display ();


};


// initialization of  function named d() which accepts number of days as user input
void
Calendar::d ()
{
  cout << "Please Input the number of days : ";
  cin >> nds;
  
  year = nds / 365;
  nds = nds - (365 * year);
  months = nds / 30;
  days = nds - (months * 30);


}




 // initialization of  function named Display() outputs the total number of years, months and days
 //as user feedback.
void
Calendar::Display ()
{
  cout << "Years : " << year << "\nMonths : " << months << "\nDays : " <<
    days;
}


//Start of the driving / Main method    
int
main ()
{
  Calendar myCalendar;		// Create an object of MyClass
  myCalendar.d ();
  myCalendar.Display ();
  return 0;
}


//the end.

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