Question

In: Computer Science

Write a program to compute answers to some basic geometry formulas. The program prompts the user...

Write a program to compute answers to some basic geometry formulas. The program prompts the user to input a length (in centimeters) specified as a floating point value. The program then echoes the input and computes areas of squares and circles and the volume of a cube. For the squares, you will assume that the input length value is the length of a side. For the circles, this same value becomes the diameter. Use the meter value input to calculate the results in square (or cubic) meters and then print the answers in square (or cubic) meters. Area of a square (length times width) Area of a circle (pi times radius squared) How much bigger the area of the square is than the circle (see previous calculations) Round the length down to the next whole number of meters, compute the volume of a cube with this value as the length of its side Round the length up to the next whole number of meters, compute the volume of a cube with this value as the length of its side. You are to run the program three times using the following input values: 1000 1999.9 299.4 Please turn in the program and the outputs of running the program three times as directed. Be sure to use good style, appropriate comments and make use of constants in this program. Important Notes For the constant PI, please use 3.14159 Use the floor() and ceil() functions to round down and up respectively. For example, ceil(3.02) is 4. Be sure to #include to get access to these two functions Sample Output Your output format should look similar in style to the one below. Geometry formulas by (Your name) Enter one floating point number for length, 123.4 The number you entered is 123.4 cm or 12.34xx m. Area of square xx.xxxxxxx sq. m. Area of a circle xx.xxxxxxx sq. m. Difference is xx.xxxxxxxx sq. m. Cube volume rounded down is xx.xxxxxxxx cu. m. Cube volume rounded up is xx.xxxxxxxx cu. m. Press any key to continue

Solutions

Expert Solution

#include <stdio.h>
#include <math.h>

#define PI 3.14159


int main(){
float length;// centimeters
printf("\nGeometry formulas by [Name]");
printf("\nEnter one floating point number for length: ");
scanf("%f",&length);
printf("\nThe number you entered is %0.1f cm",length);


length = length/100; // to meters

float square_area = length*length;
float circle_area = PI*(length/2)*(length/2); // radius = diameter/2
float difference = square_area - circle_area;

//
float cube_volume_down = floor(length)*floor(length)*floor(length);
float cube_volume_up = ceil(length)*ceil(length)*ceil(length);
//
printf("\nArea of square %0.7f sq.m",square_area);
printf("\nArea of circle %0.7f sq.m",circle_area);
printf("\nDifference is %0.7f sq.m",difference);
//
printf("\nCube volume rounded down is %0.7f cu.m",cube_volume_down);
printf("\nCube volume rounded up is %0.7f cu.m",cube_volume_up);
//
printf("\nPress any key to continue");

return 0;
}

------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~


Related Solutions

Use Java (Geometry: point in a rectangle?) Write a program that prompts the user to enter...
Use Java (Geometry: point in a rectangle?) Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5.  For example, (2, 2) is inside the rectangle and (6, 4) is outside the rectangle. (Hint: A point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to10 / 2 and its vertical...
JAVA 5- Write a program that prompts the user to enter two (2) numbers and compute...
JAVA 5- Write a program that prompts the user to enter two (2) numbers and compute the sum of the numbers between these two numbers (including the numbers entered). If the user Enters 2 and 6. The program will calculate the sum of the numbers: 2+3+4+5+6 and will display the result. Enter First number> 2 Enter second number> 6 The sum is 20
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
using c++. ALWAYS GRADE MY ANSWERS nstructions Write a program that prompts the user to input...
using c++. ALWAYS GRADE MY ANSWERS nstructions Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, it should output the individual digits of: 3456 as 3 4 5 6 8030 as 8 0 3 0 2345526 as 2 3 4 5 5 2 6 4000 as 4 0 0 0 -2345 as 2 3 4 5 #2 Instructions Write a...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT