Lecture notes using the given member functions and UML struc


Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of
Please modify the class Date.
1. Multiple output the date in the following format: DDD YYY
MM / DD / YY June 14, 1992
2. Use the date format of the above, use the overloaded constructor to create and initialize a Date object.
3. Use the standard library functions in <ctime> header Data Write a constructor that reads the system date and set the Data member. Information about the function of the header <ctime>, please refer to the reference document or www.cplusplus.com/ref/ctime/index.html of the compiler.
Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of
Please modify the class Date.
1. Multiple output the date in the following format: DDD YYY
MM / DD / YY June 14, 1992
2. Use the date format of the above, use the overloaded constructor to create and initialize a Date object.
3. Use the standard library functions in <ctime> header Data Write a constructor that reads the system date and set the Data member. Information about the function of the header <ctime>, please refer to the reference document or www.cplusplus.com/ref/ctime/index.html of the compiler.


Please anyone help me to give me all of the codes in this program \'\'C++\'\'

Thanks
1 // Fig. 10.10: Date.h 2 // Date class definition; Member functions defined in Date.cpp 3 #ifndef DATEH 4 #define DATE-H 5 6 class Date - 8 public: Date( int = 1, int = 1, int = 1900 ); // default constructor 10 void printO const; // print date in month/day/year format 11 Date O; // provided to confirm destruction order 12 private: 13 int month; // 1-12 (January-December) 14 int day; // 1-31 based on month 15 int year; // any year 16 17 II utility function to check if day is proper for month and year 18 int checkDay int const; 19 // end class Date 20 21 #endif 19 i 11 end class Date

Solution

//Date.h

#ifndef DateFormat
#define DateFormat
#include <string>
using std::string;

class Date {

   public:
   // constructor
   Date();
   // parameterized consturctors
   Date( int, int );
   Date( int, int, int );
   Date( string, int, int );
   // setters
   void setDay11(int);
   void setMonth11( int );
   // print functions
   void print11() const;
   void printDDDYYYY11( ) const;
   void printMMDDYY11( ) const;
   void printMonthDDYYYY11( ) const;
   ~Date();

   private:
   // variables
   int month1;
   int day1;
   int year1;
   // check valid day
   int checkDay(int)const;
   // count days in month
   int daysInMonth(int)const;
   // check leap year
   bool isLeapYear()const;
   // converter function
   int convertDDToDDD()const;
   // setter
   void setMMDDFromDDD(int);
   // converter function
   string convertMMToMonth(int)const;
   // setter
   void setMMFromMonth(string);
   // converter function
   int convertYYYYToYY()const;
   // setter
   void setYYYYFromYY(int);

};

#endif

//Date.cpp

// input output library
#include <iostream>
using std::cout;
using std::endl;
// library to set width and fill
#include <iomanip>
using std::setw;
using std::setfill;
// library to use time
#include <ctime>
using std::time;
using std::localtime;
using std::tm;
using std::time_t;
#include \"Date.h\"

// default constructor
Date::Date()
{
    // taking pointer to tm
    struct tm *ptr;
    // set time as 0
    time_t t1 = time( 0 );
    // pointer taking address of t1
    ptr = localtime( &t1 );
    // day1 holds the day value of ptr
    day1 = ptr->tm_mday;
    // month1 holds the month value of ptr
    month1 = 1 + ptr->tm_mon;
    // year1 holds the year value of ptr + 1900
    year1 = ptr->tm_year + 1900;

}

// parameterized constructor
Date::Date( int ddd1, int yyyy1 )
{
    // set year
    year1=yyyy1;
    // call the month from date function
    setMMDDFromDDD(ddd1);
}

// parameterized constructor
Date::Date( int mm1, int dd1, int yy1 )
{
// call the year from year function
setYYYYFromYY( yy1 );
// set day function
setDay11( dd1 );
}

// parameterized constructor
Date::Date(string monthName2,int dd1,int yyyy1)
{
// call the month from month function
setMMFromMonth(monthName2);
// setday
setDay11(dd1);
year1=yyyy1;
}

void Date::setDay11( int d1 )
{
    // check for valid day and set it
    day1 = checkDay(d1);
}

void Date::setMonth11( int m1 )
{
    // check for valid month and set it
    if(m1>0&& m1<=12)
        month1=m1;
    else
    {
        // end set month to 1
        month1=1;
        cout<<\"invalid month(\"<<m1<<\")set to 1\ \";
    }

}

// print function
void Date::print11()const
{
    cout<<month1<<\"/\"<<day1<<\'/\'<<year1<<endl;
}
void Date::printDDDYYYY11()const
{
    cout<<convertDDToDDD()<<\' \'<<year1<<endl;
}

