A weather balloon is used to collect data on temperature and pressure at various
ID: 3596773 • Letter: A
Question
A weather balloon is used to collect data on temperature and pressure at various altitudes in the atmosphere. The balloon rises because the density of the helium in the balloon is lower than the density of the air that surrounds the balloon. As the balloon rises, the air around the balloon becomes less and less dense, and thus the rising of the balloon slows until it reaches a point of equilibrium During the day, the sun warms the helium in the balloon, which causes the helium to expand and become less dense; thus, the balloon rises to a higher altitude. During the night, the helium cools and becomes denser; thus, the balloon lowers to a lower altitude. The following day, the sun heats the helium again and the balloon rises to a new altitude. The change in the weather balloon altitude as a function of time can be approximated with a polynomial equation. Assume that the change in altitude in meters during the first 48 hours following the release of the balloon is represented by the equation: alt(t)=-0.12t^4+12t^3-380t^2+4100+220 where the unit of time t is hour. The corresponding velocity in meters per second of the balloon is represented by the equation v(t)=-0.48t^3+36t^2-760t+4100. Develop a program that requests from the user a range of time for t to calculate the change in altitude and velocity of the weather balloon. Twenty-five values of time/altitude/velocity over this range are displayed in a table. Respect the following guidelines during your development: a) Declare a structure variable in the main function which contains: The start time and end time of the period to calculate altitude and speed values, A computer array for storing time values, A computer array for storing altitude values, A computer array for storing velocity values, The values at the same index of the three arrays give the
Question 3 (15 marks) A weather balloon is used to collect data on temperature and pressure at various altitudes in the atmosphere. The balloon rises because the density of the helium in the balloon is lower than the density of the air that surrounds the balloon. As the balloon rises, the air around the balloon becomes less and less dense, and thus the rising of the balloon slows until it reaches a point of equilibrium During the day, the sun warms the helium in the balloon, which causes the helium to expand and become less dense; thus, the balloon rises to a higher altitude. During the night, the helium cools and becomes denser; thus, the balloon lowers to a lower altitude. The following day, the sun heats the helium again and the balloon rises to a new altitude. The change in the weather balloon altitude as a function of time can be approximated with a polynomial equation. Assume that the change in altitude in meters during the first 48 hours following the release of the balloon is represented by the equation alt(t) -0.12t4 +12t3-380t2+4100t+220 where the unit of time t is hour. The corresponding velocity in meters per second of the balloon is represented by the equation v(t)--0.48r3 + 36t2-760t +4100 alt(t) v(t) 5000.00 4000.00 3000.c0 2000.00 1000.c0 0.c0 16000.0 8000.00 6000.00 4000.00 2000.00 0.00 0.00 0.00 20.00 30.00 50.00 Develop a program that requests from the user a range of time for t to calculate the change in altitude and velocity of the weather balloon. Twenty-five values of time/altitude/velocity over this range are displayed in a table. Respect the following guidelines during your development a) Declare a structure variable in the main function which contains The start time and end time of the period to calculate altitude and speed values, A computer array for storing time values, A computer array for storing altitude values A computer array for storing velocity values, The values at the same index of the three arrays give the altitude and velocity at the time value. The arrays will contain 25 elements. Use a symbolic constant to represent this value . b) Obtain from the user the following data: The start and end time of the of the period to calculate altitude and speed values Verify that the two time values are between 0.0 and 48.0. Also verify that the start time proceeds the end time. Repeat the request from the user for the times values until they are both valid. Use a separate function (called by main) to get the user data. The function should receive the address of the variable structure declared in main within a pointer parameter to store the two time values . . c) Use a function to calculate all time/altitude/velocity points to fill the three arrays in the structure variable. The function shall also receive the address to the structure variable declared in main within a pointer parameter in order to update the arrays of the structure variable.Explanation / Answer
In this code, #define TOTAL 25 is the array size, weather is the structure used,
void input(double *ptr) takes input
void calculateValues(struct weather ptr) calculates time altitude and velocity
I hope its clear, If not you can comment below.
Kindly see the output below.
*************************************************************************************************
#include <stdio.h>
#include <stdlib.h>
#define TOTAL 25
struct weather
{
double starttime;
double endtime;
double time[TOTAL];
double altitude[TOTAL];
double velocity[TOTAL];
};
void input(double *ptr){
scanf("%lf",ptr);
}
void calculateValues(struct weather ptr){
double sample = (double)(ptr.endtime-ptr.starttime)/(TOTAL-1);
double t=ptr.starttime;
int i;
for(i=0;i<TOTAL;i++){
ptr.time[i]=t;
ptr.altitude[i]=(-0.12*t*t*t*t)+(12*t*t*t)+(-380*t*t)+(4100*t)+220;
ptr.velocity[i]=(-0.48*t*t*t)+(36*t*t)+(-760*t)+4100;
t=t+sample;
}
printf("Time Altitude Velocity ");
printf("-------------------------------------------- ");
for(i=0;i<TOTAL;i++){
printf("%.2lf %.2lf %.2lf ",ptr.time[i],ptr.altitude[i],ptr.velocity[i]);
}
}
int main()
{
struct weather data;
do {
data.starttime=-1;
while(data.starttime < 0.0 || data.starttime > 48.0){
printf("Enter start time: ");
input(&data.starttime);
}
data.endtime=-1;
while(data.endtime < 0.0 || data.endtime > 48.0){
printf("Enter end time: ");
input(&data.endtime);
}
if(data.starttime>data.endtime)
printf("Enter proper values, start time should be less than end time ");
}while(data.starttime>data.endtime);
calculateValues(data);
return 0;
}
*************************************************************************************************
Sample input 1
2
5
Sample output 1:
Enter start time:
2
Enter end time:
5
Time Altitude Velocity
--------------------------------------------
2.00 6994.08 2720.16
2.13 7329.26 2642.96
2.25 7654.86 2566.78
2.38 7971.00 2491.63
2.50 8277.81 2417.50
2.63 8575.42 2344.38
2.75 8863.95 2272.27
2.88 9143.53 2201.16
3.00 9414.28 2131.04
3.13 9676.33 2061.91
3.25 9929.80 1993.77
3.38 10174.81 1926.61
3.50 10411.49 1860.42
3.63 10639.96 1795.20
3.75 10860.33 1730.94
3.88 11072.73 1667.63
4.00 11277.28 1605.28
4.13 11474.09 1543.87
4.25 11663.29 1483.40
4.38 11844.98 1423.87
4.50 12019.29 1365.26
4.63 12186.34 1307.58
4.75 12346.22 1250.81
4.88 12499.07 1194.95
5.00 12645.00 1140.00
Sample input 2
5
2
2
5
Sample output 2:
Enter start time:
5
Enter end time:
2
Enter proper values, start time should be less than end time
Enter start time:
2
Enter end time:
5
Time Altitude Velocity
--------------------------------------------
2.00 6994.08 2720.16
2.13 7329.26 2642.96
2.25 7654.86 2566.78
2.38 7971.00 2491.63
2.50 8277.81 2417.50
2.63 8575.42 2344.38
2.75 8863.95 2272.27
2.88 9143.53 2201.16
3.00 9414.28 2131.04
3.13 9676.33 2061.91
3.25 9929.80 1993.77
3.38 10174.81 1926.61
3.50 10411.49 1860.42
3.63 10639.96 1795.20
3.75 10860.33 1730.94
3.88 11072.73 1667.63
4.00 11277.28 1605.28
4.13 11474.09 1543.87
4.25 11663.29 1483.40
4.38 11844.98 1423.87
4.50 12019.29 1365.26
4.63 12186.34 1307.58
4.75 12346.22 1250.81
4.88 12499.07 1194.95
5.00 12645.00 1140.00
**************************************************************************************************
I hope this helps you.
If you find my answer useful, kindly rate it.
All the best. :)