| cairo |
Jul 4th, 2007 11:49 AM |
errr.. im sorry.. i re-post again, i must be out of my mind -_-!
clockType.h is the member access specifiers i state just now
:
class clockType
{
public:
void setTime(int hours, int minutes, int seconds);
//Function to set the time.
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds
// The function checks whether the values of
// hours, minutes, and seconds are valid. If a
// value is invalid, the default value 0 is
// assigned.
void getTime(int& hours, int& minutes, int& seconds) const;
//Function to return the time.
//Postcondition: hours = hr; minutes = min;
// seconds = sec
void printTime() const;
//Function to print the time.
//Postcondition: The time is printed in the form
// hh:mm:ss.
void incrementSeconds();
//Function to increment the time by one second.
//Postcondition: The time is incremented by one
// second.
// If the before-increment time is 23:59:59, the
// time is reset to 00:00:00.
void incrementMinutes();
//Function to increment the time by one minute.
//Postcondition: The time is incremented by one
// minute.
// If the before-increment time is 23:59:53,
// the time is reset to 00:00:53.
void incrementHours();
//Function to increment the time by one hour.
//Postcondition: The time is incremented by one
// hour.
// If the before-increment time is 23:45:53, the
// time is reset to 00:45:53.
bool equalTime(const clockType& otherClock) const;
//Function to compare the two times.
//Postcondition: Returns true if this time is
// equal to otherClock; otherwise,
// returns false.
clockType(int hours, int minutes, int seconds);
//constructor with parameters
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds
// The constructor checks whether the values of
// hours, minutes, and seconds are valid. If a
// value is invalid, the default value 0 is
// assigned.
clockType();
//default constructor with parameters
//The time is set to 00:00:00.
//Postcondition: hr = 0; min = 0; sec = 0
private:
int hr; //variable to store the hours
int min; //variable to store the minutes
int sec; //variable to store the seconds
};
clockTypeImp.cpp is the methods i mean just now
:
//Implementation File for the class clockType
#include <iostream>
#include "clockType.h"
using namespace std;
void clockType::setTime(int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
void clockType::getTime(int& hours, int& minutes, int& seconds) const
{
hours = hr;
minutes = min;
seconds = sec;
}
void clockType::incrementHours()
{
hr++;
if(hr > 23)
hr = 0;
}
void clockType::incrementMinutes()
{
min++;
if (min > 59)
{
min = 0;
incrementHours();
}
}
void clockType::incrementSeconds()
{
sec++;
if (sec > 59)
{
sec = 0;
incrementMinutes();
}
}
void clockType::printTime() const
{
if (hr < 10)
cout << "0";
cout << hr << ":";
if (min < 10)
cout << "0";
cout << min << ":";
if (sec < 10)
cout << "0";
cout << sec;
}
bool clockType::equalTime(const clockType& otherClock) const
{
return (hr == otherClock.hr
&& min == otherClock.min
&& sec == otherClock.sec);
}
clockType::clockType(int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
clockType::clockType() //default constructor
{
hr = 0;
min = 0;
sec = 0;
}
testClockClass.cpp is the main program
:
//The user program that uses the class clockType
#include <iostream>
#include "clockType.h"
using namespace std;
int main()
{
clockType myClock;
clockType yourClock;
int hours;
int minutes;
int seconds;
//set the time of myClock
myClock.setTime(5, 4, 30); //Line 1
cout << "Line 2: myClock: "; //Line 2
myClock.printTime(); //print the time of myClock //Line 3
cout << endl; //Line 4
cout << "Line 5: yourClock: "; //Line 5
yourClock.printTime(); //print the time of yourClock Line 6
cout << endl; //Line 7
//set the time of yourClock
yourClock.setTime(5, 45, 16); //Line 8
cout << "Line 9: After setting, yourClock: "; //Line 9
yourClock.printTime(); //print the time of yourClock Line 10
cout << endl; //Line 11
//compare myClock and yourClock
if (myClock.equalTime(yourClock)) //Line 12
cout << "Line 13: Both times are equal."
<< endl; //Line 13
else //Line 14
cout << "Line 15: The two times are not equal."
<< endl; //Line 15
cout << "Line 16: Enter the hours, minutes, and "
<< "seconds: "; //Line 16
cin >> hours >> minutes >> seconds; //Line 17
cout << endl; //Line 18
//set the time of myClock using the value of the
//variables hours, minutes, and seconds
myClock.setTime(hours, minutes, seconds); //Line 19
cout << "Line 20: New myClock: "; //Line 20
myClock.printTime(); //print the time of myClock //Line 21
cout << endl; //Line 22
//increment the time of myClock by one second
myClock.incrementSeconds(); //Line 23
cout << "Line 24: After incrementing myClock by "
<< "one second, myClock: "; //Line 24
myClock.printTime(); //print the time of myClock //Line 25
cout << endl; //Line 26
//retrieve the hours, minutes, and seconds of the
//object myClock
myClock.getTime(hours, minutes, seconds); //Line 27
//output the value of hours, minutes, and seconds
cout << "Line 28: hours = " << hours
<< ", minutes = " << minutes
<< ", seconds = " << seconds << endl; //Line 28
system("pause");
return 0;
}//end main
i take these three files to compile just now by using Dev c++, it didn't work and gave me error
Quote:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Documents and Settings\Compaq_Owner\My Documents\SIT\6044-6\Chapter 11\Source Code\Ch11_ClassClock\testClockClass.cpp" -o "C:\Documents and Settings\Compaq_Owner\My Documents\SIT\6044-6\Chapter 11\Source Code\Ch11_ClassClock\testClockClass.exe" -ansi -pedantic -Wall -fexceptions -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x131): In function `main':
C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:10: undefined reference to `clockType::clockType()'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x13c):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:11: undefined reference to `clockType::clockType()'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x15f):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:18: undefined reference to `clockType::setTime(int, int, int)'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x17e):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:21: undefined reference to `clockType::printTime() const'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x1b1):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:25: undefined reference to `clockType::printTime() const'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x1e8):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:29: undefined reference to `clockType::setTime(int, int, int)'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x207):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:32: undefined reference to `clockType::printTime() const'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x22d):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:36: undefined reference to `clockType::equalTime(clockType const&) const'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x308):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:50: undefined reference to `clockType::setTime(int, int, int)'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x327):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:53: undefined reference to `clockType::printTime() const'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x346):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:57: undefined reference to `clockType::incrementSeconds()'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x375):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:61: undefined reference to `clockType::printTime() const'
C:\DOCUME~1\COMPAQ~1\LOCALS~1\Temp/ccaOcaaa.o(.text+0x3a9):C:/Documents and Settings/Compaq_Owner/My Documents/SIT/6044-6/Chapter 11/Source Code/Ch11_ClassClock/testClockClass.cpp:66: undefined reference to `clockType::getTime(int&, int&, int&) const'
collect2: ld returned 1 exit status
Execution terminated
|
i try again by putting the all the methods of this program which is clockTypeImp.cpp inside tester file which is testClockClass.cpp and its work
|