Define a class Clock with three private integer data members hour, min and sec. Define a no
argument constructor to initialize time value to 12:00:00. Define a three argument
constructor to initialize the time.
Define a methods to
a. Increment time to next second.
b. Display the time value.
c. Return the hour (int getHour())
d. Return the minute (int getMinute())
e. Return the seconds (int getSeconds())
Expected output:
Time is:= 22:55:58
New Time is:= 22:55:59
Hour:= 22
Minute:= 55
Seconds:= 59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace tutorial3
{
class Clock
{
private int hour, min, sec;
public Clock()
{
this.hour = 22;
this.min = 55;
this.sec = 58;
}
public Clock(int h, int m, int s)
{
this.hour = h;
this.min = m;
this.sec = s;
}
public void inc()
{
sec++;
Console.WriteLine("New time is " + hour + ":" + min + ":" + sec);
}
public void display()
{
Console.WriteLine("time is "+hour+":"+min+":"+sec);
}
public int gethour()
{
return hour;
}
public int getmin()
{
return min;
}
public int getsec()
{
return sec;
}
}
}
Output:-
No comments:
Post a Comment