C++ class example program to display date: In this sample tutorial you can display day, month and year details. Syntax of the classes is so simple.
This program is to assign values to the data members of a class such as year, month and day. For example if you want to display the today’s date, it is possible by using this class program.
[SEE: C Program Tutorials] & [IT Companies Details]
How to Display Date?
It is so simple and easy to display date. Following C++ class program will tell you everything in detail. It has only one class namely “DisplayDate” and few methods for the further process. An access specifier used in this tutorial is PRIVATE. Some of the data members are there for the better C++ programming. An example CPP source code is given below.
C++ Class Program:
How to display date in C++ programming? Explain with an example code.
- Read: Learn English Quickly
- Worth Read: C++ Interview Questions
// Header files section #include<iostream.h> #include<conio.h> class DisplayDate { private: //Access specifiers int Dt; int Mn; int Yr; public: // Acess specifier void input(void) //Input method { cout<<"Give your INPUT values {dd-mm-yy}"<<"\n"; cin>>Dt>>Mn>>Yr; } void outputDisp(void) { cout<<"Date of Today is:"<<Dt<<"-"<<Mn<<"-"<<Yr<<"\n"; } }; void main(void) // Main method { class DisplayDate Today ; //Object creation Today.input(); Today.outputDisp(); }