Untitled
unknown
plain_text
2 years ago
963 B
3
Indexable
#include <iostream> using namespace std; class Time { private: int hours; int minutes; int seconds; public: // Default constructor Time() { hours = 0; minutes = 0; seconds = 0; } // Parameterized constructor Time(int h, int m, int s) { hours = h; minutes = m; seconds = s; } // Copy constructor Time(const Time& t) { hours = t.hours; minutes = t.minutes; seconds = t.seconds; } // Display method void display() { cout << hours << ":" << minutes << ":" << seconds << endl; } }; int main() { // Create a time object using the default constructor Time t1; cout << "t1: "; t1.display(); // Output: 0:0:0 // Create a time object using the parameterized constructor Time t2(12, 30, 45); cout << "t2: "; t2.display(); // Output: 12:30:45 // Create a time object using the copy constructor Time t3 = t2; cout << "t3: "; t3.display(); // Output: 12:30:45 return 0; }
Editor is loading...