### NEED HELP

This is my question :

Write a single C++ program based on the structures to compute the radii,volumes,and surface area of the spheres formed from the following sets of data
CENTER : (0,0,0) POINT ON THE SURFACE : (-1,3,5)
CENTER : (0,0,0) POINT ON THE SURFACE : (2,-5,7)
CENTER : (-1,-1,-1) POINT ON THE SURFACE : (-1,3,5)
CENTER : (1,-1,3) POINT ON THE SURFACE : (-1,3,5)

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596`` `````` #include #include #include #define n 4 #define m 6 #define PI 3.142 using namespace std; void main() { int i,j; double c[n+1][m+1],p[n+1][m+1]; ifstream InFile; InFile.open("data.in"); for (i=1;i<=n;i++) { for (j=1; j<=m; j++) { if (j<=3) { InFile >> c[i][j]; //cout << c[i][j] << " \t"; } else { InFile >> p[i][j]; //cout << p[i][j] << "\t"; } } cout << endl; } InFile.close(); typedef struct { double x,y,z; }POINT; typedef struct { POINT b,e; double length; }RADIUS; typedef struct { RADIUS r; double radius,volume,area; }SPHERE; SPHERE s[n+1]; s[1].r.b.x=0; s[1].r.b.y=0; s[1].r.b.z=0; s[1].r.e.x=-1; s[1].r.e.y=3; s[1].r.e.z=5; s[2].r.b.x=0; s[2].r.b.y=0; s[2].r.b.z=0; s[2].r.e.x=2; s[2].r.e.y=-5; s[2].r.e.z=7; s[3].r.b.x=-1; s[3].r.b.y=-1; s[3].r.b.z=-1; s[3].r.e.x=-1; s[3].r.e.y=3; s[3].r.e.z=5; s[4].r.b.x=1; s[4].r.b.y=-1; s[4].r.b.z=3; s[4].r.e.x=-1; s[4].r.e.y=3; s[4].r.e.z=5; c[1][1]=s[1].r.b.x; c[1][2]=s[1].r.b.y; c[1][3]=s[1].r.b.z; p[1][4]=s[1].r.e.x; p[1][5]=s[1].r.e.y; p[1][6]=s[1].r.e.z; c[2][1]=s[2].r.b.x; c[2][2]=s[2].r.b.y; c[2][3]=s[2].r.b.z; p[2][4]=s[2].r.e.x; p[2][5]=s[2].r.e.y; p[2][6]=s[2].r.e.z; c[3][1]=s[3].r.b.x; c[3][2]=s[3].r.b.y; c[3][3]=s[3].r.b.z; p[3][4]=s[3].r.e.x; p[3][5]=s[3].r.e.y; p[3][6]=s[3].r.e.z; c[4][1]=s[4].r.b.x; c[4][2]=s[4].r.b.y; c[4][3]=s[4].r.b.z; p[4][4]=s[4].r.e.x; p[4][5]=s[4].r.e.y; p[4][6]=s[4].r.e.z; for (i=1; i<=n; i++) { s[i].radius=sqrt(pow(s[i].r.e.x-s[i].r.b.x,2)+pow(s[i].r.e.y-s[i].r.b.y,2)+pow(s[i].r.e.z-s[i].r.b.z,2)); s[i].volume=(4*PI*pow(s[i].radius,3)/3); s[i].area=4*PI*pow(s[i].radius,2); cout << "SPHERE #" << i << endl; cout << "CENTER " "("<< s[i].r.b.x << "," << s[i].r.b.y << "," << s[i].r.b.z << ")" << endl; cout << "POINT " "(" << s[i].r.e.x << "," << s[i].r.e.y << "," << s[i].r.e.z << ")" << endl; cout << "Radius is " << s[i].radius << endl; cout << "Volume is " << s[i].volume << endl; cout << "Surface area is " << s[i].area << endl << endl; } cin.get(); } ``````
Last edited on
Apart from busting into other peoples topics, also don't do duplicate posts.

Consider why there are no replies. You have just asked whether it was correct or not - are you able to verify by other means whether you calculated correctly. What don't you like about the code?