Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ Day of year program. This uses the Julian date (1 – 365) and translates it i

ID: 3674375 • Letter: C

Question

c++ Day of year program.

This uses the Julian date (1 – 365) and translates it into a string consisting of the month followed by the day in that moth, ignore leap years for this assignment. For example:

Day 23 would translate to January 23 Day 32 would translate to February 1 Day 360 would translate to December 26

A constructor for this class should take an integer as a parameter representing the day of the year, and the class should have a public member function print() that prints the day in the month-day format. The class should have an integer member variable to represent the day and should have static member variables holding string objects that can be used to assist in thr translation from integer format to the month-day format. Test your class by inputting various integers representing days and printing out their representations in the month-day format.

Create a program description, algorithm, source code and screen shot document

Explanation / Answer

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>

using namespace std;
// Class declaration
class DayOfYear
{
public:
   int day;
   string Month;

   // Constructor function
   DayOfYear(int dayEntered)
   {
       day = dayEntered;
       //cout << "Please enter a number from 1 to 365" << endl;
       //cin >> dayEntered;
         
   } // end constructor function

   void print()
   {
      
           if(day >= 1 && day <= 31)
           {
               cout << "January " << day << endl;
           }
  
           if(day >= 32 && day <= 59)
           {
               cout << "February " << (day - 31) << endl;
           }

           if(day >= 60 && day <= 90)
           {
               cout << "March " << (day - 59) << endl;
           }

           if(day >= 91 && day <= 120)
           {
               cout << "April " << (day - 90) << endl;
           }

           if(day >= 121 && day <= 151)
           {
               cout << "May " << (day - 120) << endl;
           }

           if(day >= 152 && day <= 181)
           {
               cout << "June " << (day - 151) << endl;
           }

           if(day >= 182 && day <= 212)
           {
               cout << "July " << (day - 181) << endl;
           }

           if(day >= 213 && day <= 243)
           {
               cout << "August " << (day - 212) << endl;
           }

           if(day >= 244 && day <= 273)
           {
               cout << "September " << (day - 243) << endl;
           }

           if(day >= 274 && day <= 304)
           {
               cout << "Octobe r" << (day - 273) << endl;
           }

           if(day >= 305 && day <= 334)
           {
               cout << "November " << (day - 304) << endl;
           }

           if(day >= 335 && day <= 365)
           {
               cout << "December " << (day - 334) << endl;
           }
      

   } // end print function

      
}; // end Class DayOfYear

int main()
{
int day;
cout << "Enter the Day of the Year: ";
cin >> day;
   // choose a day to print
   DayOfYear d(day);
   // print day 78 in Month and Day format
   d.print();

   system("Pause");
   return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote