Modify the DayOfYear class, to add a constructor that takes two parameters: a string object representing a month and an integer in the range 0 through 31 representing the day of the month. The constructor should then initialize the integer member of the class to represent the day specified by the month and day of month parameters. The constructor should terminate the program with an appropriate error message if the number entered for a day is outside the range of days for the month given. Add the following overload operators: ++ prefix and postfix increment operators. These operators should modify the DayOf Year object so that it represents the next day. If the day is already the end of the year, the new value of the object will represent the first day of the year. -- prefix and postfix decrement operators. These operators should modify the DayOf Year object so that it represents the previous day. If the day is already the first day of the year, the new value of the object will represent the last day of the year.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ compile a program to answer question in picture included.

Code to edit:

 

#include <iostream>

#include <string>

class DayOfYear
{

private:
  mutable int day; // Make 'day' mutable

  // Static arrays to hold month names and the number of days in each month

  static const std::string monthNames[];

  static const int daysInMonth[];

public:
  // Constructor

  DayOfYear (int day) : day (day) {}

  // Member function to print the day in month-day format

  void
  print () const
  {

    int tempDay = day; // Create a temporary variable

    int month = 0;

    // Find the month for the given day

    while (tempDay > daysInMonth[month])
      {

        tempDay -= daysInMonth[month];

        month++;
      }

    // Print the result

    std::cout << monthNames[month] << " " << tempDay << std::endl;
  }
};

// Static member variable initialization

const std::string DayOfYear::monthNames[] = {

  "January", "February", "March",     "April",   "May",      "June",

  "July",    "August",   "September", "October", "November", "December"

};

const int DayOfYear::daysInMonth[] = {

  31, 28, 31, 30, 31, 30,

  31, 31, 30, 31, 30, 31

};

int
main ()
{

  int userDay;

  // Get user input for the day of the year

  std::cout << "Enter the day of the year: ";

  std::cin >> userDay;

  // Validate user input

  if (userDay < 1 || userDay > 365)
    {

      std::cerr << "Invalid input. Day of the year should be between 1 and 365."
                << std::endl;

      return 1;
    }

  // Create an instance of the DayOfYear class with user input

  DayOfYear userDayOfYear (userDay);

  // Print the representation in month-day format

  std::cout << "Day " << userDay << ": ";

  userDayOfYear.print ();

  return 0;
}

Modify the DayOfYear class, to add a constructor that takes two parameters: a string
object representing a month and an integer in the range 0 through 31 representing
the day of the month. The constructor should then initialize the integer member of the
class to represent the day specified by the month and day of month parameters. The
constructor should terminate the program with an appropriate error message if the
number entered for a day is outside the range of days for the month given.
Add the following overload operators:
++ prefix and postfix increment operators. These operators should modify the
DayOfYear object so that it represents the next day. If the day is already the end of
the year, the new value of the object will represent the first day of the year.
prefix and postfix decrement operators. These operators should modify the
DayOfYear object so that it represents the previous day. If the day is already the first
day of the year, the new value of the object will represent the last day of the year.
Transcribed Image Text:Modify the DayOfYear class, to add a constructor that takes two parameters: a string object representing a month and an integer in the range 0 through 31 representing the day of the month. The constructor should then initialize the integer member of the class to represent the day specified by the month and day of month parameters. The constructor should terminate the program with an appropriate error message if the number entered for a day is outside the range of days for the month given. Add the following overload operators: ++ prefix and postfix increment operators. These operators should modify the DayOfYear object so that it represents the next day. If the day is already the end of the year, the new value of the object will represent the first day of the year. prefix and postfix decrement operators. These operators should modify the DayOfYear object so that it represents the previous day. If the day is already the first day of the year, the new value of the object will represent the last day of the year.
Expert Solution
steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education