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

need help using C++ This chapter defines the class clock Type to implement time

ID: 3826355 • Letter: N

Question

need help using C++

This chapter defines the class clock Type to implement time in a program. Add functions to this class so that a program that uses this class can set only the hours, minutes, or seconds and retrieve only the hours, Also write a program to test your class.

Create a new project named Lab13ClockType. Then write a program that behaves as described in the textbook’s Chapter 10, Programming Exercise 7, with the modification discussed below. (See pages 652 to 667 for the original clockType class.) Your program should consist of three files:

clockType.h, a header file that declares your class. To save yourself some typing, build upon the original clockType.h file that you’ll find on the course website’s Unit 13 page. clockType.cpp, an implementation file that defines your class’s member functions. Build upon the original clockType.cpp file that you’ll find on the course website’s Unit 13 page.

Lab13ClockType.cpp, a file that tests your class by creating a clockType object and demonstrating the member functions.

Modification: To make things a little easier, change the word “retrieve” to “print” in the second sentence of the book’s directions for this program.

File clockType.h

File ClockType.cpp

please read the instructions carefully

i need a working program please

need help using C++

This chapter defines the class clock Type to implement time in a program. Add functions to this class so that a program that uses this class can set only the hours, minutes, or seconds and retrieve only the hours, Also write a program to test your class.

Create a new project named Lab13ClockType. Then write a program that behaves as described in the textbook’s Chapter 10, Programming Exercise 7, with the modification discussed below. (See pages 652 to 667 for the original clockType class.) Your program should consist of three files:

clockType.h, a header file that declares your class. To save yourself some typing, build upon the original clockType.h file that you’ll find on the course website’s Unit 13 page. clockType.cpp, an implementation file that defines your class’s member functions. Build upon the original clockType.cpp file that you’ll find on the course website’s Unit 13 page.

Lab13ClockType.cpp, a file that tests your class by creating a clockType object and demonstrating the member functions.

Modification: To make things a little easier, change the word “retrieve” to “print” in the second sentence of the book’s directions for this program.

File clockType.h

File ClockType.cpp

please read the instructions carefully

i need a working program please

Explanation / Answer

//File Name: clockType.h
//clockType.h, the specification file for the class clockType
#ifndef CLOCKTYPE_H
#define CLOCKTYPE_H
#include <iostream>
#include <ostream>

//Class clockType Definition
class clockType
{
public:
//Prototype of class Member functions
void setTime(int hours, int minutes, int seconds);
//Function to set the time.
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds;
// The function checks whether the
// values of hours, minutes, and seconds
// are valid. If a value is invalid, the
// default value 0 is assigned.

void getTime(int& hours, int& minutes, int& seconds) const;
//Function to return the time.
//Postcondition: hours = hr; minutes = min;
// seconds = sec;

void printTime() const;
//Function to print the time.
//Postcondition: The time is printed in the form
// hh:mm:ss.

void incrementSeconds();
//Function to increment the time by one second.
//Postcondition: The time is incremented by one second.
// If the before-increment time is
// 23:59:59, the time is reset to 00:00:00.

void incrementMinutes();
//Function to increment the time by one minute.
//Postcondition: The time is incremented by one minute.
// If the before-increment time is
// 23:59:53, the time is reset to 00:00:53.

void incrementHours();
//Function to increment the time by one hour.
//Postcondition: The time is incremented by one hour.
// If the before-increment time is
// 23:45:53, the time is reset to 00:45:53.

bool equalTime(const clockType& otherClock) const;
//Function to compare the two times.
//Postcondition: Returns true if this time is equal to
// otherClock; otherwise, returns false.

clockType(int hours, int minutes, int seconds);
//Constructor with parameters
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds;
// The constructor checks whether the
// values of hours, minutes, and seconds
// are valid. If a value is invalid, the
// default value 0 is assigned.

clockType();
//Default constructor
//The time is set to 00:00:00.
//Postcondition: hr = 0; min = 0; sec = 0;

private:
//Data members
int hr; //variable to store the hours
int min; //variable to store the minutes
int sec; //variable to store the seconds
};//End of class

#endif // CLOCKTYPE_H

//File Name: ClockType.cpp
//Implementation File for the class clockType
#include <iostream>
//Includes the header file
#include "clockType.h"
using namespace std;

//Defines setTime function
void clockType::setTime(int hours, int minutes, int seconds)
{
//Checks if hours is between 0 and 24 then set the hours
if (0 <= hours && hours < 24)
hr = hours;
//Otherwise set the hours to zero
else
hr = 0;
//Checks if minutes is between 0 and 59 then set the minutes
if (0 <= minutes && minutes < 60)
min = minutes;
//Otherwise set the minutes to zero
else
min = 0;
//Checks if seconds is between 0 and 59 then set the seconds
if (0 <= seconds && seconds < 60)
sec = seconds;
//Otherwise set the seconds to zero
else
sec = 0;
}//End of function

