Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Often we need to keep track of what we have spent our time on each day. In a bus

ID: 3740490 • Letter: O

Question

Often we need to keep track of what we have spent our time on each day. In a business, frequently you
might be working on several “billable” tasks at once, so it is important to keep track of how much time
you’ve spent on any one thing. This project creates a program that lets a person keep a daily task log in
a text file. The data in the log should be formatted in a readable way, and should contain the following
information: date, project, start time, end time, time spent (hours:minutes). Time spent should be
calculated by the program, not by the user. The user should be able to view the log before entering
more information, and should be able to add either one or many items.
Your project must have:
? Analysis – definition of the problem and pseudocode and/or flowchart
? Design – what questions will you ask, what will you do with the information?
? Code – clearly named variables
? Testing – evidence that you tested the program and it worked.
? Documentation – commented code, good style, self-documenting variable names.
This project covers:
? Program flow
? Conditionals
? Loops
? Text Files

Explanation / Answer

#include <stdio.h>

#include <time.h>

#include <signal.h>

struct status startTimer();

void stopTimer(int signum);

sig_atomic_t volatile timer_running = 1;

struct status

{

long hr;

long min;

long sec;

} ;

struct status startTimer()

{

time_t begin,end;

long totsec;

long v;

struct status ob;

begin= time(NULL);

signal(SIGINT, &stopTimer);

while(timer_running)

{

end = time(NULL);

totsec=difftime(end, begin);

ob.hr=totsec/3600;

v=totsec%3600;

ob.min=v/60;

ob.sec=v%60;

}

return ob;

}

void stopTimer(int signum)

{

if (signum == SIGINT)

timer_running = 0;

}

/////////////////////////////////////////////////////////////

int main()

{

char sentence[1000];

FILE *fptr;

fptr = fopen("log.txt", "a+");

if(fptr == NULL)

{

printf("Error!");

}

printf("Enter a name of the task: ");

gets(sentence);

printf("Press Control+C to terminate ");

fprintf(fptr,"Task Name: %s ", sentence);

  

time_t rawtime;

struct tm * timeinfo;

time ( &rawtime );

  

timeinfo = localtime ( &rawtime );

fprintf(fptr,"start time and date: %s ",asctime (timeinfo));

struct status ob = startTimer();

printf(" Completed- %ld : %ld : %ld " ,ob.hr, ob.min, ob.sec);

time_t rawtime2;

struct tm * timeinfo2;

time ( &rawtime2 );

  

timeinfo2 = localtime ( &rawtime2 );

fprintf(fptr," End Time and date : %s ", asctime(timeinfo2));

fprintf(fptr," Completed- %ld hours : %ld minutes: %ld seconds ",ob.hr, ob.min, ob.sec);

fclose(fptr);

system("pause");

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote