In: Computer Science
USE C++ and please keep program as simple as possible and also comment so it is easy to understad
Create a structure called time. Its three members, all type int,
should be called hours,
minutes, and seconds. Write a program that prompts the user to
enter a time value in hours,
minutes, and seconds. This should be in 12:59:59 format. This
entire input should be assigned
first to a string variable. Then the string should be tokenized
thereby assigning the 1st token
to hours, 2nd token to minutes, and 3rd token to seconds member
variables of the structure
called time. Finally inside a void Print_in_Seconds(void) member
function of time structure,
it should print out the total number of seconds represented by this
time value:
long totalsecs = t1.hours*3600 + t1.minutes*60 + t1.seconds
#include<iostream>
struct time //specify the structure
{
int seconds; //three types are declared in int
int minutes;
int hours;
};
void total_secs(struct time t1,struct time*totalsecs );
using namespace std;
int main()
{
struct time t1; //total_secs and others probably aren't of type TIME, are they
cout<<" Your Entered Time is: \n";
cout<<"Enter the Hours, Minutes and Seconds : ";
cin>>t1.hours>>t1.minutes>>t1.seconds;
cout<<t1.hours<<":"<<t1.minutes<<":"<<t1.seconds<<endl;
long total_secs = t1.hours*3600 + t1.minutes*60 + t1.seconds; //Time value
cout<<"Total number of seconds is :"<<total_secs<<endl; //Printing Total number of seconds
return 0;
}
OUTPUT:-