Question: ---------------------- PingPongTest.c // // main.c // #include #include /**************************************************** Program PingPong is designed to demonstrate functions which call each other until a condition is met.

----------------------
PingPongTest.c
// // main.c // #include#include /**************************************************** Program PingPong is designed to demonstrate functions which call each other until a condition is met. It is a demonstration of recursion. Function Ping starts the process, receiving an integer from the test Main. It will call Pong with the integer reduced by one if the integer is positive. Pong will reduce the integer and call Ping if the number is positive. *****************************************************/ #include "PingPong.h" #include // the test main executes the PingPong processing for 5 iterations. int main() { // bounce 10 times before returning int loop = 5; printf ("Kicking off the PingPong for %d iterations ", loop); // kick off PingPong Ping (loop); printf ("Back from the PingPong iterations. "); return 0; }
PingPong.c ?
// // PingPong.c // #include "PingPong.h" #include/**************************************************** Function: Ping Summary: Ping is responsible for logging its received value (val) and conditionally calling Pong. After logging the received input, it passes the information to Pong with the input value decremented by 1 if the input was positive. When the function returns, it provides an int with the decremented value *****************************************************/ int Ping (int val) { // log the incoming value printf ("in Ping with value %d ", val); // Make the call to Pong only if the decemented value has not gone negative if (--val >= 0) Pong(val); return val; } /**************************************************** Function: Pong Summary: Pong is responsible for logging its received value (val) and conditionally calling Ping. After logging the received input, it passes the information to Ping with the input value decremented by 1 if the input was positive. When the function returns, it provides an int with the decremented value *****************************************************/ int Pong (int val) { // log the incoming value printf ("in Pong with value %d ", val); // Make the call to Ping only if the decemented value has not gone negative if (--val >= 0) Ping(val); return val; }
PingPong.h
// // PingPong.h // #ifndef PingPong_h #define PingPong_h // Ping receives a val, decrements it and conditionally calls Pong int Ping (int val); // Pong receives a val, decrements it and conditionally calls Ping int Pong (int val); #endif /* PingPong_h */
Problem 1 This problem is designed to make sure you can write a typedef for a struct that contains two integers that represent hours and minutes. The demonstration will consist of writing a function that receives two instances of the struct using the typedef and computes the difference in minutes between the two times The Solution Requirements Your solution will entail writing a function called TimeDifference and a test main that demonstrates that you can compute the time difference in minutes between the two times TimeDifference is a function that receives a start time and end time that are structs of your creation. You need to compute the difference in minutes between the start time and end time returning the number of minutes to your test main. If the end time is less than the start time it means we have rolled over by a single day and you will need to correct the difference to accommodate the time rollover. Time will be in 24 hour format, rather than AM and PM This is easier than you might think. What would happen if you determined the start and end times in total minutes? If you subtracted the start total minutes from the end total minutes, wouldn't you have the difference in minutes? If the result was less than zero, wouldn't it mean that you have rolled over a day and need to add the total minutes in a day to the difference you computed to get the correct answer? Of course, you can use any other strategy you want! Your Test Main must: 1. Create two variables of a structure (using the typedef). named mine TheStart and TheEnd) TheStart contains 11 hours, 52 minutes TheEnd contains 14 hours, 43 minutes 2. 3. 4. Print out the contents of TheStart and TheEnd Call TimeDifference (TheStart, TheEnd). On return, print out the number of minutes Call TimeDifference (TheEnd, TheStart). On return, print out the number of minutes For your convenience, here is the output of my program TheStart is HH:11 MM:52 TheEnd is HH:14 MM:43 time from TheStart to TheEnd is: 171 time from TheEnd to TheStart is: 1269 Notes 1. There is no printing anywhere but from your main() 2. You must submit the code and the output from program execution
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
