C please
In this question, you will find the difference between two time durations. You are given the following struct definitions:
typedef struct _duration {
int hours;
int minutes;
} Duration;
Design a function to find the difference between two durations:
Duration* subtract(Duration* duration1, Duration* duration2) {
}
Return a pointer to a new duration struct that contains the difference between the two.
It may be useful to reduce the durations to a single unit (example: minutes), find the difference, and then convert it back to hours and minutes.
Duration 1 will always be longer than duration 2.
Your answer should be in reduced form. For example, a time of "0 hours and 130 minutes" would be incorrect. The expected result, in this case, would be "2 hours and 10 minutes".
You must include the main function in your submission (provided in the template) so the code will compile. Note that only the return value of the subtract function will be tested.
Examples
Example 1 (provided in template)
Given duration1 is a pointer to a duration struct with:
5 hours and 30 minutes
And given duration2 is a pointer to a duration struct with:
1 hours and 55 minutes
If you call Duration* difference = subtract(duration1, duration2)
difference should be a pointer to a struct containing 3 hours and 35 minutes.
Example 2
Given duration1 is a pointer to a duration struct with:
6 hours and 45 minutes
And given duration2 is a pointer to a duration struct with:
2 hours and 15 minutes
If you call Duration* difference = subtract(duration1, duration2)
difference should be a pointer to a struct containing 4 hours and 30 minutes.
TEMPLATE
#include <stdio.h>
#include <stdlib.h>
typedef struct _duration {
int hours;
int minutes;
} Duration;
Duration* subtract(Duration* d1, Duration* d2) {
// CODE HERE
}
// Example main. You only need to write 'subtract', but this is here to help you test.
int main() {
Duration a = {5, 30}; // Struct shorthand for 5 hours, 30 minutes
Duration b = {1, 55}; // Struct shorthand for 1 hour, 55 minutes
Duration* d = subtract(&a, &b);
printf("%d:%d\n", d->hours, d->minutes);
// Expected output:
// 3:35
}
If you have any doubts, please give me comment...
#include <stdio.h>
#include <stdlib.h>
typedef struct _duration {
int hours;
int minutes;
} Duration;
Duration *subtract(Duration *d1, Duration *d2) {
Duration *temp = (Duration *)malloc(sizeof(Duration));
int tot_mins = (d1->hours*60 + d1->minutes) - (d2->hours*60 + d2->minutes);
temp->hours = tot_mins/60;
temp->minutes = tot_mins%60;
return temp;
}
// Example main. You only need to write 'subtract', but this is here to help you
// test.
int main() {
Duration a = {5, 30}; // Struct shorthand for 5 hours, 30 minutes
Duration b = {1, 55}; // Struct shorthand for 1 hour, 55 minutes
Duration *d = subtract(&a, &b);
printf("%d:%d\n", d->hours, d->minutes);
// Expected output:
// 3:35
}

C please In this question, you will find the difference between two time durations. You are...
Define a type which comprises a struct called
"Maxima". In this struct contains
two int values a
and b. The purpose of this struct is to store
the largest two int values among a set of
integers. The value a is the largest number and
the value b is the second largest number. In order
to accomplish this task, you need to write the following
functions:
allzero( struct pointer ): This function sets
a and b values in a given...
Please in C Language
Thank you!
The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO: 1) Add the typedef here: 5// TODO: 2) Modify the parameter of repeat to add irn the function pointer for the function to be called repeatedly: 8 void repeat (int times) for (int k 0; k < times; ++k) 12 // TODO: 3) Add the call to the function pointer here: 14 15 17 void test (void) 18 printf("Test!\n"); 19...
IN C WITH COMMENTS PLEASE, THANKS! Write the void function, convertTime(), which converts a time given in only seconds to the associated number of hours, minutes, and remaining seconds. For example, 20,565 seconds is converted to 5 hours, 42 minutes, and 45 seconds. Note: the template does not include the required function prototype, so careful attention must be given to the following instructions to ensure you have the correct format for the function. The function does not return any quantity...
I need help on this Systems review please! it's due by midnight monday. Question 1 Not yet answered Points out of 1.00 Flag question Question text Using these declarations: int * numberPointers[3]; int * pointer; int number; Which of the following statements would generate a warning or error? Select one: a. number = pointer; b. *pointer = number; c. pointer = numberPointers; d. numberPointers[2] = &number; e. a., b., and d. f. a. and c. Question 2 Not yet answered...
Hey everyone, I need help making a function with this directions
with C++ Language.
Can you guys use code like printf and fscanf without iostream or
fstream because i havent study that yet.
Thanks.
Directions: Write a function declaration and definition for the char* function allocCat. This function should take in as a parameter a const Words pointer (Words is a defined struct) The function should allocate exactly enough memory for the concatenation of all of the strings in the...
implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...
program in C - Starter code below //In this assignment, we practice call by reference. //Below description of call by reference is from the following link //https://www.tutorialspoint.com/cprogramming/c_function_call_by_reference.htm //The call by reference method of passing arguments to a function copies //the address of an argument into the formal parameter. Inside the function, //the address is used to access the actual argument used in the call. //It means the changes made to the parameter affect the passed argument. //We use an example...
modify the code for timer_test_02.c to allow the time delay between events to be pseudo- random exponential, with a mean time between arrivals of 0.1 second. Change the limit in the time_stamps() function from 5 time-stamps to 10, so that the mean run-time will be about 10*0.1 = 1.0 seconds. Once this is working, you should be able to generate 10 events with a pseudo-random exponential arrival process. The code is: #include <stdio.h> #include <stdint.h> #include <time.h> #include <unistd.h> #include...
IN C Programming #include<stdio.h> #include<stdlib.h> typedef struct nodestruct { int item; struct nodestruct *next; } Node; typedef struct { int size; // Number of items on user’s list Node *head, *tail; } List; //In addition to creating an empty list, this function will also create two dummy nodes; one for the head, and the other for the tail. List* createList(); //This function creates a node containing the provided item, then inserts it into the list pointed by the provided list...
In C please After exploring an old shipwreck, you recovered the captain's logs for an old pirate ship. It was stored on an old waterproof USB flash drive. (Who knew pirates were so technologically advanced!). After recovering the data, you see the log is stored as an array of strings: char* log[] = { "Yarr, it be the first day since we set sail.", "We be now deep in the seas. Not a soul fer miles.", "Blimey! There been movement...