void Date::printMMDDYY11()const
{
    // print in specific format, 2 width, fill 0
    cout<<setw(2)<<setfill(\'0\')<<month1<<\'/\'<<setw(2)<<setfill(\'0\')<<day1<<setw(2)<<setfill(\'0\')<<convertYYYYToYY()<<endl;
}

void Date::printMonthDDYYYY11()const
{
    cout<<convertMMToMonth(month1)<<\' \'<<day1<<\",\"<<year1<<endl;
}

// date destructor
Date::~Date()
{
    cout<<\"date object destructor for date\";
    print11();
    cout<<endl;
}

// check if day is valid
int Date::checkDay(int testDay)const
{
    if(testDay>0 && testDay<=daysInMonth(month1))
        return testDay;
    if(month1==2 && testDay==29 && isLeapYear())
        return testDay;
    cout<<\"invalid day(\"<<testDay<<\")set to 1\ \";
    return 1;

}

// count and return number of days in month
int Date::daysInMonth( int m ) const
{
    if(isLeapYear()&&m==2)
    return 29;
    static const int daysPerMonth1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    return daysPerMonth1[m];

}

// check for leap year
bool Date::isLeapYear()const
{

    if ( year1 % 400 == 0 || ( year1 % 4 == 0 && year1 % 100 != 0 ) )
        return true;
    else
        return false;
}

// date converter function
int Date::convertDDToDDD() const
{

    int ddd1 = 0;
    for(int i=1;i<month1;i++)
    ddd1+=daysInMonth(i);
    ddd1+=day1;
    return ddd1;

}

// setting month day from day
void Date::setMMDDFromDDD(int ddd1)
{
    int dayTotal1=0;
    int m;
    // iterate months and check if total days plus month days is less than ddd1
    for(m=1;m<=2&&(dayTotal1+daysInMonth(m))<ddd1;m++)
    dayTotal1+=daysInMonth(m);
    // set month
    setMonth11(m);
    // set day
    setDay11(ddd1-dayTotal1);
}

// convert given month number to corresponding month name
string Date::convertMMToMonth(int mm)const
{
    static const string months1[]={\" \",\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"december\"};
    return months1[mm];

}

// set month function
void Date::setMMFromMonth(string m1)
{

    bool matchFound=false;
    // check for month match
    for(int k=1;k<=12&&!matchFound;k++)
    {
    string tempMonth1=convertMMToMonth(k);
    if(tempMonth1==m1)
    {
        // set month if match is found
    setMonth11(k);
    matchFound=true;
    }
    }
    // else set month to 1
    if(!matchFound)
    {
    cout<<\"invalid month name(\"<<month1<<\")month set to 1\ \";
    setMonth11(1);
    }

}

// year converter
int Date::convertYYYYToYY()const
{
    return (year1>=2000?year1-2000:year1-1900);
}

// other yer converter function
void Date::setYYYYFromYY(int yy)
{
    year1=(yy<7?yy+2000:yy+1900);
}


//Main.cpp

// input output library
#include <iostream>
using std::cout;
using std::endl;
#include \"Date.h\"

int main()
{
// calling parameterized constructors
Date date1( 252,1999 );
Date date2( 2,25,04 );
Date date3( \"September\", 1, 2000 );

// print dates
Date date4;
date1.print11();
date2.print11();
date3.print11();
date4.print11();

// print date to years
cout << \'\ \';
date1.printDDDYYYY11();
date2.printDDDYYYY11();
date3.printDDDYYYY11();
date4.printDDDYYYY11();

// print month to date to years
cout << \'\ \';
date1.printMMDDYY11();
date2.printMMDDYY11();
date3.printMMDDYY11();
date4.printMMDDYY11();

// print final dates
cout << endl;
date1.printMonthDDYYYY11();
date2.printMonthDDYYYY11();
date3.printMonthDDYYYY11();
date4.printMonthDDYYYY11();

return 0;

}


/*
output:

invalid day(193)set to 1
3/1/1999
3/25/2004
9/1/2000
10/11/2016

60 1999
85 2004
245 2000
285 2016

03/0199
03/2504
09/0100
10/1116

March 1,1999
March 25,2004
September 1,2000
October 11,2016
date object destructor for date10/11/2016

date object destructor for date9/1/2000

date object destructor for date3/25/2004

date object destructor for date3/1/1999

*/

 Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of Please modify the class Date. 1. Mul
 Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of Please modify the class Date. 1. Mul
 Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of Please modify the class Date. 1. Mul
 Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of Please modify the class Date. 1. Mul
 Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of Please modify the class Date. 1. Mul
 Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of Please modify the class Date. 1. Mul
 Lecture notes using the given member functions and UML structure to include the following capabilities: p7 (Fig. 10.10) of Please modify the class Date. 1. Mul

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site