0% found this document useful (0 votes)
22 views4 pages

Assignment 1

The assignment requires students to develop a C program to simulate the management of a farm growing wheat, corn, rice, and soybean, incorporating environmental factors and resource management. Key components include reading resource costs from a file, managing nutrient levels, irrigation, and pest control, while calculating yield, revenue, and profit/loss. Students must follow specific coding guidelines, including using functions, avoiding hardcoding values, and ensuring code readability.

Uploaded by

cvholloway8651
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Assignment 1

The assignment requires students to develop a C program to simulate the management of a farm growing wheat, corn, rice, and soybean, incorporating environmental factors and resource management. Key components include reading resource costs from a file, managing nutrient levels, irrigation, and pest control, while calculating yield, revenue, and profit/loss. Students must follow specific coding guidelines, including using functions, avoiding hardcoding values, and ensuring code readability.

Uploaded by

cvholloway8651
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SCIT-EIS-UOW

CSCI291 Programming for Engineers


Autumn 2024
Assignment 1 - Due date: April 19 2025 at 11:55 pm
Coordinator/Lecturer: Prof. Philip O. Ogunbo.na; Rm. 3.113

General code notes


These are some general rules about what you should and shouldn’t do.

1. Your code must compile without warnings or errors on the command line in the terminal with
the command:

gcc -std=c11 precision_farm.c -Wall -lm -o precision_farm

2. Your code must be executable as:

precision_farm number_of_days number_of_plots(maximum 20) resource_cost.dat

3. The structure of the text file resource_cost.dat is as follows (per line):

Water: 0.002
Fertilizer: 0.5
Pesticide: 5.00
Wheat: 0.30; Corn: 0.20; Rice: 0.40; Soybean: 0.60;

and must be read from within your program.

4. Do not hardcode these arguments in your code because the values can be changed and values
in the cost f resources can change.

5. Within your code, be consistent in your tabbing style. We want readable code.

6. Include sensible volumes of commenting otherwise you will lose marks.

7. Use functions to divide the functionality of your code into sensible components.

8. You will lose a lot of marks for not using functions.

9. Use appropriate and sensible variable names.

10. Don’t leak memory.

1
Description
The aim of this assignment is to provide opportunity for students to develop and exercise their
knowledge of programming concepts in designing software that solves a simple near-real-life problem.
Such concepts include:
1. Data types (basic, enum, struct, union), expressions, files and operators

2. Loops, selection and functions

3. Standard math functions, random number generation

4. Pointers, arrays and memory management

Specifications
The purpose of this assignment is to simulate the management of a hypothetical farm with fields
of crops. Your program will use random number generator to simulate environmental factors and
implement algorithms to make efficient farming decisions based on current conditions and weather
forecast. The simulation is to be written in the C programming language. Ensure that you break
the logic of your code into functions callable from main. Your main will take arguments from the
command line as sated above uner ”General code notes”. Broadly speaking the narrative is as follows.
You are an engineer employed in a precision farming company that deploys sensors to monitor and
maintain a farm of crops. The objective is to make a profit from this business. Hence, the crops must
be monitored and maintained to maximise the yield. The farm specialises in wheat, corn, rice and
soybean, where average yield per hectare of the respective crops are : wheat - 2,880 kg/ha; corn -
10,000 kg/ha; rice - 4,500 kg/ha; soybean - 2,000 kg/ha (values obtained from Australian agricultural
data). Each crop has a maturity period: wheat - 120 days; corn 100 days; rice 150 days; soybean
110 days. If the simulation runs for fewer days than maturity, yield is scaled proportionally to the
maturity ratio. For each crop, the plot will have the following attributes:
• Crop type (use an enum for Wheat, Corn, Rice, Soybean)

• Number of plots per crop (randomized, up to 4 per crop)

• Soil moisture level

• Nutrient levels: Nitrogen (N), Phosphorus (P), Potassium (K), Iron (Fe)

