I am trying to create a class that will run this main program but I'm getting the errors:
Can anyone explain cause/solution to said errors?
Here is my main:
int main()
{
clockType c1(15, 45, 30), c2(3, 20); // hour, min, sec
cout << "c1 is " << c1; // add whatever to beautify it
cout << "c2 is " << c2;
cout << "c1+c2 is " << c1+c2;
c2 = c1+c1;
cout << "c1+c1 is " << c2;
}
Here is my header file:
#ifndef CLOCKTYPE_H
#define CLOCKTYPE_H
#include <iostream>
#include <ostream>
class clockType
{
friend std::ostream& operator<<(std::ostream& os, const clockType& out);
friend clockType operator+(const clockType& one, const clockType& two);
public:
clockType();
clockType(int hours, int minutes, int seconds);
clockType(int hours, int minutes);
void setTime(int hours, int minutes, int seconds);
void getTime(int& hours, int& minutes, int& seconds);
void printTime();
void incrementhr();
void incrementmin();
void incrementsec();
private:
int hrs;
int mins;
int secs;
};
#endif // CLOCKTYPE_H
Here is my cpp file:
#include "clockType.h"
#include <iostream>
#include <iostream>
using namespace std;
clockType::clockType()
{
hrs = 0;
mins = 0;
secs = 0;
}
clockType::clockType(int hours, int minutes, int seconds)
{
setTime(hours, minutes, seconds);
}
clockType(int hours, int minutes)
{
hrs = hours;
mins = minutes;
secs = 0;
}
void clockType::setTime(int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hrs = hours;
else
hrs = 0;
if (0 <= minutes && minutes < 60)
mins = minutes;
else
mins = 0;
if(0 <= seconds && seconds < 60)
secs = seconds;
else
secs = 0;
}
ostream& operator<<(ostream& os, const clockType& out)
{
os << "Hour is " << out.hrs << "Minute is " << out.mins << "Seconds is " << out.secs;
return os;
}
clockType operator+(const clockType& one, const clockType& two)
{
clockType three;
three.hrs = one.hrs + two.hrs;
three.mins = one.mins + two.mins;
three.secs = one.secs + two.secs;
return three;
}