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)

MY ANSWER IS CORRECT??
PLEASE HELP ME :(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96




	


#include <iostream>
#include <iomanip>
#include <fstream>
#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?

Read this:

http://www.cplusplus.com/forum/beginner/1/#msg6680
I'M SORRY..I JUST NEW IN THIS,,I HAVE NO BASICS IN C++ PROG AT ALL..
AND THIS IS MY FIRST IN THIS
As well as that, don't type in all capitals - it means YOU ARE SHOUTING!

So what is your problem - how can we help?
Topic archived. No new replies allowed.