• Pest probability and pest damage (i.e if probability is above a threshold assign a level of
damage). Use sensible values.

• Rain forecast; Amount of rain determines moisture level of the plot.

• Number of days grown

• Resource usage: water, fertilizer, pesticide

• Final yield and profit/loss calculation

1. Use random number generation (we have used this code in the lab practice) to simulate:

• Initial values for nutrients, moisture, pest probability, and rain forecast
• Daily environmental fluctuations (moisture loss, rainfall)
• Pest events and progression
• Random assignment of 1-4 plots per crop

2
2. Nutrient Monitoring and Depletion:

• Nutrient levels (N, P, K, Fe) should decrease each day following an exponential decay
model: nutrient today = nutrient yesterday × decay factor (try 0.99)
If any nutrient falls below a critical threshold (try 30%), fertilizer must be applied.
• Fertilizer restores all nutrients partially (try +20 units per application).

3. Rain forecast and irrigation:

• At the beginning of each day, the soil loses a random amount of moisture due to environ-
mental evaporation. This is between 5 and 10 units,
• If it is forecast that it will rain (i.e rain forecast == 1), a random amount of moisture is
added to the soil, between 5 and 15 units.

4. Decision Logic:

• Irrigate when moisture is less than a threshold (try 30%).


• If irrigation is needed, water is added to bring it back to the threshold. water needed =
(MOISTURE THRESHOLD - plot moisture) x 10
• Fertilize when any nutrient is deficient.
• Apply pesticide when pests are detected.
• Adjust final yield based on:
– Nutrient sufficiency (each nutrient below threshold reduces yield by 10%)
• Pest damage (reduces yield by 5% per damage level)
• Maturity ratio is (days grown / maturity days)

5. Economic Simulation:

• Resource Costs (to be read from a file called resource_cost.dat). So do not hardcode
this into your program as they can change in the file used to test your code.:
– Water: $0.002 per litre
– Fertilizer: $0.5 per kg
– Pesticide: $5.00 per litre
– Market Prices:
∗ - Wheat: $0.30/kg, Corn: $0.20/kg, Rice: $0.40/kg, Soybean: $0.60/kg
– Revenue = Yield × Market Price
– Profit/Loss = Revenue - Total Resource Cost

6. Output to display:

• Crop type, number of plots, days simulated vs. maturity, maturity ratio, final yield, total
water/fertilizer/pesticide used, total cost, revenue, and profit/loss.
• Clearly identify any plots that are unprofitable (i.e., profit ¡ 0). Example output is given
next.

7. Sample output:

Plot 1 - Crop: Wheat


Days Grown: 90 / 120
Yield: 1987.45 kg

3
Price: $0.30/kg
Revenue: $596.24
Expenditure: $115.00
Water Used: 500.00 L
Fertilizer Used: 10.00 kg
Pesticide Used: 1.00 L
Profit/Loss: $481.24

Plot 2 - Crop: Corn


Days Grown: 90 / 100
Yield: 4210.10 kg
Selling Price: $0.20/kg
Revenue: $842.02
Expenditure: $132.00
Water Used: 400.00 L
Fertilizer Used: 12.00 kg
Pesticide Used: 2.00 L
Profit/Loss: $710.02

Plot 3 - Crop: Soybean


Days Grown: 90 / 110
Yield: 1020.30 kg
Selling Price: $0.60/kg
Revenue: $612.18
Expenditure: $195.50
Water Used: 800.00 L
Fertilizer Used: 15.00 kg
Pesticide Used: 3.50 L
Profit/Loss: $416.68

Plot 4 - Crop: Rice


Days Grown: 90 / 150
Yield: 1720.00 kg
Selling Price: $0.40/kg
Revenue: $688.00
Expenditure: $701.00
Water Used: 650.00 L
Fertilizer Used: 20.00 kg
Pesticide Used: 6.00 L
Profit/Loss: -$13.00
>> This plot was unprofitable.

You might also like