Question

Can someone help me with this coding question. I cannot get this to run properly. Write...

Can someone help me with this coding question. I cannot get this to run properly. Write a program that defines the named constant PI, const double PI = 3.14159;, which stores the value of π. The program should use PI and the functions listed in Table 6-1 to accomplish the following: Output the value of √π . Prompt the user to input the value of a double variable r, which stores the radius of a sphere. The program then outputs the following: The value of 4.0πr², which is the surface area of the sphere. The value of (4.0/3.0)πr³, which is the volume of the sphere. This is in C++ code

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Screenshot:

// Include the necessary header files. #include <iostream> #include <cmath> using namespace std; // start the main function.

Sample output:

Square root of PI is: 1.77245 Enter the radius of a sphere: 4 The surface area of a sphere with radius 4 is: 201.062 The volu

Code to Copy:

// Include the necessary header files.

#include <iostream>

#include <cmath>

using namespace std;

// start the main function.

int main()

{

// declare the constant variable PI

const double PI = 3.14159;

// Display the square root on console.

cout<<"Square root of PI is: "<<sqrt(PI)<<endl;

// Prompt the user to enter the radius..

cout<<"Enter the radius of a sphere: ";

double r;

cin>>r;

// display the result on console.

cout<<"The surface area of a sphere with radius "<<r<<" is: "<<4*PI*r*r<<endl;

cout<<"The volume of a sphere with radius "<<r<<" is: "<<(4.0/3.0)*PI*r*r*r<<endl;

}

Add a comment
Know the answer?
Add Answer to:
Can someone help me with this coding question. I cannot get this to run properly. Write...
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
  • No. 7 7th question i want this code to be done on c++ visual studio without...

    No. 7 7th question i want this code to be done on c++ visual studio without using bool operation. and please try to make as simple as possible. Also i need flowchart for the code thanks. Q7 I need a code programmed on c++ visual studios. Also flowchart of the code. Try to make it simple college level understandable code. thanks. b. wg. Prompt the user to input the value of a double variabler, which stores the radius of a...

  • can someone assist me and tell me what I'm missing. I managed to get it this...

    can someone assist me and tell me what I'm missing. I managed to get it this far but still missing two parts to complete it. CENGAGE MINDTAP Programming Exercise 6-4 Tasks main.cpp + 1 #include <iostream r with successful Uses piand 2 #include <cnath> output 5,00 out of 10.00 3 using nanespace std; 4 5 const double PI = 3.1419; 2 out of 4 checks passed. Review 6 the results below for more details. 7 int main() 8 ( Checks...

  • Can someone help me solve this MIPS question, it must be able to run on qtspim....

    Can someone help me solve this MIPS question, it must be able to run on qtspim. Write a MIPS code which involves three functions: a. main b. poly C. Pow to compute the value of the polynomial given below for any value of x, as given by the user. f(x) = 3x + 2x4 - 5x +7-6 Your program must pass arguments to functions such as poly and pow and get return values from these functions. The input to the...

  • Problem: Write a short C++ program that gets the side of a cube and the radius...

    Problem: Write a short C++ program that gets the side of a cube and the radius of a sphere from the keyboard and writes to a file the surfaces of these shapes.             ------------------------------------------------------------------------------------------------------------------------ Your task: implement in C++ the algorithm solution shown below. ------------------------------------------------------------------------------------------------------------------------ Part A (79 points) Algorithm solution (in pseudocode): To accomplish this task, your program will have to take the following steps: 1. Declare a variable named outFile that represents an output stream. 2. Declare a...

  • can someone please help me with this. I need to use java. Recursion Write and run...

    can someone please help me with this. I need to use java. Recursion Write and run a program that reads in a set of numbers and stores them in a sequential array. It then calls a recursive function to sort the elements of the array in ascending order. When the sorting is done, the main function prints out the elements of the newly sorted array Hint: How do you sort an array recursively? Place the smallest element of the array...

  • This is a matlab HW that I need the code for, if someone could help me figure this out it would b...

    This is a matlab HW that I need the code for, if someone could help me figure this out it would be appreciated. The value of t can be estimated from the following equation: in your script file, estimate the value of π for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message...

  • I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...

    I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...

  • I need help with my coding for C++! The goal of this is to calculate the...

    I need help with my coding for C++! The goal of this is to calculate the total cost of a product by combining the products price and the amount of tax, then display it to the user. The numbers we have to test out is 100 for the price and 8.25 for the percentage. When I test is out, the formula works but it isn't rounding the 108.25 to 108.3, which is the total price we are supposed to display...

  • Can anyone help me with my C hw? Exercise 3 You will write a new program...

    Can anyone help me with my C hw? Exercise 3 You will write a new program that combines dynamically allocating an array and saving that array to a file. These are the tasks your program must perform Open an output file named "data.txt" and prepare it for writing in text mode o If the file handle is NULL, quit the program o By default, it is created and stored in the same directory as your source code file Prompt the...

  • Can somebody help me with this coding the program allow 2 players play tic Tac Toe....

    Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...

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