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

Create a program that generates a simple day schedule with 3 activities, based u

ID: 3848376 • Letter: C

Question

Create a program that generates a simple day schedule with 3 activities, based upon the following inputs:

1-Activity Name (Keep it to a short word if you are using tabs, or in the length range using a .format() or .printf() statement)

2-Activity Starting Hour (in military time, which is a 24 hr clock, acceptable numbers 1-24 – do data validation)

3-Activity Ending Hour (in military time also) – perform a validity check to be sure that this number is greater than or equal to Starting Hour

4-Hints:

.Activities do not have to be entered in chronological order, but there should be no overlapping. Start/End numbers are inclusive.

.Utilize a nested loop, the outer loop goes from 1..24 for the hour of day.

.For each iteration of the outer loop, have an inner for() loop that goes from col=1 to col=3

.Use a switch statement to test for the case of 1, 2, and 3 to represent each of 3 cols/activities. Then, under the case, use an if statement to test if the hour falls between the start/end time for this activity. Then perform the output of the activity into the appropriate column (tabs work here, or you can use the .printf() or .format() method, which is preferred. If using tabs, you can tab out when processing activity 1 - two tabs, activity 2 - three tabs, and activity 3 - four tabs, for example.

.Perform data validation to prevent bad input.

.This program requires at least 3 variables for each of the 3 activities you are logging, and 2 loop counter variables.

.Arrays are not necessary, but if you want to use them you may.

Sample Output:

Enter activity 1 name: Eat

Enter activity 1 starting hour: 12

Enter activity 1 ending hour: 14

Enter activity 2 name: Sleep

Enter activity 2 starting hour: 1

Enter activity 2 ending hour: 9

Enter activity 3 name: School

Enter activity 3 starting hour: 16

Enter activity 3 ending hour: 22

My Schedule

Hour     Act1      Act2      Act3

1                      Sleep

2                      Sleep

3                      Sleep

4                      Sleep

5                      Sleep

6                      Sleep

7                      Sleep

8                      Sleep

9                      Sleep

10

11

12         Eat

13         Eat

14         Eat

15

16                                 School

17                                 School

18                                 School

19                                 School

20                                 School

21                                 School

22                                 School

23

24

Explanation / Answer

Code:
#include <stdio.h>
#include <stdlib.h>

/*
program to generate simple schedule for 24 hours
program name: schedule.c
*/

/* function prototype */
void validate(int, int);

int main()
{
   /* declaring variables */
   char act1[30], act2[30], act3[30];
   int act1_start, act1_end, act2_start, act2_end, act3_start, act3_end;
   int col, hour;

   /* getting activity and starting, ending hour information from the user */
   printf(" Enter activitiy 1 name: ");
   scanf("%s", act1);
   printf(" Enter activity 1 starting hour: ");
   scanf("%d", &act1_start);
   printf(" Enter activity 1 ending hour: ");
   scanf("%d", &act1_end);  
   validate(act1_start, act1_end);
   printf(" Enter activitiy 2 name: ");
        scanf("%s", act2);
        printf(" Enter activity 2 starting hour: ");
        scanf("%d", &act2_start);
        printf(" Enter activity 2 ending hour: ");
        scanf("%d", &act2_end);
        validate(act2_start, act2_end);
   printf(" Enter activitiy 3 name: ");
        scanf("%s", act3);
        printf(" Enter activity 3 starting hour: ");
        scanf("%d", &act3_start);
        printf(" Enter activity 3 ending hour: ");
        scanf("%d", &act3_end);
        validate(act3_start, act3_end);

   /* printing the schedule */
   printf(" My Schedule ");
   printf(" Hour Act1 Act2 Act3");
   for(hour = 1; hour <= 24; hour++){
       printf(" %d", hour);
       for(col = 1; col <= 3; col++){
           /* checking if the hour falls below any of the activities */
           switch(col){
               case 1:
                   if(hour >= act1_start && hour <= act1_end) printf(" %s", act1);
                   break;
               case 2:
                   if(hour >= act2_start && hour <= act2_end) printf(" %s", act2);
                   break;
               case 3:
                   if (hour >= act3_start && hour <= act3_end) printf(" %s", act3);
                   break;
           }
       }
   }
   printf(" ");

   return 0;
}

/* function to validate if the start and end hours are <=24 and start date less than end date */
void validate(int a, int b)
{
   /* checking if start and end hours are >= 1 and <= 24 */
   if( a >= 1 && a <= 24 && b >= 1 && b <= 24){
       /* checking if ending hour is less than starting hour */
       if(b < a){
           printf(" End hour should be more than start hour ");
           exit(1);
       }
   }  
   else{
       printf(" start and end hours should be from 1-24 hours ");
       exit(1);
   }
}

Execution and output:
Unix Terminal> ./a.out

Enter activitiy 1 name: Eat

Enter activity 1 starting hour: 12

Enter activity 1 ending hour: 14

Enter activitiy 2 name: Sleep

Enter activity 2 starting hour: 1

Enter activity 2 ending hour: 9

Enter activitiy 3 name: School

Enter activity 3 starting hour: 16

Enter activity 3 ending hour: 22

My Schedule

Hour   Act1   Act2   Act3
1       Sleep
2       Sleep
3       Sleep
4       Sleep
5       Sleep
6       Sleep
7       Sleep
8       Sleep
9       Sleep
10
11
12   Eat
13   Eat
14   Eat
15
16           School
17           School
18           School
19           School
20           School
21           School
22           School
23
24


Unix Terminal> ./a.out

Enter activitiy 1 name: Eat

Enter activity 1 starting hour: 10

Enter activity 1 ending hour: 9

End hour should be more than start hour
Unix Terminal> ./a.out

Enter activitiy 1 name: Sleep

Enter activity 1 starting hour: 20

Enter activity 1 ending hour: 24

Enter activitiy 2 name: Eat

Enter activity 2 starting hour: 11

Enter activity 2 ending hour: 14

Enter activitiy 3 name: Run

Enter activity 3 starting hour: 6

Enter activity 3 ending hour: 4

End hour should be more than start hour

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