This commit is contained in:
RafayAhmad7548 2024-06-16 18:53:25 +05:00
parent 37776af5db
commit ab03d5f10c
4045 changed files with 286212 additions and 3 deletions

View file

@ -0,0 +1,50 @@
#include <iostream>
using namespace std;
class Time{
// You will need three integer data members to store the hours, minutes, and seconds.
int hours;
int minutes;
int seconds;
public:
Time(int hours = 0, int minutes = 0, int seconds = 0) : hours(hours), minutes(minutes), seconds(seconds){}
Time(const Time& copy){
*this = copy;
}
// Binary Operators
// Arithmetic Operators
Time operator+(Time& val) {
Time result;
result.seconds = this->seconds + val.seconds;
if(result.seconds>=60){
result.seconds -= 60;
result.minutes++;
}
result.minutes += this->minutes + val.minutes;
if(result.minutes>=60){
result.minutes -= 60;
result.hours++;
}
result.hours += this->hours + val.hours;
}
Time operator-(const Time& val) const{
}
// Compound Assignment Operators
Time& operator+=(const Time& rhs){
return rhs + *this;
}
Time& operator-=(const Time& rhs);
// Logical Operators
bool operator==(const Time& val) const;
bool operator!=(const Time& val) const;
bool operator<(const Time& val) const;
bool operator<=(const Time& val) const;
bool operator>(const Time& val) const;
bool operator>=(const Time& val) const;
// Additional Functions
Time elapsedTime() const; // Calculate elapsed time
~Time(); // destructor
friend std::ostream& operator<<(std::ostream& output, const Time& val); // outputs the Time
friend std::istream& operator>>(std::istream& input, Time& val); // inputs the Time
};