Question

In: Computer Science

Write C code to create a structure called time_of_day, which stores the current time in hours,...

  1. Write C code to create a structure called time_of_day, which stores the current time in hours, minutes, and seconds. All the fields should be integers except for seconds, which should be a floating point value.
  2. Write a C function called check_time, which takes a pointer to a time_of_day structure as input, and return 1 if the time is valid (0 to 23 hours, 0 to 59 minutes, 0 to 59.999999 seconds) and 0 otherwise. Assume that times are stored in 24 hour format, with 00:00:00 being midnight and 23:59:59.9999 being the last millisecond of the day.
  3. Write a main program which reads a time from the user in the normal hh:mm:ss.sss format and stores it in a time_of_day structure. Your program should then call the check_time function to determine if it is a valid time or not, and display "valid time" or "invalid time" to the screen.

Solutions

Expert Solution

#include<stdio.h>
#include<conio.h>
struct time_of_day
{
   int Hour;
   int Minute;
   float Second;
};
int check_time( time_of_day *t1)
{ int Flag=1;
if (t1->Hour<0 || t1->Hour>23)
   {
   Flag=0;
   }
else if (t1->Minute<0 || t1->Minute>59)
   {
   Flag=0;
   }
else if (t1->Second<0 || t1->Second>59.999999)
   {
   Flag=0;
   }
return Flag;
}

void main()
{
   struct time_of_day T;
   clrscr();
   printf("\nEnter the Hour :");
   scanf("%d",&T.Hour);
   printf("\nEnter the Minute:");
   scanf("%d",&T.Minute);
   printf("\nEnter the Second:");
   scanf("%f",&T.Second);
   int R=check_time(&T);
   if(R==1)
   printf("VALID TIME");
   else
   printf("INVALID TIME");
   getch();
}


Related Solutions

Written in C code: Using a structure called person, write a C function called compare_age that...
Written in C code: Using a structure called person, write a C function called compare_age that takes two person structure pointers as input and returns 1 if the first person is older, -1 if the second person is older, or 0 if they have exactly the same birthday. Hint: Compare the years first, then if equal compare months, if they are equal compare days. The structure called person should contain the following; has fields for name (50 char array), dateOfBirth...
Part 2 Write a C code to create a user defined function called RecArea that will...
Part 2 Write a C code to create a user defined function called RecArea that will calculate the area of a rectangle. Call the function to print the area of the rectangle on the screen. Note: The user will enter the length and width of a rectangle (decimal values, float) and you Part 3 (Continue on part 2) Create another user defined function called TriArea that will calculate the area of a triangle. Print the area of the rectangle on...
Create a C structure which stores information about a student. Each student should be represented by...
Create a C structure which stores information about a student. Each student should be represented by a student ID (integer), first name, last name, day, month and year of birth, and program code (string). Write a C program which creates an array of 100 of these structures, then prompts the user to enter data from the keyboard to fill the array. If an ID of 0 is entered, data entry should finish, and the list of students should be printed...
Write a C++ code that can convert time into hours, minutes, seconds. It can accept (seconds),...
Write a C++ code that can convert time into hours, minutes, seconds. It can accept (seconds), (minutes, seconds), (hours, minutes, seconds) The input can be written in main It should produce the following output: (67.4, 14, 5) is 67 Hours, 38 Minutes, 5 Seconds (127.86) is 0 Hours, 2 Minutes, 8 Seconds (-3, 73, 2) is -1 Hours, -46 Minutes, -58 Seconds
Create a C structure which stores information about a book. Each book should have the following...
Create a C structure which stores information about a book. Each book should have the following data: Author (string), Title (string), Publisher (string), Year (int), ISBN (int), Genre (string), Price (float). Write a C program which creates an array of 100 of these structures, then prompts the user to enter book information to fill the array. The data entry should stop when the array is full, or when the user enters 0 for the ISBN.
use c++ language. Create a structure called time. Its three members, all type int, should be...
use c++ language. Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the 1st token to hours, 2nd token to minutes, and 3rd token to seconds member variables of...
C++ Write a program to create a linked list which stores the details of employees(Employee number,...
C++ Write a program to create a linked list which stores the details of employees(Employee number, employee name, rate, hours worked). Create a menu to manage the emoployee data. MENU 1. ADD EMPLOYEE DETAILS 2. DELETE EMPLOYEE 3. SEARCH EMPLOYEE 4. PRINT EMPLOYEE PAYROLL 5. EXIT When the user selected option #4 the program should print the following pay report for each employee: EmpNo.     Name      Rate    Hours    Regular Pay      Overtime Pay     Gross Pay Any hours worked above 40 hours are...
Create a class called Student which stores • the name of the student • the grade...
Create a class called Student which stores • the name of the student • the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into the grade field. • Calculate the...
Write in Java * Create a new client class called Plants.java * Write code in the...
Write in Java * Create a new client class called Plants.java * Write code in the Plants class that solves problems 1,2,3 and 4 * Include the solutions of the different problems in different methods and call them from the main method * Use the BagInterface.java and ArrayBag.java, but do not add any code Problem 1: Create a bag plantsCart, which holds the following spring seedlings(represented by String) Rose, Daisy, Cabbage, Cucumber, Carrot, Cucumber, Daffodil, Daisy, Rose, Iris, Rose, Spinach....
-------------- WRITE IN C# ------------------- Create two subclasses called outpatient and inpatient which inherit from the...
-------------- WRITE IN C# ------------------- Create two subclasses called outpatient and inpatient which inherit from the patient base class. The outpatient class has an additional data field called doctorOfficeID and the inpatient class has an additional data item called hospitalID. Write a main method that creates inpatient and outpatient objects. Sets data for these objects and display the data.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT