Posted by : Waqas Javed Wednesday, 4 March 2015

Task-1:

Write a program to implement the Date class which has three data members: day, month and year. Provide two constructors, one which takes arguments and another one which does not (you may set values of data members to 0). Write getter and setter functions (input and show functions) for the class. Write a member function pastDate() which tell where the date is the past date or not.
In main program:
Create two objects using two difference constructors
Call setter and getter functions on those objects.

Call the pastDate() function.


#include<iostream>
#include<conio.h>

using namespace std;

class Date{
private: int day;
                                 int month;
                                 int year;

public:
                //constructors
                Date();
                Date(int, int, int);

                //member funcs
                void setDate(int, int, int);             //set date
                void getDate();                                                                 //print date
                void chkPast(int, int, int);                                                                             //chk date is past or not
};

Date::Date(){
                day = 0;
                month = 0;
                year = 0;
}

Date::Date(int x, int y, int z){
                day = x;
                month = y;
                year = z;
}

void Date::setDate(int x, int y, int z){
                day = x;
                month = y;
                year = z;
}

void Date::getDate(){
                cout << "dd-mm-yy" << endl;
                cout << day << "-" << month << "-" << year << endl;
}

void Date::chkPast(int x, int y, int z){
                if (z < year){
                                cout << x << "-" << y << "-" << z << " is a past date then ";
                }
                else if (z == year && y< month){
                                cout << x << "-" << y << "-" << z << " is a past date then ";
                }
                else if (z == year && month == y && x < day){
                                cout << x << "-" << y << "-" << z << " is a past date then ";
                }
                else if (z == year && month == y && x == day){
                                cout << x << "-" << y << "-" << z << " is a current date" << endl;
                }
                else {
                                cout << x << "-" << y << "-" << z << " is a future date" << endl;
                }
}

void main(){
                Date d1;
                Date d2(10, 12, 1996);

                cout << "Date-1 is:" << endl;
                d1.getDate();

                d1.chkPast(10, 12, 2000);

                cout << endl << endl << "Date-2 is:" << endl;
                d2.getDate();
                d2.chkPast(10, 11, 1994);

                _getch();

}

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Contact Us

Stay updated for more codes if we u want any code write us by commenting below or email us.
If you want to hire us for your semester project email us at above given email or call or message
Email: 14bscswjaved@seecs.edu.pk
Phone no: 0308-8109708

Popular Post

Powered by Blogger.

- Copyright © BSCS -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -