Question

In: Computer Science

USE C++ and please keep program as simple as possible and also comment so it is...

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

Solutions

Expert Solution

#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:-


Related Solutions

C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem you will take a list of names from the user and sort them alphabetically using selection sort. The code for selection sort for integer is available in the "Lab and Weekly Coding Solution module" in webcourses. Ask the user how many names the user wants to input. Let's say the number be N. Then take N number of names and put them in an...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT PLEASE. Problem: Driving Function driving(): Write a function driving(), that updates the odometer and fuel gauge of a car. The function will take in a reference to the variables storing the odometer and fuel gauge readings, along with a double representing the miles per gallon (mpg) the car gets and the number of miles the driver intends to go. The function should update the...
20.1: Checking on the Drought [(JAVA, ECLIPSE), Please keep the program as short as possible] The...
20.1: Checking on the Drought [(JAVA, ECLIPSE), Please keep the program as short as possible] The California drought is a topic that is weighing heavily on the minds of many people in this state. With all the rain we have gotten this year, we are all hoping the drought is over Let's examine some rainfall data for Silicon Valley to get a sense of how this year's rainfall compares to the average rainfall. For this assignment, you will be practicing...
(C++) keep things as simple as possible. I would love a good starting point with hints...
(C++) keep things as simple as possible. I would love a good starting point with hints to be able to finish it! Write a function called is valid phone number that takes a phone number as an array of characters and its size, and returns true if the input array is a valid phone number, false otherwise. A phone number is valid only if it is of the following format: (uuu) uuu-uuuu where u is from ‘0’, ‘1’, ‘2’, etc....
please write simple python3 program and also explain the logic of program because i am not...
please write simple python3 program and also explain the logic of program because i am not understanding and crying so much Problem Statement There is a very famous old restaurant in ByteLand city,which can serve only 1 customer at any given time.It has B chairs outside for waiting customers.The restautants manager has a list of people who will be coming in today.The i-th customer will arrive at t[i] (all unique) time and will eat for d[i] unit of time.The restaurant...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
write in C++ as simple as possible please and thanks don't use header file <bits/stdc++.h> All...
write in C++ as simple as possible please and thanks don't use header file <bits/stdc++.h> All programs work with binary numbers which are powers of 2 (2, 4, 8, …).  Write a program that will have a user enter a number (n) less than 10,000. Then have the program put each power of 2 (int) into an array up to and possibly including the number n. This means you don't know at the start how large the array will be, so...
Create a C program that performs the following (please comment the codes): a) Create a Stack...
Create a C program that performs the following (please comment the codes): a) Create a Stack ADT. Stack should be implemented using the linked list. b) Enter 10 random integer numbers between 0 to 50 in the stack. c) After pushing each element, print the content of the top of the stack. c) Then pop out those 10 integer numbers and print those numbers. d) Finally destroy the Stack.
write a simple program to demonstrate the use of static type of variables in c++... use...
write a simple program to demonstrate the use of static type of variables in c++... use comments to explain plz
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT