Hi guys..
I've started but don't know what to do next.. can someone please help.

This is the question..

Q:- Write a program to define a class to implement the time of day. A clock gives the time of day, let us call this class ClockType. Furthermore, to represent the time in computer memory, use there int variables: one to represent the hours (i.e. hr), one to represent the minutes (i.e min) and one to represent the seconds (i.e. sec) and perform the following operations

1. setTime function with three parameters to validate the followings
a. hours should be in the range 0-23 otherwise make it 0
b. minutes should be in the range 0-59 otherwise make it 0
c. second should be in the range 0-59 otherwise make it 0
2. printTime function to print the time
3. incrementSeconds to increment the time by one second
4. incrementMinutes to increment the time by one minute
5. incrementHour to increment the time by one hour
Write application to use ClockType class and all its member functions
Note:
The time is going to be printed in the following formate: hh:mm:ss (e.g. 10:04:30)


This is my starting..

# include <iostream>
using namespace std;

class ClockType 
{
	
public:

	const ClockType ();

	void setTime (int hours, int minutes, int seconds);

	void printTime ();

	int incrementSeconds (int second);

	int incrementMinutes (int minutes);

	int incrementHour (int hours);

private:

	int hr, sec, min;

};


int main ()
{


return 0;
}

How do I fill them?

Dani AI

Generated

For : a few fixes and a compact working approach that fills the missing pieces in the posted class. Key points: the constructor should not be const, setTime must validate each field (hours 0–23, minutes/seconds 0–59), printTime should be const and print two digits per field, and the three increment methods should be no-argument operations that handle carry (seconds -> minutes -> hours) with hours wrapping modulo 24. Below is a simple, complete example and a short explanation of the important bits.

#include <iostream>
#include <iomanip>

class ClockType {
public:
    ClockType(int h=0,int m=0,int s=0) { setTime(h,m,s); }
    void setTime(int h,int m,int s) {
        hr = (h>=0 && h<24) ? h : 0;
        min = (m>=0 && m<60) ? m : 0;
        sec = (s>=0 && s<60) ? s : 0;
    }
    void printTime() const {
        std::cout << std::setw(2) << std::setfill('0') << hr << ':'
                  << std::setw(2) << std::setfill('0') << min << ':'
                  << std::setw(2) << std::setfill('0') << sec;
    }
    void incrementSeconds() {
        if (++sec >= 60) { sec = 0; incrementMinutes(); }
    }
    void incrementMinutes() {
        if (++min >= 60) { min = 0; incrementHours(); }
    }
    void incrementHours() {
        hr = (hr + 1) % 24;
    }
private:
    int hr, min, sec;
};

int main() {
    ClockType c;
    int h,m,s;
    std::cout << "Enter hours minutes seconds: ";
    if (std::cin >> h >> m >> s) c.setTime(h,m,s);
    c.printTime();
    std::cout << "  +1s -> ";
    c.incrementSeconds();
    c.printTime();
    std::cout << '\n';
}

Notes and quick troubleshooting: test edge cases such as 23:59:59 (should become 00:00:00 after one second). If input fails (non-numeric), clear the stream and handle the error before calling setTime. If a different behavior is wanted when a field is invalid (e.g., clamp instead of reset to 0), change the validation in setTime accordingly.

I also don't know wethere user is going to enter the time or not.. I mean am i going to prompt him to enter any cin or not :s

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.