0% found this document useful (0 votes)
42 views8 pages

Plant Growth Monitoring System

The document describes a Plant Growth Monitoring System implemented in C, which calculates the daily growth rate, the number of days required to reach a target height, and evaluates if the growth rate is within an expected range. It includes functions for these calculations and prompts the user for input regarding the plant's height and growth parameters. The program also allows for simulating additional growth days and recalculating the relevant metrics based on user-provided data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views8 pages

Plant Growth Monitoring System

The document describes a Plant Growth Monitoring System implemented in C, which calculates the daily growth rate, the number of days required to reach a target height, and evaluates if the growth rate is within an expected range. It includes functions for these calculations and prompts the user for input regarding the plant's height and growth parameters. The program also allows for simulating additional growth days and recalculating the relevant metrics based on user-provided data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Plant Growth Monitoring System

Code
#include <stdio.h>

#include <stdlib.h>

// creating a Function to calculate daily growth rate

float calculate_growth_rate(float initial_height, float current_height, int days) {

return (current_height - initial_height) / days;

// Creating a function to calculate the number of days required to reach the target height

int calculate_days_to_target(float current_height, float target_height, float growth_rate) {

return (target_height - current_height) / growth_rate;

// Creating a function to evaluate if the growth rate is within the expected range

void evaluate_growth_rate(float growth_rate, float min_growth, float max_growth) {


if (growth_rate < min_growth) {

printf("Alert: Growth rate is below the expected range!\n");

} else if (growth_rate >= min_growth && growth_rate <= max_growth) {

printf("Plant is growing at the expected rate.\n");

} else {

printf("Note:Growth rate is above the expected range!\n");

int main() {

float initial_height;

float current_height;

float target_height;

float min_growth;

float max_growth;

float growth_rate;

int days;

int additional_days;

float estimated_growth_rate;

// getting the inputs

printf("Enter the initial height of the plant (cm): ");

scanf("%f", &initial_height);

printf("Enter the current height of the plant (cm): ");

scanf("%f", &current_height);

printf("Enter the number of days since measurements started: ");

scanf("%d", &days);

printf("Enter the expected growth range (min and max daily growth in cm/day): ");

scanf("%f %f", &min_growth, &max_growth);

printf("Enter the target height of the plant (cm): ");

scanf("%f", &target_height);

// Calculating the daily growth rate

growth_rate = calculate_growth_rate(initial_height, current_height, days);


// Displaying the results

printf("Daily Growth Rate: %.2f cm/day\n", growth_rate);

evaluate_growth_rate(growth_rate, min_growth, max_growth);

// Calculating days required to reach the target height

int days_to_target = calculate_days_to_target(current_height, target_height, growth_rate);

printf("Days required to reach the target height: %d days\n", days_to_target);

printf("Simulate growth for additional days? (Yes: 1, No: 0): ");

scanf("%d", &additional_days);

if (additional_days == 1) {

printf("Enter the number of additional days: ");

scanf("%d", &additional_days);

printf("Enter the estimated daily growth rate (cm/day): ");

scanf("%f", &estimated_growth_rate);

// Updating the ptants height

current_height += additional_days * estimated_growth_rate;

// Recalculating growth rate and days to target

growth_rate = calculate_growth_rate(initial_height, current_height, days + additional_days);

printf("Updated Plant Height: %.2f cm\n", current_height);

printf("Daily Growth Rate: %.2f cm/day\n", growth_rate);

evaluate_growth_rate(growth_rate, min_growth, max_growth);

days_to_target = calculate_days_to_target(current_height, target_height, growth_rate);

printf("Days required to reach the target height: %d days\n", days_to_target);


}

return 0;

screenshot
Output

Explanation of the code

 First we include the preprocessor libraries


#include <stdio.h>
#include <stdlib.h>
 Then before the main function we created the
functions we needed to the programme
 calculate_growth_rate
 calculate_days_to_target
 evaluate_growth_rate
 Then the main functions come we first declare our
variables
 float initial_height;
 float current_height;
 float target_height;
 float min_growth;
 float max_growth;
 float growth_rate;

 int days;
 int additional_days;

 float estimated_growth_rate;

 Then we get the user inputs


printf("Enter the initial height of the plant (cm): ");
scanf("%f", &initial_height);
printf("Enter the current height of the plant (cm): ");
scanf("%f", &current_height);
printf("Enter the number of days since measurements started: ");
scanf("%d", &days);
printf("Enter the expected growth range (min and max daily growth in cm/day): ");
scanf("%f %f", &min_growth, &max_growth);
printf("Enter the target height of the plant (cm): ");
scanf("%f", &target_height);

 Then by the given inputs calculations are done


according to the formulas given
 Control structre If is used to check wether the
user simulate growth for additional days.
 == is used to check the user selection is equal
as the statement
 Finaly the growth is recalculated and
displayed to the user

Name- A.P.A.U. SANDEEPANI


INDEXNO-BST/23/092

You might also like