Git Product home page Git Product logo

Getting compilation error in this c++ program #include <iostream> using namespace std; class Time {     int h, m, s; public:     Time()     {         h = 0, m = 0, s = 0;     }     void setTime();     void show()     {         cout << h << ":" << m << ":" << s;     }     Time operator+(Time); }; Time Time::operator+(Time t1) {     Time t;     int a, b;     a = s + t1.s;     t.s = a % 60;     b = (a / 60) + m + t1.m;     t.m = b % 60;     t.h = (b / 60) + h + t1.h;     t.h = t.h % 12;     return t1; } int main() {     Time t1, t2, t3;     cout << "enter the first time";     t1.setTime();     cout << "\n Enter the second time";     t2.setTime();     t3 = t1 + t2;     cout << "\n first time";     t1.show();     cout << "\nsecond time";     t2.show();     cout << "\n sum of times";     t3.show();     return 0;     } about c HOT 1 OPEN

Diliphindustani avatar Diliphindustani commented on June 25, 2024
Getting compilation error in this c++ program #include using namespace std; class Time {     int h, m, s; public:     Time()     {         h = 0, m = 0, s = 0;     }     void setTime();     void show()     {         cout << h << ":" << m << ":" << s;     }     Time operator+(Time); }; Time Time::operator+(Time t1) {     Time t;     int a, b;     a = s + t1.s;     t.s = a % 60;     b = (a / 60) + m + t1.m;     t.m = b % 60;     t.h = (b / 60) + h + t1.h;     t.h = t.h % 12;     return t1; } int main() {     Time t1, t2, t3;     cout << "enter the first time";     t1.setTime();     cout << "\n Enter the second time";     t2.setTime();     t3 = t1 + t2;     cout << "\n first time";     t1.show();     cout << "\nsecond time";     t2.show();     cout << "\n sum of times";     t3.show();     return 0;     }

from c.

Comments (1)

peeyushtripathi avatar peeyushtripathi commented on June 25, 2024

#include
using namespace std;

class Time {
int h, m, s;
public:
Time()
{ h = 0, m = 0, s = 0;
}

    void setTime();     
    void show()     {         
            cout << h << ":" << m << ":" << s;     
    }     

    Time operator+(Time); 

};

void Time::setTime()
{
char tim[9];
std::cin>>tim;
int hh;
int mm;
int ss;

    hh = atoi(&tim[0]); 
    mm = atoi(&tim[3]);
    ss = atoi(&tim[6]);
    this->h=hh;
    this->m=mm;
    this->s=ss;

}

Time Time::operator+(Time t1) {
Time t;
int a, b;
a = this->s + t1.s;
t.s = a % 60;
b = (a / 60) + this->m + t1.m;
t.m = b % 60;
t.h = (b / 60) + this->h + t1.h;
t.h = t.h % 12;
return t; }

    int main() {     
            Time t1, t2, t3;     
            cout << "enter the first time hh:mm:ss";     
            t1.setTime();     
            cout << "\n Enter the second time";     
            t2.setTime();     
            t3 = t1 + t2;     
            cout << "\n first time";     
            t1.show();     
            cout << "\nsecond time";     
            t2.show();     
            cout << "\n sum of times";     
            t3.show();     
            return 0;     
    } 

/*----------------------------------------------------------------------------------------------------------------
──(shiv㉿kali)-[~/GIT_REPOS/online_c++_questions]
└─$ ./a.out
enter the first time hh:mm:ss10:13:45

Enter the second time13:45:56

first time10:13:45
second time13:45:56
sum of times11:59:41
┌──(shiv㉿kali)-[~/GIT_REPOS/online_c++_questions]
└─$ ./a.out
enter the first time hh:mm:ss01:12:23

Enter the second time03:04:05

first time1:12:23
second time3:4:5
sum of times4:16:28
---------------------------------------------------------------------------------*/

from c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.