**IN C++ ONLY** Calculate the area and volume of a sphere problem. Inside a for loop, vary the radius from 10 to 40 with a step or increment of 5 and calculate the area and volume Your radius will be equal to your loop counter. All calculations should have 2 decimal places, but the radius should have zero decimal places and any number of 1,000 or more should have a comma. Print the radius, area, and volume in a table format, with 3 columns. Note: you don’t have to print grid lines. Print column headings above the loop and all the calculations inside the loop. The column headings would just be Radius, Area, and Volume. Right justify your data under your column headings Below the loop, print the sum of the radii, the sum of the areas, and the sum of the volumes. The sum of the areas and the sum of the volumes should have 2 decimal places and commas. The sum of the radii should have zero decimal places. **IN C++ ONLY**
#include <iostream>
#include <string>
using namespace std;
string commify(unsigned long long n)
{
string s;
int cnt = 0;
do
{
s.insert(0, 1, char('0' + n % 10));
n /= 10;
if (++cnt == 3 && n)
{
s.insert(0, 1, ',');
cnt = 0;
}
} while (n);
return s;
}
float Round(float var)
{
float value = (int)(var * 100 + .5);
return (float)value / 100;
}
int main()
{
float sum_radius=0;
float sum_area=0;
float sum_volume=0;
float area,volume;
std::cout << "radius "<<"Area " <<
"volume"<< std::endl;
for(int radius=10;radius<=40;radius+=5)
{
std::cout <<radius;
sum_radius +=radius;
area=4 * 3.14 * radius * radius;
std::cout <<" "<<commify(Round(area));
sum_area +=area;
volume=(4/3)*3.14 * radius * radius * radius;
std::cout <<" "<<commify(Round(volume))<<
std::endl;
sum_volume +=volume;
}
std::cout << "Sum of radius
:"<<commify(Round(sum_radius))<< std::endl;
std::cout << "Sum of area
:"<<commify(Round(sum_area))<< std::endl;
std::cout << "Sum of volume
:"<<commify(Round(sum_volume))<< std::endl;
}



For further Information Please comment Below
**IN C++ ONLY** Calculate the area and volume of a sphere problem. Inside a for loop,...
Calculate and print the area and volume of a cone inside a While loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5) Note: Your loop variable will need to be a double data type Use two decimal places on all numbers that are double data type. This will be a table with 3 columns. Use r as the loop counter and as the radius. Let...
Calculate the area and perimeter(circumference) of a circle. Print the area and perimeter(circumference) Use a radius of 15 to test your program, calculations should have 2 decimal places. In C++, please use visual studios.
Calculate the area and perimeter(circumference) of a circle. Print the area and perimeter(circumference) Use a radius of 15 to test your program, calculations should have 2 decimal places. In C++, please use visual studios, and show the output.
IN PYTHON Print out a table of powers. Use a for loop that goes from 101 to 112 inclusive. Print out r, r squared, r cubed, square root of r, and cube root of r. Use two decimal places for the roots, and zero decimal places for the squares and cubes, and 2 decimal places for the averages. Use commas in numbers 1000 and above. After the loop, print out the average of the r squared and r cubed. Use...
Write a shell script that given a radius, calculates the area of a circle. (Hint – don’t write this from scratch. Find another script that reads user input and performs a calculation, then modify it to meet your needs.) Save the script in your home directory with the name circle.sh The formula for calculating the area is: Area=Π*Radius2 You can use 3.14 for Π, and either do Radius*Radius or Radius^2 to get the square of the radius. Use the scale...
Write a function to calculate the sum of the reciprocals of a series of odd numbers. The function will have one input and no output, with the input being the ending value for the series of odd values. Write the function definition statement Initialize a variable to zero. This variable will contain the sum of all the values. Create a for loop that loops over all odd numbers from 1 to the specified ending value. Inside the loop, add the...
Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume of rectangular objects. First, write an abstract super class RectangularShape, then write a subclass Rectangle that inherits from the super class to compute areas of rectangles, including squares if there is only one data. Finally, write another subclass Cuboid that inherits from its super class Rectangle above to compute surface areas and volumes of cuboids, including 3 equal sided cube. Must apply code-reusability in...
Please help! CS Problem Set 5 #Write a function called sphere_data. volume_and_area will #take in a dictionary. This dictionary is guaranteed to #have exactly one key: "radius", whose value is an integer #representing the radius of a sphere. # #Modify this dictionary to add two keys: "volume" and "area". #The values associated with these keys should be the volume #and surface area of the sphere. # #The formula for volume is: # (4/3) * pi * radius ^ 3 #...
(use only variables, expression, conditional statement and loop
of c programming)
***C programming**
int sum_of_cubes(int n) {
}
int quadrant(int x, int y) {
}
int num_occurrences_of_digit(long num, int digit) {
return 0;
}
3.1 int sum_of_cubes(int n) This function should return the sum of the cubes of the first n integers. For example, if n is 4, it should return 13 +23+ 39 +4°. There is a simple formula for the result: 3x = ((n + 1)) = +...
Question 3: By using the indicated number of slices, calculate the approximate volume of the solid to 8 decimal places and record your results in the table below. The result for n - 4 is recorded, and the result for n 100 is given as well. The file in the "Projects" folder gives explicit instructions to set up the worksheet for n -4, and to check that you understand the procedure, make sure that your answer for n -100 matches...