C++ program using two constructor to calculate minutes and seconds with hour as input from user

Write a class with name Time. Make a constructor which calculates the given time in minutes {if input time is 1hr, then the constructor should return 60minutes. }.
Make another constructor which calculates the time in seconds. { if the input time is 1hr, then the constructor should return 60*60=3600 seconds}.
Display the contents of both the constructors

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

class Time
{
public:
	Time(int);
	Time(float);
};

Time::Time(int b)
{
	cout << "Time in seconds: " << b*60*60 << "n";
}
Time::Time(float b)
{
	cout << "Time in Minutes: " << int(b*60) << "n";
}

void main()
{
	clrscr();
	int hr;
	cout << "Enter the time in Hours: ";
	cin >> hr;
	Time t1(hr);
	Time t2(float(hr));
	getch();
}

Output

Enter the time in Hours: 1

Time in seconds: 3600
Time in Minutes: 60

You may also like...

Leave a Reply

Your email address will not be published.

%d bloggers like this: