使用C#,对我的飞行计算机进行故障排除

使用C#,对我的飞行计算机进行故障排除,c#,C#,该数据库的目标是创建一个exe,允许用户使用.txt文件按三位数代码在机场键入。它以前是有效的,但现在似乎不起作用。我将突出显示.PolltheData和.Dataset周围的错误。我 首先是一个名为Engine的项目,它有两个类:Engine&Locations,从中我没有任何问题 引擎 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threa

该数据库的目标是创建一个exe,允许用户使用.txt文件按三位数代码在机场键入。它以前是有效的,但现在似乎不起作用。我将突出显示
.PolltheData
.Dataset
周围的错误。我

首先是一个名为Engine的项目,它有两个类:Engine&Locations,从中我没有任何问题

引擎

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Engine
{
    public class Engine
    {
        public const double EarthRadiusInMiles = 3959.0;
        public const double EarthRadiusInKilometers = 6371.0;
        public List<Location> Route;

        /// <summary>
        /// The Engine constructor
        /// </summary>
        public Engine()
        {
            Route = new List<Location>();
        }

        public void Add(Location Loc)
        {
            Route.Add(Loc);
        }

        /// <summary>
        /// GetRouteLength Calculates the length of all the Location objects in the Route Container
        /// </summary>
        /// <returns></returns>
        public double GetRouteLength()
        {
            double temp = 0;



            for (int i = 0; i < Route.Count; ++i)
            {
                if (Route.Count == 1)
                {
                    return 0;
                }
                if (i != this.Route.Count - 1)
                {
                    double view = this.Distance(this.Route[i], this.Route[i + 1], 'K');
                    temp = temp + this.Distance(this.Route[i], this.Route[i + 1], 'K');
                }

            }

            return temp;
        }

        /// <summary>
        /// Prints out all the elements in the Route.
        /// </summary>
        public void PrintRoute()
        {
            if (this.Route.Count != 0)
            {
                Console.WriteLine("Current Route----- {0} Locations ", this.Route.Count);
                foreach (Location Loc in this.Route)
                {
                    Console.WriteLine("{0} Lat, {1} Long,", Loc.GetLatitude(), Loc.GetLongitude());

                }
                Console.WriteLine("Total Distance = {0} {1}", this.GetRouteLength(), this.Route[0].Unit);
            }

            else
            {
                Console.WriteLine("Route is empty");
            }
        }

        /// <summary>
        /// Calculates the distance between two location objects
        /// </summary>
        /// <param name="loc1"></param>
        /// <param name="loc2"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public double Distance(Location loc1, Location loc2, char unit)
        {
            double R;
            if (unit == 'K')
            {
                R = EarthRadiusInKilometers;
            }
            else
            {
                R = EarthRadiusInMiles;
            }

            double dLat = deg2rad(loc2.GetLatitude()) - deg2rad(loc1.GetLatitude());
            double dLon = deg2rad(loc2.GetLongitude()) - deg2rad(loc1.GetLongitude());
            double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(deg2rad(loc1.GetLatitude())) * Math.Cos(deg2rad(loc2.GetLatitude())) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
            double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            double distance = c * R;

            return Math.Round(distance, 2);
        }

        /// <summary>
        /// Calculates the distance between two sets of latitudes and longitudes
        /// </summary>
        /// <param name="lat1"></param>
        /// <param name="lng1"></param>
        /// <param name="lat2"></param>
        /// <param name="lng2"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public double Distance(double lat1, double lng1, double lat2, double lng2, char unit)
        {
            double R;
            if (unit == 'K')
            {
                R = EarthRadiusInKilometers;
            }
            else
            {
                R = EarthRadiusInMiles;
            }

            double dLat = deg2rad(lat2) - deg2rad(lat1);
            double dLon = deg2rad(lng2) - deg2rad(lng1);
            double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat1)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
            double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            double distance = c * R;

            return Math.Round(distance, 2);
        }

        /// <summary>
        /// Calculates the bearing between two location objects
        /// </summary>
        /// <param name="loc1"></param>
        /// <param name="loc2"></param>
        /// <param name="lat1"></param>
        /// <returns></returns>
        public double BearingTo(Location loc1, Location loc2)
        {
            double dlat1 = deg2rad(loc1.GetLatitude());
            double dlat2 = deg2rad(loc2.GetLatitude());
            double dLon = deg2rad(loc1.GetLongitude()) - deg2rad(loc2.GetLongitude());

            double y = Math.Sin(dLon) * Math.Cos(dlat2);
            double x = Math.Cos(dlat1) * Math.Sin(dlat2) - Math.Sin(dlat1) * Math.Cos(dlat2) * Math.Cos(dLon);
            double brng = Math.Atan2(y, x);
            return (rad2deg(brng) + 360) % 360;
        }

        /// <summary>
        /// Calculates bearing between two sets of latitudes and longitudes
        /// </summary>
        /// <param name="lat1"></param>
        /// <param name="lon1"></param>
        /// <param name="lat2"></param>
        /// <param name="lon2"></param>
        /// <returns></returns>
        public double BearingTo(double lat1, double lon1, double lat2, double lon2)
        {
            double dlat1 = deg2rad(lat1);
            double dlat2 = deg2rad(lat2);
            double dLon = deg2rad(lon1) - deg2rad(lon2);

            double y = Math.Sin(dLon) * Math.Cos(dlat2);
            double x = Math.Cos(dlat1) * Math.Sin(dlat2) - Math.Sin(dlat1) * Math.Cos(dlat2) * Math.Cos(dLon);
            double brng = Math.Atan2(y, x);
            return (rad2deg(brng) + 360) % 360;
        }

        /// <summary>
        /// Calculates a location object based on a location object start, a distance and a bearing
        /// </summary>
        /// <param name="loc1"></param>
        /// <param name="dist"></param>
        /// <param name="brng"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public Location DestinationPoint(Location loc1, double dist, double brng, char unit)
        {
            double R;
            if (unit == 'K')
            {
                R = EarthRadiusInKilometers;
            }
            else
            {
                R = EarthRadiusInMiles;
            }

            dist = dist / R;
            brng = Math.PI * brng / 180;
            double lat1 = deg2rad(loc1.GetLatitude());
            double lon1 = deg2rad(loc1.GetLongitude());
            double lat2 = Math.Asin(Math.Sin(lat1) * Math.Cos(dist) + Math.Cos(lat1) * Math.Sin(dist) * Math.Cos(brng));
            double lon2 = lon1 + Math.Atan2(Math.Sin(brng) * Math.Sin(dist) * Math.Cos(lat1), Math.Cos(dist) - Math.Sin(lat1) * Math.Sin(lat2));
            lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;
            lat2 = rad2deg(lat2);
            lon2 = rad2deg(lon2);
            Location temp = new Location(lat2, lon2);
            return temp;
        }

        /// <summary>
        /// Converts degrees to radians
        /// </summary>
        /// <param name="deg"></param>
        /// <returns></returns>
        private double deg2rad(double deg)
        {
            return (deg * Math.PI / 180.0);
        }

        /// <summary>
        /// Converts radians to degrees
        /// </summary>
        /// <param name="rad"></param>
        /// <returns></returns>

        private double rad2deg(double rad)
        {
            return (rad / Math.PI * 180.0);
        }
    }
}
在程序中,我在
PollTheData
下遇到了一个问题,在
机场所在的区域。PollTheData(text)
已就位

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using FlightConsole;
using Engine;


