Question: Description (Need to work with c++ Thank you) The purpose of this challenge is to use arrays and functions. This challenge calculates the day of

Description (Need to work with c++ Thank you)

The purpose of this challenge is to use arrays and functions. This challenge calculates the day of the year given the nth day of the year.

Requirements

  1. Write a function string get_date(int day) that will return a string indicating the month and day of the year based on an integer input. For this function to return a string that is a combination of a month (a string) and a day (an integer), you will have to use the to_string() function
     string get_date(int day) { // month will represent an index into the months array // day_of_month will represent the resulting day // within the calculated month int day_of_month, month; // more code here // to use to_string(), see the compiler requirements below  // to_string() is a library function  // you do not need to create it return months[month] + " " + to_string(day_of_month); } 
  2. In the function, declare a string array as below
     string months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 
  3. In the function, declare an int array as below
     int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 
  4. In main, ask the user to enter an integer between 1 and 365
  5. Display to the user the month and day by calling the get_date() function. (See interaction)

Compiler Requirements

 When compiling your code having used the to_string() function, you may have to compile as below (don't type the dollar sign): $ g++ -std=c++11 yourfile.cpp 

Hints

Your get_date() function can be written-at minimum-with two accumulators, a while loop and a subtraction or two.

DO NOT USE

Any built-in date/time functions

Sample Interaction / Output

 Enter the nth day of the year: 5 Day 5 is Jan 5 [run it again] Enter the nth day of the year: 59 Day 59 is Feb 28 [run it again] Enter the nth day of the year: 365 Day 365 is Dec 31 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!