Help with Implementing a class please


I need to write an application, which reads two times and finds out which time is later.

After that it calculates the time difference between these times and displays the
smaller (earlier) time and the time difference (duration)


I wrote most of the code below but still not working. Can I get some remarks of my errors please?


CODE:


#pragma once

#include <iostream>
#include <iomanip>

using namespace std;

class Time {
public:
Time diff(Time t2);
Time read(Time hrs, mins);
Time lessThan(Time time1, time2);
Time subtract(Time time1, time2);
Time display(Time duration);

private:
int hrs;
int mins;
};

bool Time::lessThan(const Time& num) const
{
return (hrs * 60) + mins < (num.hrs * 60) + num.mins;
}

void main()
{
Time time1, time2, difference;
difference = time1.diff(time2);


time1.read("Enter time 1");
time2.read("Enter time 2");

if (time1.lessThan(time2)) {
cout << "first is less" << endl;
duration = time2.subtract(time1);
cout << "Starting time was ";
time1.display();
}

else {
cout << "second is less" << endl;
duration = time1.subtract(time2);
cout << "Starting time was ";
time2.display();
}

cout << "Duration was ";

duration.display();

return 0;
}

time1.read("Enter time 1");

What parameters does the function Time read(Time hrs, mins); accept? Those two parameters right there, what are they? Do they match the single parameter you;'re trying to use, "Enter time 1" ?

Put another one, is the parameter "Enter time 1" two parameters, the first begin a Time and the second being... well, nothing, what is mins? Your code just makes no sense.
Last edited on
Topic archived. No new replies allowed.