Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/header file clocktype #ifndef h_clocktype #define h_clocktype #include using na

ID: 3641642 • Letter: #

Question

/header file clocktype
#ifndef h_clocktype
#define h_clocktype
#include
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
#include
#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<if(min<10)
cout<<"0";
cout<if(sec<10)
cout<<"0";
cout<}
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<<" The time now is : ";
myclock.printtime();
getch();
}
// header for the derived class
#ifndef h_clocktype2
#define h_clocktype2
#include
#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
#include
#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<<" The time now is : ";
clock.printtime();
return(0);
}

Explanation / Answer

The biggest problem I found was that you had two different main() defined. Also, the code that was posted had a bunch of #include lines with nothing specified to include.

I fixed what I could find to get the code to compile... I added comments to indicate the changes.

Once compiled, it generates this output:

The time now is : 12:14:40
The time now is : 00:00:00
Press any key to continue . . .
The time now is : 12:14:40 GMT
The time now is : 00:00:00 IST
Press any key to continue . . .

Hope this helps...

// main function

using namespace std;

#include <iostream> // this was blank
#include <string> // this was blank

#include "clocktype.h"
#include "clocktype2.h"

int main()
{   // combined the two different main() sections into one
    clocktype myclock;
    myclock.settime( 12, 14, 40);
    cout<<" The time now is : ";
    myclock.printtime();
    myclock.settime( 24, 60, 60);
    cout<<" The time now is : ";
    myclock.printtime();
    cout << endl;

    system("pause"); // pause output
   
    clocktype2 clock;
    clock.settime( 12, 14, 40, GMT);
    cout<<" The time now is : ";
    clock.printtime();
    clock.settime( 24, 60, 60, IST);
    cout<<" The time now is : ";
    clock.printtime();
    cout << endl;

    system("pause"); // pause output
    return(0);
}

//header file clocktype
#ifndef h_clocktype
#define h_clocktype
//#include // don't need this
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

using namespace std;

#include <iostream> // this was a blank #include
//#include

#include "clocktype.h"

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()
{   // many fixes here!!!
    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) // Changed < to >
        hr=0;
}
void clocktype::incminutes()
{
    min++;
    if(min>59) // changed < to >
    {           // added braces
        min=0;
        inchours();
    }
}
void clocktype::incseconds()
{
    sec++;
    if(sec>59) // changed < to >
    {          // added braces
        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;
}

// header for the derived class
#ifndef h_clocktype2
#define h_clocktype2

using namespace std;

#include"clocktype.h"

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
using namespace std;

#include <iostream> // This was blannk
#include <string> // This was blank

#include"clocktype.h"
#include"clocktype2.h"

void clocktype2::settime(int hours, int minutes, int seconds, zonetype timezone)
{   // rewrote this
    clocktype::settime(hours,minutes,seconds); // call base class settime
    tz=timezone; // set timezone since base class doesn't set this
}
void clocktype2::printtime()
{  
    static string zonetype[5]={"GMT", "EST", "PST", "IST", "CET"};
    clocktype::printtime(); // call base class print time
    cout << " " << zonetype[tz]; // print timezone since base class doesn't print this
}
clocktype2::clocktype2(){
    hr=0;
    min=0;
    sec=0;
    tz=GMT;
}
clocktype2::clocktype2(int hours, int minutes, int seconds, zonetype timezone)
{   // all of these assignments were backwards
    hr=hours;
    min=minutes;
    sec=seconds;
    tz=timezone;
}