Write a function called hms_to_secs() that takes three int values—for hours, minutes, and seconds—as arguments, and returns the equivalent time in seconds (type long). Create a program that exercises this function by repeatedly obtaining a time value in hours, minutes, and seconds from the user (format 12:59:59), calling the function, and displaying the value of seconds it returns.

Respuesta :

Solution:

#include<iostream>

using namespace std;

class timeconvert//class

{

     public:

         int hms_to_secs(int h,int m,int s)//function of the class

               {

                   return (h*3600+m*60+s);

               }

};

int main()

{       timeconvert obj;//creating object of the class

       int h,m,s,total;

       cout<<"enter hour";

       cin>>h;

       cout<<"enter minute";

       cin>>m;

       cout<<"enter second";

       cin>>s;

       total=obj.hms_to_secs(h,m,s);//function call

       cout<<"total second of"<<h<<":"<<m<<":"<<s<<"="<<total;

}

/*

sample output:-

enter hour12

enter minute59

enter second59

total second of12:59:59=46799

*/

In this exercise we have to use the computer language knowledge in C++ to write the code as:

the code is in the attached image.

In a more easy way we have that the code will be:

#include<iostream>

using namespace std;

class timeconvert//class

{

    public:

        int hms_to_secs(int h,int m,int s)//function of the class

              {

                  return (h*3600+m*60+s);

              }

};

int main()

{       timeconvert obj;//creating object of the class

      int h,m,s,total;

      cout<<"enter hour";

      cin>>h;

      cout<<"enter minute";

      cin>>m;

      cout<<"enter second";

      cin>>s;

      total=obj.hms_to_secs(h,m,s);//function call

      cout<<"total second of"<<h<<":"<<m<<":"<<s<<"="<<total;

}

/*

sample output:-

enter hour12

enter minute59

enter second59

total second of12:59:59=46799

*/

See more about C++ code at brainly.com/question/25870717

Ver imagen lhmarianateixeira