저는 C#을 처음 사용하므로 코드 형식이 잘못되었을 때 사과드립니다. 현재 데이터의 거리를 계산하는 클래스에서 값을 반환하는 방법을 알아 내려고 노력 중입니다.클래스에서 주 프로그램으로 데이터를 가져 오려고 시도합니다.
여기 내가 지금까지 가지고있는 것, 내가 물어볼 때 또는 두 가지 점을 제외하고는 밖으로 나가는 유일한 거리감은 DistanceGenerator.Coursework입니다. 내가 뭘 잘못하고 있는지, 어떤 도움을 볼 수 없습니까? 여기
namespace DistanceGenerator
{
class Program
{
static void Main(string[] args)
{
//Displays data in correct Format
List<float> inputList = new List<float>();
TextReader tr = new StreamReader("c:/users/tom/documents/visual studio 2010/Projects/DistanceCalculator3/DistanceCalculator3/TextFile1.txt");
String input = Convert.ToString(tr.ReadToEnd());
String[] items = input.Split(',');
Console.WriteLine("Point Latitude Longtitude Elevation");
for (int i = 0; i < items.Length; i++)
{
if (i % 3 == 0)
{
Console.Write((i/3) + "\t\t");
}
Console.Write(items[i]);
Console.Write("\t\t");
if (((i - 2) % 3) == 0)
{
Console.WriteLine();
}
}
Console.WriteLine();
Console.WriteLine();
// Ask for two inputs from the user which is then converted into 6 floats and transfered in class Coordinates
bool exit = false;
do
{
Console.WriteLine("Please enter the two points that you wish to know the distance between:");
string point = Console.ReadLine();
string[] pointInput = point.Split(' ');
int pointNumber = Convert.ToInt16(pointInput[0]);
int pointNumber2 = Convert.ToInt16(pointInput[1]);
double latitude = (Convert.ToDouble(items[pointNumber * 3]));
double longtitude = (Convert.ToDouble(items[(pointNumber * 3) + 1]));
double elevation = (Convert.ToDouble(items[(pointNumber * 3) + 2]));
double latitude2 = (Convert.ToDouble(items[pointNumber2 * 3]));
double longtitude2 = (Convert.ToDouble(items[(pointNumber2 * 3) + 1]));
double elevation2 = (Convert.ToDouble(items[(pointNumber2 * 3) + 2]));
//Calculate the distance between two points
Distance curDistance = new Distance(latitude, longtitude, elevation, latitude2, longtitude2, elevation2);
Console.WriteLine(curDistance);
Console.WriteLine("If you wish to calculate another distance type 1 and return, if you wish to end the program, type -1.");
string reset;
do
{
reset = Console.ReadLine().Trim();
}
while (reset != "1" && reset != "-1");
if (reset == "-1") exit = true;
}
while (!exit);
}
}
}
//와 당신의 Main
방법으로 클래스
namespace DistanceGenerator
{
class Distance
{
private double latitude;
private double longtitude;
private double elevation;
private double latitude2;
private double longtitude2;
private double elevation2;
public Distance(double latitude, double longtitude, double elevation, double latitude2, double longtitude2, double elevation2)
{
// TODO: Complete member initialization
this.latitude = latitude;
this.longtitude = longtitude;
this.elevation = elevation;
this.latitude2 = latitude2;
this.longtitude2 = longtitude2;
this.elevation2 = elevation2;
}
private double curDistance()
{
const double PIx = 3.141592653589793;
const double RADIO = 6371;
double dlat = ((latitude2) * (PIx/180)) - ((latitude) * (PIx/180));
double dlon = ((longtitude2) * (PIx/180)) - ((longtitude) * (PIx/180));
double a = (Math.Sin(dlat/2) * Math.Sin(dlat/2)) + Math.Cos((latitude) * (PIx/180)) * Math.Cos((latitude2) * (PIx/180)) * (Math.Sin(dlon/2) * Math.Sin(dlon/2));
double angle = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
double ultimateDistance = (angle * RADIO);
return ultimateDistance;
}
}
}
너무 많은 코드 : 그것을 위해 당신이 (당신이 혼동도
curDistance
명명 한)이Distance
인스턴스에서 방법curDistance
를 호출해야합니다. – Oded여기에 언급 된 DistanceGenerator.Coursework가 표시되지 않습니다. 조금 줄이고 문제 영역을 강조 할 수 있을까요? – tmesser