Alright. Here is the mostly completed assignment, with much help from a tutor and a little help from you guys.
CTime.cpp:
Code:
/******************************
* FILE: CTime.cpp
* PROGRAMMER: Stephen Croy
* DATE: 01-14-09
*
* Implementation of class CTime.
*******************************/
#include "CTime.h"
using namespace std;
CTime CTime::add(CTime t2)
{
//Declarations
long t1Seconds;
long t2Seconds;
long t3Seconds;
CTime answer;
//Conversion of hours and minutes into seconds
t1Seconds = ((long)hours)*3600 + minutes*60 + seconds;
t2Seconds = ((long)t2.hours)*3600 + t2.minutes*60 + t2.seconds;
t3Seconds = t1Seconds + t2Seconds;
//Conversion of seconds back to hours and minutes
answer.hours = t3Seconds / 3600;
answer.minutes = t3Seconds % 3600 / 60;
answer.seconds = t3Seconds % 3600 % 60;
return answer;
}
CTime.h :
Code:
/******************************
* FILE: CTime.h
* PROGRAMMER: Stephen Croy
* DATE: 01/14/09
*
* Declaration of class CTime.
*******************************/
#ifndef CTime_H
#define CTime_H
#include <iostream>
class CTime
{
public:
CTime();
~CTime() {}
int getHours();
int getMinutes();
int getSeconds();
CTime add(CTime);
void setHours(int);
void setMinutes(int);
void setSeconds(int);
private:
int hours;
int minutes;
int seconds;
};
inline CTime::CTime()
{
hours = 0;
minutes = 0;
seconds = 0;
}
inline int CTime::getHours()
{ return hours; }
inline int CTime::getMinutes()
{ return minutes; }
inline int CTime::getSeconds()
{ return seconds; }
inline void CTime::setHours(int hr)
{ hours = hr; }
inline void CTime::setMinutes(int min)
{ minutes = min; }
inline void CTime::setSeconds(int sec)
{ seconds = sec; }
#endif
and TimeApp.cpp :
Code:
#include <cstdlib>
#include <iostream>
#include "CTime.h"
using namespace std;
int main(int argc, char *argv[])
{
char colon;
int hrs;
int mins;
int secs;
CTime firstT;
CTime secondT;
CTime answerT;
cout << "Enter the first time in the format of HH:MM:SS\n\n";
cin >> hrs >> colon >> mins >> colon >> secs;
firstT.setHours(hrs);
firstT.setMinutes(mins);
firstT.setSeconds(secs);
cout << "Enter the second time in the same format\n\n";
cin >> hrs >> colon >> mins >> colon >> secs;
secondT.setHours(hrs);
secondT.setMinutes(mins);
secondT.setSeconds(secs);
answerT = firstT.add(secondT);
cout << answerT.getHours();
cout << answerT.getMinutes();
cout << answerT.getSeconds();
system("PAUSE");
return EXIT_SUCCESS;
}
Now there is a problem when I go to compile. I get this error 4 times in a row with no reference to the line number:
[Linker error] undefined reference to `CTime::CTime()'
Thank you again for all the help guys.