Question: Please fix the compile error(s) #include #include #define_USE_MATH_DEFINES #include double volume(int radius, int side_length, int height); double density(char material_code); double weight(int radius, int side_len, int
Please fix the compile error(s)
#include
#include
#define_USE_MATH_DEFINES
#include
double volume(int radius, int side_length, int height);
double density(char material_code);
double weight(int radius, int side_len, int height, char material, double *output_volume, double *output_density);
int main(void) { double eet247_weight; double eet247_volume; double eet247_density; // calculate the weight of a gold EET247cylinder with // circle radius 5, side length 4, and // height 4 eet247_weight = weight(5, 4, 4, 'g', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 2857.08 && eet247_weight < 2857.09); // calculate the weight of gold EET247cylinder with // circle radius 2, side length 1, and // height 3 eet247_weight = weight(2, 1, 3, 'G', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 577.76 && eet247_weight < 577.77); // calculate the weight of silver EET247cylinder with // circle radius 12, side length 9, and // height 1 eet247_weight = weight(12, 9, 1, 's', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 2538.00 && eet247_weight < 2538.01); // calculate the weight of silver EET247cylinder with // circle radius 4, side length 1, and // height 2 eet247_weight = weight(4, 1, 2, 'S', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 1000.06 && eet247_weight < 1000.07); // calculate the weight of an aluminumm EET247cylinder with // circle radius 17, side length 11, and // height 3 eet247_weight = weight(17, 11, 3, 'a', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 4807.77 && eet247_weight < 4807.78); // calculate the weight of an aluminumm EET247cylinder with // circle radius 14, side length 6, and // height 2 eet247_weight = weight(14, 6, 2, 'A', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 2819.99 && eet247_weight < 2820.00); // calculate the weight of a copper EET247cylinder with // circle radius 5, side length 3, and // height 1 eet247_weight = weight(5, 3, 1, 'c', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 494.20 && eet247_weight < 494.21); // calculate the weight of a copper EET247cylinder with // circle radius 13, side length 4, and // height 11 eet247_weight = weight(13, 4, 11, 'C', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 48231.31 && eet247_weight < 48231.32); // calculate the weight of a lead EET247cylinder with // circle radius 7, side length 4, and // height 5 eet247_weight = weight(7, 4, 5, 'l', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 6371.31 && eet247_weight < 6371.32); // calculate the weight of a lead EET247cylinder with // circle radius 5, side length 4, and // height 5 eet247_weight = weight(5, 4, 4, 'L', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 1676.98 && eet247_weight < 1676.99); // calculate the weight of a zinc EET247cylinder with // circle radius 11, side length 6, and // height 3 eet247_weight = weight(11, 6, 3, 'z', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 6130.41 && eet247_weight < 6130.42); // calculate the weight of a zinc EET247cylinder with // circle radius 7, side length 6, and // height 2 eet247_weight = weight(7, 6, 2, 'Z', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight > 861.40 && eet247_weight < 861.41); // ensure the zero is returned for an unknown material eet247_weight = weight(9, 6, 2, '*', &eet247_volume, &eet247_density); assert(eet247_weight == eet247_volume * eet247_density); assert(eet247_weight == 0.0); printf("Your program has successfully calculated " "the weights of the test inputs."); return (0); }
double volume(int radius, int side_length, int height) { double AreaCircle = M_PI * radius * radius; double sideHexagon = 3 * sqrt(3) / 2 * (side_length * side_length); double BaseCylinder = AreaCircle - sideHexagon; return BaseCylinder * height; }
/*Function: density Given material_code, this function will determine the density of the material_code If an unknown material code is passed it will return 0 */
double density(char material_code) { double density = 0; /*density is initialized*/ /*start switch-case logic*/ switch(material_code) { case 'A': case 'a': density = 2.70; break;/*for A or a: Aluminium*/ case 'C': case 'c': density = 8.96; break; /*for C or c: Copper*/ case 'G': case 'g': density = 19.32; break; /*for G or g: Gold*/ case 'L': case 'l': density = 11.34; break; /*for L or l: Lead*/ case 'S': case 's': density = 10.49; break; /*for S or s: Silver*/ case 'Z': case 'z': density = 7.13; break; /*for Z or z: Zinc*/ default: density = 0;/*for all other unknown cases*/ } return density; }
double weight(int radius, int side_len, int height, char material, double *output_volume, double *output_density)
*output_volume = volume(radius, side_len, height);
*output_density = density(material);
//weight is the product of density and volume when gravitational constant is 1
//formula of weight is :
//weight = mg
//m is mass of object and g is gravitational constant
//m is given by formula :
//volume = mass / density
//mass = volume * density
//m = volume * density and g = 1
//weight = mg = (volume * density)*(1) = volume * density
double output_weight = (*output_density)*(*output_volume);//store the weight material
return output_weight;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
