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

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!