namespace FlightConsole
{



    internal class Program
    {
        private static void RefreshConsole(Engine.Engine inputEngine)
        {
            Console.Clear();
            Console.WriteLine("Van Moorsel Flight Computer Version 1.0");
            Console.WriteLine("");
            if (inputEngine.Route.Count > 0)
            {
                Console.WriteLine("{0,10}{1,15}{2,10}{3,10}", "Start", "Destination", "Distance", "Bearing");
                Console.WriteLine("{0,10}{1,15}{2,10}{3,10}", inputEngine.Route[0].AirportCode, "", "", "");
                for (int i = 1; i < inputEngine.Route.Count; i++)
                {
                    Console.WriteLine("{0,10}{1,15}{2,10}{3,10}", inputEngine.Route[i - 1].AirportCode, inputEngine.Route[i].AirportCode, inputEngine.Distance(inputEngine.Route[i - 1], inputEngine.Route[i], 'K'), Math.Round(inputEngine.BearingTo(inputEngine.Route[i], inputEngine.Route[i - 1]), 2));
                }
                Console.WriteLine("Total Number of Waypoints: {0}  Total Distance: {1}", inputEngine.Route.Count, inputEngine.GetRouteLength());
            }
            else
            {
                Console.WriteLine("");
            }
        }

        private static void Main(string[] args)
        {
            bool flag = true;
            bool flag2 = true;
            try
            {
                Engine.Engine engine = new Engine.Engine();
                Airports airports = new Airports();
                while (flag)
                {
                    Program.RefreshConsole(engine);
                    flag2 = true;
                    Console.WriteLine("Enter your next destination, or quit pressing Q");
                    while (flag2)
                    {
                        string text = Console.ReadLine();
                        if (airports.PollTheData(text) != null)
                        {
                            engine.Route.Add(airports.PollTheData(text));
                            flag2 = false;
                        }
                        else
                        {
                            flag2 = false;
                        }
                        if (text.ToUpper() == "Q")
                        {
                            flag2 = false;
                            flag = false;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Whoops something went wrong");
                Console.WriteLine("Press any key to end program.");
                Console.ReadLine();
                flag2 = false;
                flag = false;
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用静态系统控制台;
使用FlightConsole;
使用发动机;
命名空间FlightConsole
{
内部课程计划
{
专用静态控制台(Engine.Engine-inputenengine)
{
Console.Clear();
控制台。WriteLine(“Van Moorsel飞行计算机1.0版”);
控制台。写线(“”);
如果(inputEngine.Route.Count>0)
{
Console.WriteLine(“{0,10}{1,15}{2,10}{3,10}”,“开始”,“目的地”,“距离”,“方位”);
Console.WriteLine(“{0,10}{1,15}{2,10}{3,10}”,inputEngine.Route[0].机场代码,“,”,“,”);
对于(int i=1;i
错误状态为:

错误CS1061“Airports”不包含“DataSet”的定义,并且找不到接受“Airports”类型的第一个参数的扩展方法“DataSet”(是否缺少using指令或程序集引用?)

FlightConsole C:\Users\Desktop\COMP6034\U ProgrammingBasics\FinalFlag\FMS Student\FlightConsole\Airports.cs


和都在airport和程序文件中。

行“this.DataSet=new List();”中的“this”指的是包含类,即airport。正如您所列出的,机场中没有具有该名称的属性或字段-您是否意外删除了某些行?

“它以前工作,但现在似乎不工作”-发生了什么变化?也许比较一下以前的版本?您需要将变量
DataSet
全局添加到Airports类中。您正在构造函数中设置它,但它在类定义中不存在。
catch(异常ex2){Console.WriteLine(“出错”);throw ex2;}
将在此处更改堆栈跟踪…这不是最好的事情,即
机场
没有
PollTheData
功能。感谢大家的帮助,特别是布兰登、马克、约翰尼和迈克尔。虽然不是罗克博基,但我知道他来自哪里。
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Engine;
using FlightConsole;


namespace FlightConsole
{
    public class Airports
    {

        public Airports()
        {

            try
            {
                string currentDirectory = Directory.GetCurrentDirectory();
                List<string> list = File.ReadLines(currentDirectory + "\\GlobalAirportDatabase.txt").ToList();
                this.DataSet = new List<Location>();
                foreach (string item2 in list)
                {
                    string[] array = item2.Split(':');
                    Location item = new Location(array[1].ToString(), int.Parse(array[5]), int.Parse(array[6]), int.Parse(array[7]), array[8], int.Parse(array[9]), int.Parse(array[10]), int.Parse(array[11]), array[12], double.Parse(array[13]));
                    this.DataSet.Add(item);
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("The file is missing.");
                throw new FileNotFoundException();
            }
            catch (Exception ex2)
            {
                Console.WriteLine("Something went wrong.");
                throw ex2;
            }
            finally
            {
            }
        }

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using FlightConsole;
using Engine;


namespace FlightConsole
{



    internal class Program
    {
        private static void RefreshConsole(Engine.Engine inputEngine)
        {
            Console.Clear();
            Console.WriteLine("Van Moorsel Flight Computer Version 1.0");
            Console.WriteLine("");
            if (inputEngine.Route.Count > 0)
            {
                Console.WriteLine("{0,10}{1,15}{2,10}{3,10}", "Start", "Destination", "Distance", "Bearing");
                Console.WriteLine("{0,10}{1,15}{2,10}{3,10}", inputEngine.Route[0].AirportCode, "", "", "");
                for (int i = 1; i < inputEngine.Route.Count; i++)
                {
                    Console.WriteLine("{0,10}{1,15}{2,10}{3,10}", inputEngine.Route[i - 1].AirportCode, inputEngine.Route[i].AirportCode, inputEngine.Distance(inputEngine.Route[i - 1], inputEngine.Route[i], 'K'), Math.Round(inputEngine.BearingTo(inputEngine.Route[i], inputEngine.Route[i - 1]), 2));
                }
                Console.WriteLine("Total Number of Waypoints: {0}  Total Distance: {1}", inputEngine.Route.Count, inputEngine.GetRouteLength());
            }
            else
            {
                Console.WriteLine("");
            }
        }

        private static void Main(string[] args)
        {
            bool flag = true;
            bool flag2 = true;
            try
            {
                Engine.Engine engine = new Engine.Engine();
                Airports airports = new Airports();
                while (flag)
                {
                    Program.RefreshConsole(engine);
                    flag2 = true;
                    Console.WriteLine("Enter your next destination, or quit pressing Q");
                    while (flag2)
                    {
                        string text = Console.ReadLine();
                        if (airports.PollTheData(text) != null)
                        {
                            engine.Route.Add(airports.PollTheData(text));
                            flag2 = false;
                        }
                        else
                        {
                            flag2 = false;
                        }
                        if (text.ToUpper() == "Q")
                        {
                            flag2 = false;
                            flag = false;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Whoops something went wrong");
                Console.WriteLine("Press any key to end program.");
                Console.ReadLine();
                flag2 = false;
                flag = false;
            }
        }
    }
}