subject
Engineering, 14.03.2020 05:18 myg21

Needs to be written in C++

Assuming that a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string for output consisting of the month followed by day of the month. For example:

day 2 would be "January 2".
day 32 would be "February 1".
day 365 would be "December 31".

The class should have:

a constructor for the class which takes as a parameter an integer representing the day number of the year
an private integer member variable to store the parameter
a "getter" to return the value of the member variable
member function which overloads the stream extraction operator to print the day in month-day format.
static constants which will assist in the conversion from an integer to a month-day format, for example, a collection of month names and days in each month.
The DayOfYear class described above should have a second constructor that takes two parameters: a string representing a month name and an integer in the range 1 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 month name entered is invalid or if the number entered for a day is outside the range of days for the month given.

Add the following overloaded 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, then the new value of the object will represent the first day of the year.

prefix and posfix –– (decrement) operators. These operators should modify the DayOfYear object so that it represent the previous day. If the day is already the first day of the year, then the new value of the object will represent the last day of the year.

Demonstrate the class by writing a main program which shows the appropriate month-day dates for days numbered 15, 31, 59, 180, and 360.

Also in main, demonstrate the second constructor by displaying the appropriate day number for "January 1", "March 4", "July 27", and "December 31".

Demonstrate how the prefix –– operator works on the first date (January 1) and the prefix ++ operator works on the second date (March 4) above. To do this, using a single cout statement, show the original value of the object (in month-day format), the object using the prefix++ or –– operator, and the final value of the object on three separate lines. For example, to demonstrate the prefix –– on day 1, the output might look like:

Using day 1:
The original value: January 1
Using prefix–– : December 31
After prefix–– : December 31
Also demonstrate how the postfix version of the –– and ++ operators work by doing the same thing on the third (July 27) and fourth (December 31) dates above, respectively.

Finally demonstrate what happens when an invalid month/day combination (such as February 30) is entered using the second constructor.

ansver
Answers: 1

Other questions on the subject: Engineering

image
Engineering, 04.07.2019 18:10, skpdancer1605
Ariver flows from north to south at 8 km/h. a boat is to cross this river from west to east at a speed of 20 km/h (speed of the boat with respect to the earth/ground). at what angle (in degrees) must the boat be pointed upstream such that it will proceed directly across the river (hint: find the speed of the boat with respect to water/river)? a 288 b. 21.8 c. 326 d. 30.2
Answers: 3
image
Engineering, 04.07.2019 19:10, justkevin1231
Which of the following is the most important advantage of a large field of view? a. allows larger areas to be examined b. relieves eyestrain c. minimizes parallax errors. d. increases precision in proportion to the in- crease in field of view
Answers: 2
image
Engineering, 06.07.2019 03:10, lacourboud20005
An electrical kettle is made out of stainless steel, weighs two pounds (when empty) with a heating element that consumes 2 kw of electricity. assuming that the water and the kettle are at the same uniform temperature at any moment of time, calculate the shortest possible time to bring 2 quarts of water from room temperature to the onset of boiling.
Answers: 1
image
Engineering, 06.07.2019 03:20, dinapearce1403
Write a technical essay (maximum two pages) about stress concentration. and paste from the textbook. instead, read updated material about this phenomenon and provide a technical evaluation of the different techniques to avoid/reduce such phenomenon. consider in your analysis cutting-edge computational techniques such as fea to study and analyze stress concentrations.
Answers: 2
You know the right answer?
Needs to be written in C++

Assuming that a year has 365 days, write a class named DayOfY...

Questions in other subjects:

Konu
Mathematics, 22.04.2020 19:59