Question
C++ : Create the program that converts month in number to string month Implement the ostream function The example output: Enter the date (MM-DD): 02-01
C++ :
Create the program that converts month in number to string month
Implement the ostream function
The example output:
Enter the date (MM-DD): 02-01
02-01 = Feb. 1
-------------------------Date.h--------------------
#ifndef DATE_H
#define DATE_H
#include
#include
using namespace std;
class Date {
private:
unsigned month_, day_;
static const string MONTHS[12];
public:
//constructors
Date();
//Overloaded operators
friend ostream& operator<<(ostream&, const Date&);
friend istream& operator>>(istream&, Date&);
};
#endif
----------------------date.cpp-------------
#include
#include "Date.h"
using namespace std;
const string Date::MONTHS[12] = {"Jan.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."};
Date::Date() : month_(1), day_(1) {
}
istream& operator>>(istream& input, Date& a)
{
unsigned month_, day_;
input >> month_;
input.ignore();
input >> day_;
return input;
}
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