Question

Create a header file timer.h containing the following functions (you can have more functions, but the...

Create a header file timer.h containing the following functions (you can have more functions, but the below ones are required. Do not modify the given function signatures.

// Initialize the timer with the user-provided input
void initTimer(ClockType *clock, int minutes, int seconds);

// Run the timer -- print out the time each second
void runTimer();

// Clean up memory (as needed)
void cleanTimer(ClockType  *clock);

Create a file timer.c and implement (at least) these three functions and any other functions you find helpful. Also, create testTimer.c with your main function implementation for this task.

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

/*
* timer.h file
*/

#ifndef CLOCK_TYPE_H
define CLOCK_TYPE_H
#include <stdio.h>
#include <unistd.h>

typedef struct ClockType
{
    int hr;
    int min;
    int sec;
}   ClockType;



void initTimer(ClockType *c, int minutes, int seconds);

void runTimer(ClockType *c);

void cleanTimer(ClockType *c);

#endif

/* timer.h file ends here */


/*
 * timer.c fle
 */

#include "timer.h"

// function to set timer

void initTimer(ClockType *c, int minutes, int seconds)
{
   c->hr = 0;
   c->min = minutes;
   c->sec = seconds;
}

// function to display current timer with every second
void runTimer(ClockType *c)
{
   int minToStop = 60; // put here in seconds
   
   int i;
   
   for(i = 0; i < minToStop; i++)
   {
      usleep(1000000);
      printf("Time (HH:MM:SS) - %d:%d:%d ",c->hr, c->min, c->sec);
      
      c->sec = c->sec + 1;
      
      if(c->sec == 60)
      {
         c->sec = 0;    
         c->min = c->min + 1;
      }
   }
}

// function to reset the timer
void cleanTimer(ClockType *c)
{
   c->hr = 0;
   c->min = 0;    
   c->sec = 0;
}

/* timer.c files ends here    */


/*
 * testTimer.c File
 */

#include <stdio.h>
#include "timer.h"

int main()
{
   ClockType c;
   initTimer(&c, 15, 30);
   runTimer(&c);
   cleanTimer(&c);    
   return 0;
}

/* testTimer.c ends here */


 

Note: For queries, drop a comment.

Add a comment
Know the answer?
Add Answer to:
Create a header file timer.h containing the following functions (you can have more functions, but the...
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
  • Using C Please comment Part 1: BST Create a link based Binary Search tree composed of a Node and a Tree struct. You should have a header file, BST.h, with the following: o Node struct containing...

    Using C Please comment Part 1: BST Create a link based Binary Search tree composed of a Node and a Tree struct. You should have a header file, BST.h, with the following: o Node struct containing left, right, and parent pointers, in addition to holding an Data struct value Tree struct containing a pointer to the root of the tree A function declaration for a function that allocates a tree, and initializes the root to NULL o o o A...

  • IN C++ MUST INCLUDE HEADER FILE, IMPLEMENTATION FILE, AND DRIVER FILE. IN C++ Create a header...

    IN C++ MUST INCLUDE HEADER FILE, IMPLEMENTATION FILE, AND DRIVER FILE. IN C++ Create a header and implementation file to define an apartment class. Create a driver program to test the class, and create a make file to compile the driver program. Create two files called apartment.h and appartmentImp.cpp along with creating a driver program named testApartment.cpp containing the main function. Program Requirements: • Class attributes should include integers for number of rooms, monthly rent, and square feet, as well...

  • Programming Concepts cin/cout variables/types Functions Reference structs Task Summary: For this first Quest you I have...

    Programming Concepts cin/cout variables/types Functions Reference structs Task Summary: For this first Quest you I have set up a program in Visual Studio that will use operation between fractions. I have written a basic code example that does all the resources that you need to follow. Your job is to complete the exercises presented below in quest2.cpp. For this assignment you will learn and demonstrate how to: Work with functions use Past-by-Value and Past-by-Reference. use structs. use cin to get...

  • Create a Namespaces.h header file containing a namespace declaration yourname. The declaration should include a method...

    Create a Namespaces.h header file containing a namespace declaration yourname. The declaration should include a method with the signature void message (string, ostream &) that prints a string to the output stream. Create a testNamespaces.cpp that uses the yourname namespace, and invokes the message() method with a message of your choice and cout as input parameters. NOTE: You should not use the “using namespace” directive in your header file. Modify Namespaces.h to define PI as 3.1415, and MYNAME as your...

  • The object manager's interface is given by the file ObjectManager.h and the implementation will be in...

    The object manager's interface is given by the file ObjectManager.h and the implementation will be in the file ObjectManager.c. Your task is to implement the functions required for the object manager. This includes all the functions listed in ObjectManager.h. #ifndef _OBJECT_MANAGER_H #define _OBJECT_MANAGER_H #ifndef MEMORY_SIZE #define MEMORY_SIZE 1024*512 #endif #define NULL_REF 0 typedef unsigned long Ref; // This function trys to allocate a block of given size from our buffer. // It will fire the garbage collector as required. //...

  • I am working in c++. My program requires me to use a header file that is...

    I am working in c++. My program requires me to use a header file that is provided. I must use this header file and create 5 methods: 2 constructors, 2 accessors and this operation* on a 4x4 matrix. Matrix has 16 floating point values that must be entered by user. The Two operator functions: i*t; and t+i, multiply identity (i) matrix by user input value matrix and second function add identity (i) plus user input matrix transform. These two operations...

  • For this homework, you will use multiple source files. The file descriptions are below. Make sure...

    For this homework, you will use multiple source files. The file descriptions are below. Make sure to use the correct include statements in all files. Submit only the .c and .h files. multiple.h - This file will include the function prototypes for two functions. Include the prototypes within an include guard. void printUpTriangle(int x); void printDownTriangle(int x); main.c - This file will include the main function. In main, prompt the user for a positive integer and then call both functions...

  • Implement the Message class using a header and implementation file named Message.h and Message.cpp respectively. In...

    Implement the Message class using a header and implementation file named Message.h and Message.cpp respectively. In addition to the two Message class files, you must write a driver. The driver must create a Message array that is capable of holding 100 messages (make sure that you don’t exceed the maximum number of Messages). It then must read all Messages from a file named messages.txt (ordered date\n sender\n recipient\n body\n), sort the Messages based on date, find a Message based on...

  • 1. Your project will include the following three files: A header file: dynamicArray.h that includes a...

    1. Your project will include the following three files: A header file: dynamicArray.h that includes a list of function prototypes as enumerated in the next section. An implementation file: dynamicArray.cpp that implements the functions declared in the header file. A test driver file: dynamicArray-main.cpp that includes the main() function so that you can test all the functions you've implemented above. 2. The header file dynamicArray.h will include the following list of functions: constructing a dynamic array of the specified size...

  • C++ The following task is to be submitted with one Header file that contains all of...

    C++ The following task is to be submitted with one Header file that contains all of the classes and two CPP or source files that contain the function definitions for the classes and the main. 1. Take what we did in class and create a File class for easy reading and writing access. The constructor should take a string and should open a file. 2. Create a function for writing bytes to a file. The function should be a template...

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