Я работаю над проектом, класс которого (Time) определен в заголовочном файле, и цель состоит в том, чтобы использовать этот класс в моей основной функции, чтобы определить разницу между двумя значениями. Я рассмотрел этот класс и все же не могу понять, как использовать класс, определенный для меня, и использовать его функции доступа в main.
Я опубликую заголовок и то, что я сделал до сих пор, и, надеюсь, кто-то сможет прояснить, что мне нужно сделать, потому что я понимаю цель и что мне нужно сделать для ее достижения, но я просто не могу перевести это в пригодный для использования код ... Надеюсь, кто-то может выразить это в терминах, понятных начинающему программисту, как я, лучше, чем мой учитель и мой текст.
Заголовок:
#ifndef CCC_TIME_H
#define CCC_TIME_H
/**
A class that describes a time of day
(between 00:00:00 and 23:59:59)
*/
class Time
{
public:
/**
Constructs a time of day.
@param hour the hours
@param min the minutes
@param sec the seconds
*/
Time(int hour, int min, int sec);
/**
Constructs a Time object that is set to
the time at which the constructor executes.
*/
Time();
/**
Gets the hours of this time.
@return the hours
*/
int get_hours() const;
/**
Gets the minutes of this time.
@return the minutes
*/
int get_minutes() const;
/**
Gets the seconds of this time.
@return the seconds
*/
int get_seconds() const;
/**
Computes the seconds between this time and another.
@param t the other time
@return the number of seconds between this time and t
*/
int seconds_from(Time t) const;
/**
Adds a number of seconds to this time.
@param s the number of seconds to add
*/
void add_seconds(int s);
private:
int time_in_secs;
};
#endif
___________________
using namespace std;
int main()
{
int t;
string x;
cout<< "This program will test your typing speed."<< endl;
cout<< "Type the following:"<<endl;
cout<<" "<<endl;
cout<< "The quick brown fox jumped over the lazy dog"<< endl;
Time startTime;
getline(cin, x, '\n');
if(x == "The quick brown fox jumped over the lazy dog")
{
Time endTime;
int durationInSeconds = endTime.seconds_from(startTime);
t = durationInSeconds;
}
else{cout<<"Invalid text entered";}
cout<<"You finished in: " << t << "seconds." endl;
system ("pause");
return 0;
}