Advertisement
adityatandon

Object As Function Parameter

May 7th, 2021
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Time
  4. {
  5.     int hour, minute, second;
  6.     public:
  7.         void getTime() {
  8.             cout<<"\nEnter hours: "; cin>>hour;
  9.             cout<<"\nEnter minutes: "; cin>>minute;
  10.             cout<<"\nEnter seconds: "; cin>>second;
  11.         }
  12.         void printTime() {
  13.             cout<<"\nHours: "<<hour;
  14.             cout<<"\nMinutes: "<<minute;
  15.             cout<<"\nSeconds: "<<second;
  16.         }
  17.         void addTime(Time x, Time y) {
  18.             hour = x.hour + y.hour;
  19.             minute = x.minute + y.minute;
  20.             second = x.second + y.second;
  21.         }
  22. };
  23. int main()
  24. {
  25.     Time t1, t2, t3;
  26.     cout<<"\n\tTime 1\n";
  27.     t1.getTime();
  28.     t1.printTime();
  29.     cout<<"\n\tTime 2\n";
  30.     t2.getTime();
  31.     t2.printTime();
  32.    
  33.     t3.addTime(t1, t2);
  34.     cout<<"\nafter adding two objects\n";
  35.     t3.printTime();
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement