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.
//********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.
Comments
Leave a comment