Question

2. Write a program with three functions that will be called from the main function The functions will calculate the volume, a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 2:

Here is code:

#include <stdio.h>

#include <math.h>

float

volume(float l, float w, float h)

{

return (l * w * h);

}

float

area(float l, float w, float h)

{

return 2 * (w * l + l * h + h * w);

}

float

perimeter(float l, float w, float h)

{

return 4 * (l * w * h);

}

int

main()

{

float width, length, height;

float c_area, c_volume, c_perimeter;

printf("Enter value of width, length & height of the cuboids:\n");

scanf("%f%f%f", &width, &length, &height);

c_area = area(length, width, height);

c_volume = volume(length, width, height);

c_perimeter = perimeter(length, width, height);

printf("Area of cuboids is: %f\n", c_area);

printf("\nVolume of cuboids is : %f\n", c_volume);

printf("\nPerimeter of cuboids is : %f\n", c_perimeter);

return 0;

}

Question 3:

Here is code:

#include <stdio.h>

#include <stdlib.h>

float

volume(float l, float w, float h)

{

return (l * w * h);

}

float

area(float l, float w, float h)

{

return 2 * (w * l + l * h + h * w);

}

float

perimeter(float l, float w, float h)

{

return 4 * (l * w * h);

}

float *

calculation(float l, float w, float h)

{

float * result = (float *) malloc(3 * sizeof(float));

result[0] = volume(l,w,h);

result[1] = area(l,w,h);

result[2] = perimeter(l,w,h);

return result;

}

int

main()

{

float width, length, height;

float c_area, c_volume, c_perimeter;

printf("Enter value of width, length & height of the cuboids:\n");

scanf("%f%f%f", &width, &length, &height);

float * result = calculation(length, width, height);

printf("Cuboid's volume = %f, area = %f, perimeter=%f\n", result[0], result[1], result[2]);

return 0;

}

Output:

Enter value of width, length & height of the cuboids: 10 20 30 Cuboids volume = 6000.000000, area = 2200.000000, perimeter=2

Add a comment
Know the answer?
Add Answer to:
2. Write a program with three functions that will be called from the main function The functions will calculate the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the C++ program you created in assignment 1 by using 'user defined' functions. You are...

    Modify the C++ program you created in assignment 1 by using 'user defined' functions. You are to create 3 functions: 1. A function to return the perimeter of a rectangle. This function shall be passed 2 parameters as doubles; the width and the length of the rectangle. Name this function and all parameters appropriately. This function shall return a value of type double, which is the perimeter. 2. A function to return the area of a rectangle. This function shall...

  • 7. Consider a function definition of calc Perimeter in the program segment given in Figure 17....

    7. Consider a function definition of calc Perimeter in the program segment given in Figure 17. float calcPerimeter (float width, float height) float perimeter; perimeter 2. (width + height); return (perimeter); Figure 17 a) Modify function definition calc Perimeter to pass argument perimeter by reference b) Write a function call for function calc Perimeter after modification in (a).

  • Write a complete program utilizing functions. The function accepts two parameters: one representing a radius of...

    Write a complete program utilizing functions. The function accepts two parameters: one representing a radius of type float, the other parameter is an integer “select” which chooses between finding the area of a circle or the volume of sphere. If the select variable is 1, then area is calculated. If the select value is 2, then volume is calculated. If the select value is any other value, then the function returns 0. Test your function in main by calling it...

  • Write a C program named assignment04.cpp that will ask for and read in a float for...

    Write a C program named assignment04.cpp that will ask for and read in a float for a radius ask for and read in a float for the height each of the following functions will calculate some property of a shape (area, volume, circumference, etc) The functions will accept one or two parameters (radius and/or height) and return the proper calculation. There is no input/output (cin or cout) in the function – just the calculation write the following functions float areaCircle(float...

  • A closer look at functions - C++ C option: (The best grade is a 79%) Write...

    A closer look at functions - C++ C option: (The best grade is a 79%) Write a program to calculate the cost and time it takes to fill a swimming pool . Inputs: Length, Width, and Depth of the pool (This is a gross simplification, since pools are not really rectangular cubes.) Fill rate of the pool in Gallons per minute Calculation functions Write a function to calculate the total cubic feet (Length x Width x Depth) and return the...

  • The program must be in C# syntax. Write the definition for a generic class called Rectangle...

    The program must be in C# syntax. Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that...

  • The program must be in C# syntax. Write the definition for a generic class called Rectangle...

    The program must be in C# syntax. Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that...

  • Write a complete C++ program that is made of functions main() and rShift(). The rShift() function...

    Write a complete C++ program that is made of functions main() and rShift(). The rShift() function must be a function without return with 6 parameters. rShift() should do following. Shift the first 4 formal parameters' value one place to right circularly and send the updated values out to the caller function, i.e. main. Furthermore, after calling this function with first 4 actual parameters, say a1, a2, a3, a4, and these actual parameters should shift their value one place to right...

  • Question 1: Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating...

    Question 1: Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating point number number1 is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differing bit is encountered. The fact that this can be done easily is the main motivation for biased exponent notation. The function should return 1 if number1 > number2, return...

  • using C , comments will be appreciated. Question1 Write down an function named bitwisedFloatCompare(float number1, float...

    using C , comments will be appreciated. Question1 Write down an function named bitwisedFloatCompare(float number1, float number2)that tests whether a floating point number number1is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differingbit is encountered. The fact that this can be done easily is the main motivation for biased exponent notation. The function should return 1 if number1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT