I have a project that is getting hard for me to do. I've been told I've done the hardest part, but I'm just confused. We are making a program that adds 2 times together. The times are entered by the user. Here is what the assignment is and the code I've done so far.
************************************************** **************
DESCRIPTION
1.1
Write a program that uses a class.
1.2
Your project will contain files CTime.h, CTime.cpp and TimeApp.cpp.
1.2.1 (Class declaration)
* Place the class declaration and inline functions in a seperate header file, CTime.h.
* Class declaration:
declare CTime as a class
public:
declare a defualt constructor
define an inline destructor with an empty code body
declare getHours as a member function
declare getMinutes as a member function
declare getSeconds as a member function
declare setHours, setMinutes, setSeconds as a member function
declare add as a member function with CTime return and a CTime parameter
private:
declare hours, minutes and seconds as an integer
make the constructor, destructor, get- and set- functions inline.
1.2.2 (Implementation CTime.cpp)
* #include file CTime.h
* place the noninline member function add in a separate file, CTime.cpp
-convert the time values to total seconds before adding them
example:
CTime tm;
long t1Seconds;
t1Seconds = (long)tm.hours*3600 + tm.minutes*60 + tm.seconds;
-add the total seconds together:
t3Seconds = t1Seconds + t2Seconds;
-divide them back out to make the new time hours, minutes and seconds.
- store them in a class CTime variable before returning it.
1.2.3 (member function add)
Module add
Return: CTime
Paramaters: define t2 as a CTime
Data:
define t1Seconds, t2Seconds and t3Seconds as long integers
Processing:
convert hours, minutes and seconds to a long and assign to
t1Seconds
convert t2.hours, t2.minutes and t2.seconds toa long and assign to t2Seconds
SET t3Seconds to t1Seconds + t2Seconds
derive values from t3Seconds to assign to temp.hours, temp.minutes and temp.seconds
return temp
END add
1.2.4 (Application file TimApp.cpp)
this is where the prgoram asks the user for 2 times entered in this format:
12:59:59
the program adds the 2 times and displays the sum
Here's the code I've done:
CTime.h file:
Code:
/******************************
* FILE: CTime.h
* PROGRAMMER: (left blank for now, this is the internet after all)
* DATE: 01/14/09
*
* Declaration of class CTime.
*******************************/
#ifndef CTime_H
#define CTime_Hclass CTime
#include <iostream.h>
class CTime
{
public:
CTime();
~CTime() {}
int getHours();
int getMinutes();
int getSeconds();
int add();
void setHours();
void setMinutes();
void setSeconds();
private:
int hours;
int minutes;
int seconds;
};
inline int CTime::getHours()
{ return hours; }
inline int CTime::getMinutes()
{ return minutes; }
inline int CTime::getSeconds()
{ return seconds; }
inline int CTime::add(CTime)
{ return CTime }
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 here's CTime.cpp:
Code:
/******************************
* FILE: CTime.cpp
* PROGRAMMER:
* DATE: 01-14-09
*
* Implementation of class CTime.
*******************************/
#include "CTime.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int t1Seconds;
int t2Seconds;
int t3Seconds;
int CTime::time()
{
t1Seconds = (long)time.hours*3600 + time.minutes*60 + tm.seconds;
system("PAUSE");
return EXIT_SUCCESS;
}
Now, I really don't know what I'm doing, most of this work is from the notes we were given. I haven't started the application file, but I figure that's easy once the other 2 files are completed. I really just don't know where to go from here, any help would be appreciated.