Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FIX THE ERRORS OUTPUT: 3/15/16 March 15, 2016 15 March 2016 // This is a program to print dates in diffent formats. #include #include using

FIX THE ERRORS

OUTPUT:

3/15/16

March 15, 2016

15 March 2016

// This is a program to print dates in diffent formats.

#include

#include

using namespace std;

// Creating a namespace for an array month and day

namespace day_mon

{

//Month Array

string month_list[12] = {"January","February","March","April","May","June","July","August","September","October","November","December"};

//Days array for number of days in the month

int days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,};

}

//Declare the class

class Date

{

//Declare priate

private:

int day, month, year;

//Declare public

public:

//Defualt date constructor initializing the default vales for date, month and year

Date()

{

//Month should be less than 12 and greater than 1 amd less than days in corresponding month

if ((month >= 1 && month <= 12) && (day <= day_mon::days_in_month[month - 1]))

{ //If valid date passed than set values

this -> day = 1;

this -> month = 1;

this -> year = 2001;

}

}

//Print date in format: month/day/last two numbers of year

string format_1()

{

return to_string(month) + "/"

+""+ to_string(day) + "/"

+ to_string(year).substr(2);

}

//Print date in format: month name day, year

string format_2()

{

return day_mon::month_list[month -1]

+" "+ to_string(day)

+", "+ to_string(year);

}

//Print date in format: day month name yeat

string format_3()

{

return to_string(day) + " "

+ day_mon::month_list[month -1]

+ " "+ to_string(year);

}

};

//Class end here

//Main

int main(void) {

//Creating variable for stroring day, month and year

unsigned int day, month, year;

cout << "Enter the day:\t";

cin >> day;

cout << "Enter the month:\t";

cin >> month;

cout << "Enter the year: \t";

cin >> year;

// Creating defualt object having defualt value for day, month, year

Date d(day, month, year);

//Display date in three formates

cout << d.format_1() << endl;

cout << d.format_2() << endl;

cout << d.format_3() << endl;

cout << endl;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions