Code Monkey home page Code Monkey logo

date_class's Introduction

Class "Date"

Implementation of the class with multiple constructors and a destructor. Implementation of the specified list of overloaded operations for the class.

TAGS: C++, OOP

The implemented class "Date" is designed to represent dates.

The following constructors are defined in the class:

  • default
  • by year
  • by year and month
  • by full date
  • copy constructor

The date is registered by default as a static member of the class.

Functions-modifiers for changing the date by an integer amount are implemented:

  • change year
  • change month
  • change days

The following operators are overloaded:

  • "=" // Assignment
  • "+=" (Date & d, int n) // add n days
  • "-=" (Date & d, int n) // subtract n days
  • "+" (Date & d, int n) // add n days
  • "-" (Date & d, int n) // subtract n days
  • increment / decrement
  • ==,! =,>, < // comparison operators
  • ">>", "<<" // (input/output using istream/ostream streams)

Constant member functions to query the year, month, day are prescribed

The developed Date class allows such use

int main()

{

    Date date1, date2(1995), date3(1995, Date::mar), date4(1995, Date::may,5);
    date1 = date2 + date3;    // doesn't work!
    
    Date tdate1,tdate2;
    tdate1 += 2;
    tdate2++; tdate2++;                      
    if (tdate1 != tdate2) cout << "Something wrong\n";
    else cout << "As expected\n";
    
    cout << date1 << endl << date2 << endl << date3 << endl  << date4 << endl;
    
    Date today = Date(2018, Date::sep, 10);
    Date tomorrow = today + 1;
    
    Date never = 43 + today;  // doesn't work!

return 0;

}

date_class's People

Contributors

ellkrauze avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.