//Function to get time
void clockType::getTime(int& hours, int& minutes, int& seconds) const
{
hours = hr;
minutes = min;
seconds = sec;
}//End of function

//Function to increment hours by one
void clockType::incrementHours()
{
//Increment hour by one
hr++;
//Checks if the hour is greater than 23 then set the hour to zero
if(hr > 23)
hr = 0;
}//End of function

//Function to increment minutes by one
void clockType::incrementMinutes()
{
//Increment minutes by one
min++;
//Checks if the minutes is greater than 59 then set the minutes to zero and increment the hour by one
if (min > 59)
{
//Reset the minutes to zero
min = 0;
//Increment the hours by one
incrementHours();
}//End of if
}//End of function

//Function to increment Seconds by one
void clockType::incrementSeconds()
{
//Increment seconds by one
sec++;
//Checks if the seconds is greater than 59 then set the seconds to zero and increment the minutes by one
if (sec > 59)
{
//Reset the seconds to zero
sec = 0;
//Increment the minutes by one
incrementMinutes();
}//End of if
}//End of function

//Function to print time
void clockType::printTime() const
{
//Checks if the hour is single digit then add a zero before it
if (hr < 10)
cout << "0";
cout << hr << ":";
//Checks if the minute is single digit then add a zero before it
if (min < 10)
cout << "0";
cout << min << ":";
//Checks if the second is single digit then add a zero before it
if (sec < 10)
cout << "0";
cout << sec;
}//End of function

//Checks two clockType class object whether they are equal or not and returns boolean result
bool clockType::equalTime(const clockType& otherClock) const
{
return (hr == otherClock.hr && min == otherClock.min && sec == otherClock.sec);
}//End of function

//Parameterized constructor to initialize the data members to the given parameter value
clockType::clockType(int hours, int minutes, int seconds)
{
//Checks if hours is between 0 and 24 then set the hours
if (0 <= hours && hours < 24)
hr = hours;
//Otherwise set hour hour to zero
else
hr = 0;
//Checks if minutes is between 0 and 59 then set the minutes
if (0 <= minutes && minutes < 60)
min = minutes;
//Otherwise set the minutes to zero
else
min = 0;
//Checks if seconds is between 0 and 59 then set the seconds
if (0 <= seconds && seconds < 60)
sec = seconds;
//Otherwise set the seconds to zero
else
sec = 0;
}//End of function

//Default Constructor to initialize the data members to zero
clockType::clockType()
{
hr = 0;
min = 0;
sec = 0;
}//End of Default constructor

//File Name: Lab13ClockType.cpp

#include <iostream>
#include "clockType.h"
#include "ClockType.cpp"
using namespace std;

//Main function to test the member functions of the class clockType
int main()
{
//Using default constructor creates time
clockType c1;
cout<<" Using Default Constructor Initial Time For Time - 1: ";
c1.printTime();
//Using parameterized constructor creates time
clockType c2(11, 58, 59);
cout<<" Using Parameterized Constructor Initial Time For Time - 2: ";
c2.printTime();

clockType c3;
//Using set time function creates time
c3.setTime(11, 58, 59);
cout<<" After Setting Time For Time - 3: ";
c3.printTime();

//Compares the equality of two time class object
if(c1.equalTime(c2))
cout<<" Both Time - 1 and Time - 2 Are Equal";
else
cout<<" Both Time - 1 and Time - 2 Are Not Equal";

if(c2.equalTime(c3))
cout<<" Both Time - 2 and Time - 3 Are Equal";
else
cout<<" Both Time - 2 and Time - 3 Are Not Equal";

//Increment the time by one hour by calling incrementHours function
c1.incrementHours();
cout<<" After Incrementing Time - 1 Hour By One Hour: ";
c1.printTime();

//Increment the time by one minute by calling incrementMinutes function
c2.incrementMinutes();
cout<<" After Incrementing Time - 2 Minute By One Minute: ";
c2.printTime();

//Increment the time by one second by calling incrementSeconds function
c3.incrementSeconds();
cout<<" After Incrementing Time - 3 Second By One Second: ";
c3.printTime();

//Increment the time by one second by calling incrementSeconds function
c2.incrementSeconds();
cout<<" Again Incrementing Time - 2 Second By One Second: ";
c2.printTime();

}//End of main

Output:

Using Default Constructor Initial Time For Time - 1: 00:00:00

Using Parameterized Constructor Initial Time For Time - 2: 11:58:59

After Setting Time For Time - 3: 11:58:59

Both Time - 1 and Time - 2 Are Not Equal

Both Time - 2 and Time - 3 Are Equal

After Incrementing Time - 1 Hour By One Hour: 01:00:00

After Incrementing Time - 2 Minute By One Minute: 11:59:59

After Incrementing Time - 3 Second By One Second: 11:59:00

Again Incrementing Time - 2 Second By One Second: 12:00:00