Question

Given two time data (in hour, minute and second format) an input, create a Time structure...

Given two time data (in hour, minute and second format) an input, create a Time structure to store hour, minute and second values. Calculate the difference between two time.

Perform the following operations

  • Store value of hour, minute and second in the Time structure.
  • Calcuate the difference of Time.

Input:

  12 34 55

    8 12 15

    where:

  • First line represents value of time in hours, minute and second format.
  • Second line represents value of anothre time in hours, minute and second format.

Output:

   12:34:55 - 8:12:15 = 4:22:40

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:-

#include <stdio.h>
struct Time{//Time Structure
int h;
int m;
int s;
};
int main()
{
struct Time t1,t2,t3;
scanf("%d %d %d",&t1.h,&t1.m,&t1.s);
scanf("%d %d %d",&t2.h,&t2.m,&t2.s);
t3.h=t1.h-t2.h;//Calculation......
t3.m=t1.m-t2.m;
t3.s=t1.s-t2.s;
printf("%d:%d:%d - %d:%d:%d = %d:%d:%d",t1.h,t1.m,t1.s,t2.h,t2.m,t2.s,t3.h,t3.m,t3.s);//Output statement
return 0;
}

Screenshot of Code:-(For indentation Check)

Output:-(screenshot)

Note:- Please LIKE if you understand.

Please don't hesitate to comment if you've any doubt

Add a comment
Know the answer?
Add Answer to:
Given two time data (in hour, minute and second format) an input, create a Time structure...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Determine the time period of the day in C++ a. Request an hour in military time...

    Determine the time period of the day in C++ a. Request an hour in military time between 0 and 23 inclusive. b. If the value for hour is invalid: 1. Output Invalid hour". 2. Repeat the input request. a. Request the minutes b. Print the time using hh:mm format C. Convert to 12 hour format (i.e. AM/PM) and print Use a single if/else-if/else structure to do the following: 1. If the hour is between 0 and 12 inclusive, output "It...

  • Lesson is about Input validation, throwing exceptions, overriding toString Here is what I am supposed to...

    Lesson is about Input validation, throwing exceptions, overriding toString Here is what I am supposed to do in the JAVA Language: Model your code from the Time Class Case Study in Chapter 8 of Java How to Program, Late Objects (11th Edition) by Dietel (except the displayTime method and the toUniversalString method). Use a default constructor. The set method will validate that the hourly employee’s rate of pay is not less than $15.00/hour and not greater than $30.00 and validate...

  • Java problem In this problem, the first input is a positive integer called n that will...

    Java problem In this problem, the first input is a positive integer called n that will represent the number of lines to process. The lines to be processed have one or more integers separated by whitespaces. For each of these lines, you must output: The minimum value of the integers The maximum value of the integers The sum of the integers It is worth to mention that the number of integers of each line is not known a priori and...

  • Please submit only Python source code. 1. Arithmetic trees 50 marks You are given an input file with multiple pairs of...

    Please submit only Python source code. 1. Arithmetic trees 50 marks You are given an input file with multiple pairs of input lines. The first line of each pair is a tree given as a predecessor array. The second line is the value at the corresponding node. Values at leaf nodes (nodes with no children) are integers. At non-leaf nodes, the two possible values are + or *. The tree represents an arithmetic expression where the value at a non-leaf...

  • POD 3: Tick Tock Instructions There are 24 hours in a day, but we all think...

    POD 3: Tick Tock Instructions There are 24 hours in a day, but we all think about them differently. Some people and places in the world work with a 24-hour clock that goes from 0:00 to 23:59, while others work with a 12-hour clock that goes from 12.00AM to 11:59PM 24-hour clock 0.00 (midnight) 1200 (noon) 23:59 (one minute before midnight), A COLLAPSE 12-hour clock: *12.00 AM" (midnight) *12:00 PM" (noon) "11:59 PM" (one minute before midnight), You are going...

  • Objectives: 1. Use if, switch, and loop statements 2. Use input and output statements 3. Incorporate...

    Objectives: 1. Use if, switch, and loop statements 2. Use input and output statements 3. Incorporate functions to divide the program into smaller segments Instructions: Your task is to write a program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then ask you what time the car left the parking deck. You should then calculate the time that has passed between...

  • CC++ Compiler: CPP (gcc-5.x) 0 Simple Calculator Given two integers and a string, create a simple...

    CC++ Compiler: CPP (gcc-5.x) 0 Simple Calculator Given two integers and a string, create a simple calculator which performs the following operations: • Addition if the string is "+" • Difference if the string is "-" Multiplication if the string is "*" • Return quotient (obtained by dividing the first number by the second) if the string is "/" • Return greater value if the string is "max" • Return lesser value if the string is "min" solution.cpp 2 Create...

  • Datapath To make the calculator work, you have to create datapath components for the Datapath subcircuit:...

    Datapath To make the calculator work, you have to create datapath components for the Datapath subcircuit: Create an ALU that can calculate the result for the basic arithmetic operations (addition, subtraction, multiplication, division) for two 8-bit values. The ALU should output the needed result depending on the selected operation. Use 3 registers to store the first number, selected operator and second number. Remember that registers store the values on the input during a rising edge in the clock input (default...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

  • PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program tha...

    PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file  timeValidation.txt :   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT