Write a C++ program that calls a function named calcul8, to determine the volume
ID: 3832230 • Letter: W
Question
Write a C++ program that calls a function named calcul8, to determine the volume of a sphere and the area of a circle for a given radius that varies from 1 to 10 in increments of 0.5. The array "data" must contain the values of the radius in the first column, values for the volumes of the spheres in the second column and the values for the areas of the circles in the third column. Requirements: 1. The increment of 0.5 must be a global variable, and must be named "inc". 2. "inc" must be initialized in the main function 3. A function prototype must be used for calcul8 The main function must: 1. call the calcul8 function 2. populate the array "data" with values of the radius using a repetition statement 3. contain all output filestream objects 4. instantiate the string object named MyString 5. the function call to calcul8 must assign the return value to the object named 'MyStrlng" 6. use a nested repetition statement to display the array values on the monitor. 7. display the message returned by the function cakul8 at the end of the program The calcul8 function must: 1. have one pass by reference argument which must be a two-dimensional array named "data." 2. have two pass by value arguments. The beginning radius, r_beg and the ending radius, r_end. 3. populate the values for the volume of the spheres and the area of the circles in the "data" array using repetition statements. Return these values through the argument list. 4. use the pow function 5. cannot have any output file stream objects 6. instantiate the object named Message with an initial string of "We are finished with the program" 7. return by value the string object named "Message" The output must have the following characteristics: 1. The output must be displayed on the monitor in three columns. 2. The column headings must be Radius, Volume and Area. 3. All output data must have three decimal places. 4. All numerical output must use the three manipulators that have been required throughout the entire semester. The equations are: V = 4/3 pi r^3 A = pi r^2Explanation / Answer
#include<iostream.h>
#include<string>
#include <math.h>
using namespace std;
float inc;
string calcul8(float (&data1)[19][3], int r_beg, int r_end);
void main(){
float data[19][3];
string MyString;
int i,j,k;
float rad;
inc = 0.5;
rad = 1;
for(i=0; i<19; i++){
data[i][0] = rad;
rad = rad + inc;
}
MyString = calcul8(data[19][3], 1, 10);
cout << "Radius" << " " << "Volume" << " " << "Area" << endl;
for (i = 0; i<19; i++){
for (j = 0; j<3; j++){
cout << setprecision(3) << data[i][j];
if (j < 2)
cout << " ";
}
cout << endl;
}
cout << MyString << endl;
}
string calcul8(int (&data1)[19][3], int r_beg, int r_end){
int i,j;
string Message;
float rad;
rad = (float)r_beg;
Message = "We are finished with the program";
i = 0;
while (rad <= r_end){
j = 1;
while (j < 3){
if (j == 1){
data1[i][j] = (4/3)* 3.14 * pow(rad, 3);
}
if (j == 2){
data1[i][j] = 3.14 * pow(rad, 2);
}
j++;
}
rad = rad + inc;
i++;
}
return Message;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.