Hello, sorry for not being specific enough. Ill put the errors that it shows in. I don't really know how to use clockTypeImp.cpp. The assignment calls for us to use it, to use main.cpp (only for objects), and to use clockType.h.
here is my updated code:
for clockType.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
class clockType
{
public:
clockType(int h = 0, int m = 0, int s = 0);
void setTime(int h, int m, int s);
void getTime(int& h, int& m, int& s) const;
void printTime() const;
void incrementSeconds();
void incrementMinutes();
void incrementHours();
bool equalTime(const clockType&) const;
private:
int hr;
int min;
int sec;
};
| |
for clockTypeImp.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include "clockType.h"
#include <iostream>
#include <fstream>
clockType::clockType(int h, int m, int s){
hr = h;
min = m;
sec = s;
}
void clockType::setTime(int h, int m, int s){
hr = h;
min = m;
sec = s;
}
void clockType::printTime(){
cout << setw(2) << setfill('0') << hr << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << setfill('0') << sec << "\n"
}
bool clockType::equalTime(clockType second){
if(hr == second.hr && min == second.min && sec = second.sec){
return true;
}
else{
return false;
}
}
| |
for main.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include "clockType.h"
#include "clockTypeImp.cpp"
using namespace std;
int main() {
// Write your main here
clockType time1(5, 10, 15);
time1.print();
clockType time2;
time2.print();
time2.setTime(6, 39, 33);
time2.print();
}
| |
here are the errors I'm getting:
clockTypeImp.cpp:17:6: error: prototype for ‘void clockType::printTime()’ does not match any in class ‘clockType’
void clockType::printTime(){
^~~~~~~~~
clockType.h:9:7: error: candidate is: void clockType::printTime() const
void printTime() const;
^~~~~~~~~
clockTypeImp.cpp:21:6: error: prototype for ‘bool clockType::equalTime(clockType)’ does not match any in class ‘clockType’
bool clockType::equalTime(clockType second){
^~~~~~~~~
clockType.h:13:7: error: candidate is: bool clockType::equalTime(const clockType&) const
bool equalTime(const clockType&) const;
^~~~~~~~~
In file included from clockTypeImp.cpp:1:0,
from main.cpp:3:
clockType.h:1:7: error: redefinition of ‘class clockType’
class clockType
^~~~~~~~~
In file included from main.cpp:2:0:
clockType.h:1:7: note: previous definition of ‘class clockType’
class clockType
^~~~~~~~~
In file included from main.cpp:3:0:
clockTypeImp.cpp:17:6: error: prototype for ‘void clockType::printTime()’ does not match any in class ‘clockType’
void clockType::printTime(){
^~~~~~~~~
In file included from main.cpp:2:0:
clockType.h:9:7: error: candidate is: void clockType::printTime() const
void printTime() const;
^~~~~~~~~
In file included from main.cpp:3:0:
clockTypeImp.cpp:21:6: error: prototype for ‘bool clockType::equalTime(clockType)’ does not match any in class ‘clockType’
bool clockType::equalTime(clockType second){
^~~~~~~~~
In file included from main.cpp:2:0:
clockType.h:13:7: error: candidate is: bool clockType::equalTime(const clockType&) const
bool equalTime(const clockType&) const;
^~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:9:11: error: ‘class clockType’ has no member named ‘print’
time1.print();
^~~~~
main.cpp:11:11: error: ‘class clockType’ has no member named ‘print’
time2.print();
^~~~~
main.cpp:13:11: error: ‘class clockType’ has no member named ‘print’
time2.print();
sory for spelling mistakes, my english is not that good.