Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Requirements 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.
Requirements
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) { // 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); }
In the function, declare a string array as below
string months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
In the function, declare an int array as below
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
In main, ask the user to enter an integer between 1 and 365
Display to the user the month and day by calling the get_date() function. (See interaction)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started