Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please make a flowchart for me for the C Program below: #include #define MAX_NAME_LENGTH 50 #define MAX_WEEKS 4 #define MAX_DAYS_IN_WEEK 7 #define MAX_FILENAME_LENGTH 50 #define

Please make a flowchart for me for the C Program below:

#include #define MAX_NAME_LENGTH 50 #define MAX_WEEKS 4 #define MAX_DAYS_IN_WEEK 7 #define MAX_FILENAME_LENGTH 50 #define MAX_FOOD_ITEMS 5 #define MAX_EXERCISE_TYPES 6 #define MAX_MONTHS 12 const char *foodList[MAX_FOOD_ITEMS] = {"Fruits", "Vegetables", "Protein", "Carbohydrates", "Dairy"}; const char *ExerciseType[MAX_EXERCISE_TYPES] = {"Running", "Cycling", "Swimming", "Weight Training", "Yoga", "Rest"}; const char *MONTHLY_SUMMARY_FILENAME = "MonthlySummary.txt"; struct PersonalHealthDetails { char name[MAX_NAME_LENGTH]; char dateOfBirth[12]; char sex[10]; float weight; float height; char healthGoals[100]; }; typedef struct HealthDaily { char date[50]; int Food; int Exercise; float sleep; int calories; float Eduration; } HealthDaily; struct WeeklyHealthSummary { HealthDaily entries[MAX_DAYS_IN_WEEK]; int numDaysEntered; char filename[MAX_FILENAME_LENGTH]; }; struct MonthlyHealthSummary { int totalCalories; float totalSleep; float totalExerciseDuration; }; struct PersonalHealthDetails personalHealthDetails; struct WeeklyHealthSummary weeklySummaries[MAX_WEEKS]; struct MonthlyHealthSummary monthlySummaries[MAX_MONTHS]; int numWeeksEntered = 0; // Function prototypes void enterPersonalHealthDetails(); void displayHealthDetails(); void updateHealthDetails(); void enterHealthweekly(); void displayHealthweekly(); void generateWeeklySummary(int week); void generateMonthlySummary(); void displayMonthlyHealthSummary(); void saveMonthlySummaryToFile(); void readMonthlySummaryFromFile(); void updateMonthlySummaryToFile(); int avgCalorieIntake[MAX_WEEKS] = {0}; float avgSleep[MAX_WEEKS] = {0}; float avgExerciseDuration[MAX_WEEKS] = {0}; int main() { int choice; do { printf(" Health Tracker Menu "); printf("1. Enter personal health details "); printf("2. Display personal health details "); printf("3. Update personal health details "); printf("4. Enter Weekly Health Report "); printf("5. Generate Monthly Health Summary "); printf("6. Exit "); printf(" Enter your choice: "); if (scanf("%d", &choice) != 1) { while (getchar() != ' '); continue; // Restart the loop } switch (choice) { case 1: enterPersonalHealthDetails(); break; case 2: displayHealthDetails(); break; case 3: updateHealthDetails(); break; case 4: do { enterHealthweekly(); displayHealthweekly(); // Ask the user if they want to continue for the next week char continueInput; printf(" Do you want to continue for the next week? (y/n): "); scanf(" %c", &continueInput); if (continueInput != 'y' && continueInput != 'Y') { break; } } while (1); // Continue until the user decides to stop break; case 5: generateMonthlySummary(); displayMonthlyHealthSummary(); break; case 6: printf("Exit the program. "); break; default: printf("Please try again. "); } } while (choice != 6); return 0; } void enterPersonalHealthDetails() { FILE *HealthDetails; if ((HealthDetails = fopen("Health Details.txt", "a")) == NULL) { printf("File cannot be opened "); } else { printf(" Enter your name: "); scanf("%c", personalHealthDetails.name); fgets(personalHealthDetails.name,MAX_NAME_LENGTH,stdin); printf("Enter your date of birth (DD/MM/YYYY): "); scanf("%s", personalHealthDetails.dateOfBirth); printf("Enter your sex: "); scanf("%s", personalHealthDetails.sex); printf("Enter your weight (in kg): "); scanf("%f", &personalHealthDetails.weight); printf("Enter your height (in cm): "); scanf("%f", &personalHealthDetails.height); printf("Enter your health goals: "); scanf("%c", personalHealthDetails.healthGoals); fgets(personalHealthDetails.healthGoals,100,stdin); printf("Personal health details have been saved successfully! "); fprintf(HealthDetails, "%s\t%s\t%s\t%.2f\t%.2f\t%s ", personalHealthDetails.name, personalHealthDetails.dateOfBirth, personalHealthDetails.sex, personalHealthDetails.weight, personalHealthDetails.height, personalHealthDetails.healthGoals); } fclose(HealthDetails); } void displayHealthDetails() { printf(" Personal Health Details "); printf("Name: %s", personalHealthDetails.name); printf("Date of Birth: %s ", personalHealthDetails.dateOfBirth); printf("Sex: %s ", personalHealthDetails.sex); printf("Weight: %.2f kg ", personalHealthDetails.weight); printf("Height: %.2f cm ", personalHealthDetails.height); printf("Health Goals: %s", personalHealthDetails.healthGoals); } void updateHealthDetails() { printf(" Update Personal Health Details "); printf("Enter new weight (kg): "); scanf("%f", &personalHealthDetails.weight); printf("Enter new height (cm): "); scanf("%f", &personalHealthDetails.height); printf("Enter new health goals: "); scanf("%c", personalHealthDetails.healthGoals); fgets(personalHealthDetails.healthGoals,100,stdin); printf("Personal health details have been successfully updated. "); } void enterHealthweekly() { if (numWeeksEntered < MAX_WEEKS) { printf(" Enter daily health entries for Week %d: ", numWeeksEntered + 1); for (int day = 0; day < MAX_DAYS_IN_WEEK; ++day) { printf(" Enter the date today (DD/MM/YYYY): "); scanf("%s", weeklySummaries[numWeeksEntered].entries[day].date); printf("Choose a food item: "); for (int i = 0; i < MAX_FOOD_ITEMS; ++i) { printf("%d. %s ", i + 1, foodList[i]); } printf("Enter your choice (1-%d): ", MAX_FOOD_ITEMS); scanf("%d", &weeklySummaries[numWeeksEntered].entries[day].Food); weeklySummaries[numWeeksEntered].entries[day].Food--; printf("Choose an exercise type: "); for (int i = 0; i < MAX_EXERCISE_TYPES; ++i) { printf("%d. %s ", i + 1, ExerciseType[i]); } printf("Enter your choice (1-%d): ", MAX_EXERCISE_TYPES); scanf("%d", &weeklySummaries[numWeeksEntered].entries[day].Exercise); weeklySummaries[numWeeksEntered].entries[day].Exercise--; printf("Enter the exercise duration today (in minutes): "); scanf("%f", &weeklySummaries[numWeeksEntered].entries[day].Eduration); if (weeklySummaries[numWeeksEntered].entries[day].Eduration < 150) { printf("%1.2f (Below Recommended Limit) ", weeklySummaries[numWeeksEntered].entries[day].Eduration); } else if (weeklySummaries[numWeeksEntered].entries[day].Eduration <= 300) { printf("%1.2f (Recommended Limit Reached) ", weeklySummaries[numWeeksEntered].entries[day].Eduration); } else { printf("%1.2f (Exceeding Recommended Limit) ", weeklySummaries[numWeeksEntered].entries[day].Eduration); } printf("Enter the duration you slept today (in hours): "); scanf("%f", &weeklySummaries[numWeeksEntered].entries[day].sleep); if (weeklySummaries[numWeeksEntered].entries[day].sleep < 7) { printf("%1.2f (Insufficient Sleep) ", weeklySummaries[numWeeksEntered].entries[day].sleep); } else if (weeklySummaries[numWeeksEntered].entries[day].sleep <=9) { printf("%1.2f (Optimal Sleep) ", weeklySummaries[numWeeksEntered].entries[day].sleep); } else { printf("%1.2f (Excessive Sleep) ", weeklySummaries[numWeeksEntered].entries[day].sleep); } printf("Enter the calories consumed today: "); scanf("%d", &weeklySummaries[numWeeksEntered].entries[day].calories); if (weeklySummaries[numWeeksEntered].entries[day].calories < 800) { printf("%1.2d(Weight Loss) ", weeklySummaries[numWeeksEntered].entries[day].calories); } else if (weeklySummaries[numWeeksEntered].entries[day].calories >=800 && weeklySummaries[numWeeksEntered].entries[day].calories <=2400) { printf("%d1.2 (Weight Maintenance ", weeklySummaries[numWeeksEntered].entries[day].calories); } else { printf("%d1.2 (Weight Gain) ", weeklySummaries[numWeeksEntered].entries[day].calories); } } weeklySummaries[numWeeksEntered].numDaysEntered = MAX_DAYS_IN_WEEK; // Prompt for a filename and save the weekly data to a file printf(" Enter a filename to save the health weekly data: "); scanf("%s", weeklySummaries[numWeeksEntered].filename); FILE *weeklyFile = fopen(weeklySummaries[numWeeksEntered].filename, "a"); if (weeklyFile == NULL) { printf("Error opening file for writing. "); return; } fprintf(weeklyFile, "Week %d Health Data: ", numWeeksEntered + 1); for (int day = 0; day < MAX_DAYS_IN_WEEK; ++day) { fprintf(weeklyFile, "%s\t%d\t%d\t%.2f\t%.2f\t%d ", weeklySummaries[numWeeksEntered].entries[day].date, weeklySummaries[numWeeksEntered].entries[day].Food, weeklySummaries[numWeeksEntered].entries[day].Exercise, weeklySummaries[numWeeksEntered].entries[day].Eduration, weeklySummaries[numWeeksEntered].entries[day].sleep, weeklySummaries[numWeeksEntered].entries[day].calories); } fclose(weeklyFile); printf(" File has been saved successfully!!"); numWeeksEntered++; } else { printf("Maximum number of weeks reached. Cannot enter more data. "); } // Check if the maximum number of weeks is reached if (numWeeksEntered >= MAX_WEEKS) { printf("Maximum number of weeks reached. Cannot enter more data. "); return; } } void displayHealthweekly() { for (int week = 0; week < numWeeksEntered; ++week) { printf(" ----------------------------------------------Weekly Health Summary for Week %d:------------------------------------------------------------------- ", week + 1); printf("| Date | Food Items | Exercise Details | Exercise Duration (hour) | Sleep Duration (hour) | Calories Consumed (kcal) | "); printf("|------------|----------------------|------------------------|-----------------------------|--------------------------|--------------------------| "); // Iterate over the days within the current week for (int day = 0; day < weeklySummaries[week].numDaysEntered; ++day) { printf("| %-10s | %-20s | %-22s | %-15.2f | %-15.2f |%-18d | ", weeklySummaries[week].entries[day].date, foodList[weeklySummaries[week].entries[day].Food], ExerciseType[weeklySummaries[week].entries[day].Exercise], weeklySummaries[week].entries[day].Eduration, weeklySummaries[week].entries[day].sleep, weeklySummaries[week].entries[day].calories); } printf("-------------------------------------------------------------------------------------------------------------------------------------------------- "); } } void generateWeeklySummary(int week) { // Initialize totals for the week int totalCalories = 0; float totalSleep = 0; float totalEduration = 0; for (int day = 0; day < weeklySummaries[week].numDaysEntered; ++day) { // Accumulate values for each day in each week totalCalories += weeklySummaries[week].entries[day].calories; totalSleep += weeklySummaries[week].entries[day].sleep; totalEduration += weeklySummaries[week].entries[day].Eduration; } // Calculate averages for each day in the week int avgCaloriesPerDay = totalCalories / weeklySummaries[week].numDaysEntered; float avgSleepPerDay = totalSleep / weeklySummaries[week].numDaysEntered; float avgEdurationPerDay = totalEduration / weeklySummaries[week].numDaysEntered; // Accumulate average for the week avgCalorieIntake[week] = avgCaloriesPerDay; avgSleep[week] = avgSleepPerDay; avgExerciseDuration[week] = avgEdurationPerDay; } void generateMonthlySummary() { for (int week = 0; week < numWeeksEntered; ++week) { generateWeeklySummary(week); } for (int month = 0; month < MAX_MONTHS; ++month) { monthlySummaries[month].totalCalories = 0; monthlySummaries[month].totalSleep = 0; monthlySummaries[month].totalExerciseDuration = 0; for (int week = 0; week < numWeeksEntered; ++week) { monthlySummaries[month].totalCalories += avgCalorieIntake[week]; // Use the weekly averages monthlySummaries[month].totalSleep += avgSleep[week]; // Use the weekly averages monthlySummaries[month].totalExerciseDuration += avgExerciseDuration[week]; // Use the weekly averages } // Calculate averages monthlySummaries[month].totalCalories /= numWeeksEntered; monthlySummaries[month].totalSleep /= numWeeksEntered; monthlySummaries[month].totalExerciseDuration /= numWeeksEntered; } saveMonthlySummaryToFile(); } void displayMonthlyHealthSummary() { int month; // Read the monthly summary from the file readMonthlySummaryFromFile(); printf(" -----------------------------------------------Monthly Health Summary------------------------------------------------------------ "); printf("| Health Parameter | Week 1 | Week 2 | Week 3 | Week 4 | Total for Month| "); printf("|------------------------------------------|----------------|----------------|----------------|----------------|----------------| "); printf("| Average Calorie Intake (Calories) | %-15d| %-15d| %-15d| %-15d| %-15d| ", avgCalorieIntake[0], avgCalorieIntake[1], avgCalorieIntake[2], avgCalorieIntake[3], monthlySummaries[0].totalCalories); // Display average exercise duration printf("| Exercise Duration (Hours) | %-15.2f| %-15.2f| %-15.2f| %-15.2f| %-15.2f| ", avgExerciseDuration[0], avgExerciseDuration[1], avgExerciseDuration[2], avgExerciseDuration[3], monthlySummaries[0].totalExerciseDuration); // Display average sleep duration printf("| Average Sleep Duration (Hours per Night) | %-15.2f| %-15.2f| %-15.2f| %-15.2f| %-15.2f| ", avgSleep[0], avgSleep[1], avgSleep[2], avgSleep[3], monthlySummaries[0].totalSleep); printf("--------------------------------------------------------------------------------------------------------------------------------- "); printf("Month %d Health Summary: ",month + 1); printf("Average Calorie Intake: "); if (monthlySummaries[month - 1].totalCalories < 800) { printf("Average Total Calorie Intake %-d for the month of is in a not acceptable range ",monthlySummaries[0].totalCalories); } else if (monthlySummaries[month - 1].totalCalories >= 800 && monthlySummaries[month - 1].totalCalories <= 2400 ) { printf("Average Total Calorie Intake %-d for the month of is in acceptable range ",monthlySummaries[0].totalCalories); } else { printf("Average Total Calorie Intake %-d for the month of is in a not acceptable range ",monthlySummaries[0].totalCalories); } printf("Exercise Duration: "); if (monthlySummaries[month -1].totalExerciseDuration <2.5){ printf("The calculated monthly exercise duration of %-4.2f hours does not meet the minimum recommended weekly exercise duration. ",monthlySummaries[0].totalExerciseDuration); } else if (monthlySummaries[month - 1].totalExerciseDuration >= 2.5 && monthlySummaries[month - 1].totalExerciseDuration <= 5){ printf("The calculated monthly exercise duration of %-4.2f hours and has meet the minimum recommended weekly exercise duration. ",monthlySummaries[0].totalExerciseDuration); } else { printf("The calculated monthly exercise duration of %-4.2f hours does not meet the minimum recommended weekly exercise duration. ",monthlySummaries[0].totalExerciseDuration); } printf("Average Sleep: "); if (monthlySummaries[month -1].totalSleep <7){ printf("The calculated monthly average sleep duration of %-4.2f hours is below the recommended range of 7-9 hours per night for adults, suggesting insufficient sleep. ", monthlySummaries[0].totalSleep); } else if (monthlySummaries[month - 1].totalSleep >=7 && monthlySummaries[month - 1].totalSleep<=9){ printf ("The calculated monthly exercise duration of %-4.2f hours falls within the recommended range of 7-9 hours per night for adults, indicating a reasonable sleep pattern. ", monthlySummaries[0].totalSleep); } else { printf("The calculated monthly average sleep duration of %-4.2f hours exceeds the recommended range of 7-9 hours per night for adults, indicating an excessive sleep duration. ", monthlySummaries[0].totalSleep); } } void saveMonthlySummaryToFile() { FILE *monthlySummaryFile = fopen(MONTHLY_SUMMARY_FILENAME, "a"); if (monthlySummaryFile == NULL) { printf("Error opening file for writing. "); return; } for (int month = 0; month < MAX_MONTHS; ++month) { fprintf(monthlySummaryFile, "Month %d Summary: ", month + 1); fprintf(monthlySummaryFile, "Total Calories: %d ", monthlySummaries[month].totalCalories); fprintf(monthlySummaryFile, "Total Sleep: %.2f ", monthlySummaries[month].totalSleep); fprintf(monthlySummaryFile, "Total Exercise Duration: %.2f ", monthlySummaries[month].totalExerciseDuration); fprintf(monthlySummaryFile, "---------------------------------------- "); } fclose(monthlySummaryFile); } void readMonthlySummaryFromFile() { FILE *monthlySummaryFile = fopen(MONTHLY_SUMMARY_FILENAME, "r"); if (monthlySummaryFile == NULL) { printf("Error opening file for reading. Monthly summary file does not exist. "); return; } for (int month = 0; month < MAX_MONTHS; ++month) { fscanf(monthlySummaryFile, "Month %d Summary: ", &month); fscanf(monthlySummaryFile, "Total Calories: %d ", &monthlySummaries[month].totalCalories); fscanf(monthlySummaryFile, "Total Sleep: %f ", &monthlySummaries[month].totalSleep); fscanf(monthlySummaryFile, "Total Exercise Duration: %f ", &monthlySummaries[month].totalExerciseDuration); fscanf(monthlySummaryFile, "---------------------------------------- "); } fclose(monthlySummaryFile); } void updateMonthlySummaryToFile() { FILE *monthlySummaryFile = fopen(MONTHLY_SUMMARY_FILENAME, "a"); if (monthlySummaryFile == NULL) { printf("Error opening file for updating. "); return; } for (int month = 0; month < MAX_MONTHS; ++month) { fprintf(monthlySummaryFile, "Updated Summary for Month %d: ", month + 1); fprintf(monthlySummaryFile, "Total Calories: %d ", monthlySummaries[month].totalCalories); fprintf(monthlySummaryFile, "Total Sleep: %.2f ", monthlySummaries[month].totalSleep); fprintf(monthlySummaryFile, "Total Exercise Duration: %.2f ", monthlySummaries[month].totalExerciseDuration); fprintf(monthlySummaryFile, "---------------------------------------- "); } fclose(monthlySummaryFile); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions