I am trying to run this program, in this I have a class clocktype with its header file and implementation file. Now I am trying to inherit this class to implement a new function called timezone.
The build is successful but I have 2 errors while compiling here is my code:
//header file clocktype
#ifndef h_clocktype
#define h_clocktype
#include<string>
using namespace std;
class clocktype
{
public:
void settime(int hours, int minutes, int seconds);
void gettime(int& hours, int& minutes, int& seconds);
void printtime();
void incseconds();
void incminutes();
void inchours();
clocktype (int hours, int minutes, int seconds);
clocktype();
protected:
int hr;
int min;
int sec;
};
#endif;
// implemnetation file
#include<iostream>
#include<conio.h>
#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)
{
hours=hr;
minutes=min;
seconds=sec;
}
void clocktype::printtime()
{
if(hr<10)
cout<<"0";
cout<<hr<<":";
if(min<10)
cout<<"0";
cout<<min<<":";
if(sec<10)
cout<<"0";
cout<<sec;
}
void clocktype::inchours()
{
hr++;
if(hr<23)
hr=0;
}
void clocktype::incminutes()
{
min++;
if(min<59)
min=0;
inchours();
}
void clocktype::incseconds()
{
sec++;
if(sec<59)
sec=0;
incminutes();
}
clocktype::clocktype()
{
hr=0;
min=0;
sec=0;
}
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;
}
// main function
int main()
{
clocktype myclock;
myclock.settime( 12, 14, 40);
cout<<" The time now is : ";
myclock.printtime();
myclock.settime( 24, 60, 60);
cout<<"\n The time now is : ";
myclock.printtime();
getch();
}
// header for the derived class
#ifndef h_clocktype2
#define h_clocktype2
#include<iostream>
#include"clocktype.h"
using namespace std;
enum zonetype {GMT, EST, PST, IST, CET};
class clocktype2: public clocktype
{
public:
void settime(int hours, int minutes, int seconds,zonetype timezone);
void gettime(int hours, int minutes, int seconds,zonetype timezone);
void printtime();
clocktype2 (int hours, int minutes, int seconds, zonetype timezone);
clocktype2();
private:
zonetype tz;
};
#endif;
// implementation file for derived class
#include<iostream>
#include<conio.h>
#include"clocktype.h"
#include"clocktype2.h"
using namespace std;
void clocktype2::settime(int hours, int minutes, int seconds, zonetype timezone)
{
hours=hr;
minutes=min;
seconds=sec;
timezone=tz;
}
void clocktype2::printtime()
{
static string zonetype[5]={"GMT", "EST", "PST", "IST", "CET"};
}
clocktype2::clocktype2(){
hr=0;
min=0;
sec=0;
tz=GMT;
}
clocktype2::clocktype2(int hours, int minutes, int seconds, zonetype timezone)
{
hours=hr;
minutes=min;
seconds=sec;
timezone=tz;
}
int main()
{
clocktype2 clock;
clock.settime( 12, 14, 40, GMT);
cout<<" The time now is : ";
clock.printtime();
clock.settime( 24, 60, 60, IST);
cout<<"\n The time now is : ";
clock.printtime();
return(0);
}