Tuesday 4 October 2016

C++ OOP write a program to input a date print on the screen by using class

Code:-


#include<iostream>
#include<conio.h>
using namespace std;

class Time{
private:
int hour;
int minute;
int seconds;
public:
int flag = 0;

void get_Time(){
if (flag == 0)
{
cout << "Enter time Please _:_:_";
flag = 1;
}
if (flag == 1)
{
cin >> hour;
if (hour < 24)
{
flag = 2;
cout << "hours is finished";
}
else
{
flag = 1;
get_Time();
}
}
if (flag == 2)
{
cin >> minute;
if (minute <= 60)
{
flag = 3;

cout << "minute is finished";
}
else
{
flag = 2;
get_Time();
}
}
if (flag == 3)
{
cin >> seconds;
if (seconds <= 60)
{
flag = 4;

cout << "seconds is finished";
}
else
{
flag = 3;
get_Time();
}
}
}

void set_Time(){
cout << "Time is " << hour << ":" << minute << ":" << seconds;
}
};

void main()
{
Time tC;
tC.get_Time();
tC.set_Time();

_getch();
}


output:-