Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Time.h
C++
#pragma once

//***********************************
//** declare your struct Time here **
//***********************************

Time SubtractTime(Time t1, Time t2);

void PrintTime(Time t1);


Time.cpp

C++
#include <iostream>
#include "Time.h"

using namespace std;

Time SubtractTime(Time t1, Time t2)
{
	//**********************************************
	//** impleent your function SubtractTime here **
	//**********************************************
}

void PrintTime(Time t)
{
	//*******************************************
	//** impleent your function PrintTime here **
	//*******************************************
}


Main.cpp

C++
#include <iostream>
#include "Time.h"

using namespace std;

int main()
{
	Time diff, t1, t2;

	t1 = { 3, 20, 50 };
	t2 = { 2, 37, 58 };

	diff = SubtractTime(t1, t2);

	PrintTime(t1);
	cout << " - ";
	PrintTime(t2);
	cout << " is ";
	PrintTime(diff);
	cout << endl;

	return 0;
}


What I have tried:

I just cant figure it out for the life of me.
Posted
Updated 8-Dec-21 13:15pm
v2

When I look at the task, it looks more like C than C ++.
As Rick York already wrote, one would actually solve that with a class.
However, the given framework does not fit.

So a structure like this is needed to define time:
C++
//***********************************
//** declare your struct Time here **
//***********************************
typedef struct {
	int h, m, s;
}Time;

Since the prototypes for the functions are already available, it shouldn't be a problem to calculate the difference between two times.

Realizing the difference calculation with seconds as suggested makes sense, since the result should also be time according to the task. Here 4Byte should be able to calculate if max. 24h:59min:59sec can come out.
 
Share this answer
 
v2
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Think about how you would do it manually ... you might want to consider sorting the lists so it's easier to "see" duplicates.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Go back and re-read your notes and/or course material. Your instructor will have given you the information you need to solve this problem. We are not going to do it for you. Learning takes experience, and figuring out the answer will help you with your next exercise. You learn something even if you get it wrong the first few times. I still get things wrong when I'm coding, but hopefully I learn from my mistakes.

We're more than happy to help you if you've tried to solve your problem, and are stuck with compilation or run-time errors. But you won't learn anything by someone else doing the work for you.
 
Share this answer
 
It appears to me you need to define a Time class. It would need at minimum the hour, minute, and second. There should be another member that is the total seconds given the hour, minute, and second. Then the computations are easy - just add or subtract total seconds. There should also be two methods - get the total seconds from the H,M,&S; and get the H,M,&S from total seconds. In other words, those two are opposite pairs.

As for the output - you need to display the hour, minute, and second and remember it can go negative. The standard format is HH:MM:SS. This page can help with cout and its options : cout - C++ Reference[^]
 
Share this answer
 
It seems like you want us to do your work for you. Remember, we can help you, but you have to figure out how to solve it on your part first.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900