Exercise 1 50 points Contracts and other legal documents are
Solution
Please follow the code and comments for description :
CODE :
#include <iostream>
 #include <cstring>
 #include <fstream>
 #include <sstream>
using namespace std;
int main() { // driver method with the throws expected clauses
   
    int l, y, d, m; // required initialisations
    string dd, mm, yy;
int maximumDays[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //array of dates that stores the maximum days of every month
   string monthsNames[] = {\"\", \"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\",
        \"September\", \"October\", \"November\", \"December\"}; //array storing the month names
   cout << \"Enter any Date in (mm/dd/yyyy) format : \"; // prompt to enter the date to the user
    string inDate = \" \"; //getting the date in String format
    cin >> inDate;
l = inDate.length(); //finding the number of digits in the given input
   if (l == 10) //performing the task only when number of digits is 10
    {
        mm = inDate.substr(0, 2); //getting the day in String format
        dd = inDate.substr(3, 5); //getting the monthsNames in String format
        yy = inDate.substr(6); //getting the year in String format
        d = atoi(dd.c_str()); //converting the day to Integer format
        m = atoi(mm.c_str()); //converting the month to Integer format
        y = atoi(yy.c_str()); //converting the year to Integer format
       if ((y % 400 == 0) || ((y % 100 != 0) && (y % 4 == 0))) // checking the condition for leap year
        {
            maximumDays[2] = 29;
        }
       if (m < 0 || m > 12) { // Performing the Date Validation
            cout << \"Invalid Date Entered.\" << endl;
            cout << \"Month must be in between 1 and 12 Inclusive.\" << endl;
        } else if (d < 0 || d > maximumDays[m]) {
            cout << \"Invalid Date Entered.\" << endl;
            cout << \"Day is Not Valid.\" << endl;
        } else if (y < 0 || y > 9999) {
            cout << \"Invalid Date Entered.\" << endl;
            cout << \"Year is not Valid.\" << endl;
        } else {
            if ((dd == \"01\") || (dd == \"1\") || (dd == \"21\") || (dd == \"31\")) { // checking for the date to get the formatted output based on the day
                cout << \"Dated this \" << dd << \"st day of \" << monthsNames[m] << \", \" << yy << \".\";
            } else if ((dd == \"02\") || (dd == \"2\") || (dd == \"22\")) {
                cout << \"Dated this \" << dd << \"nd day of \" << monthsNames[m] << \", \" << yy << \".\";
            } else if ((dd == \"03\") || (dd == \"3\") || (dd == \"23\")) {
                cout << \"Dated this \" << dd << \"rd day of \" << monthsNames[m] << \", \" << yy << \".\";
            } else {
                cout << \"Dated this \" << dd << \"th day of \" << monthsNames[m] << \", \" << yy << \".\";
            }
        }
        cout << endl;
    } else {
        cout << \"Wrong Input.\";
    }
 }
OUTPUT :
1)
Enter any Date in (mm/dd/yyyy) format : 06/30/1959
 Dated this 30th day of June, 1959.
2)
Enter any Date in (mm/dd/yyyy) format : 09/31/2016
 Invalid Date Entered.
 Day is Not Valid.
3)
Enter any Date in (mm/dd/yyyy) format : 13/07/1994
 Invalid Date Entered.
 Month must be in between 1 and 12 Inclusive.
 Hope this is helpful.


