Причина ошибки "A get or set accessor expected" - C#

Узнай цену своей работы

Формулировка задачи:

Листинг программы
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Threading;
  5. namespace optimizationMethods {
  6. public class MethodSegmentIntoThree
  7. {
  8. public static readonly double EPS = 0.0001;
  9. public static double f (double x)
  10. {
  11. return (Math.Sqrt(x*x + 25) + Math.Sqrt ((20-x)*(20-x)+100) +0.1);
  12. }
  13.  
  14. public static double[] setSegment() throws IOException //просит поставить
  15. // точку с запятой перед throws error CS1002: ; expected
  16. {
  17. double[] x = new double[4]; //выдаёт error CS1014: A get or set
  18. // accessor expected
  19. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  20. Console.WriteLine("Введите отрезок [a; b], на котором будем искать стационарную точку");
  21. Console.WriteLine("x1 = ");
  22. x[0] = Double.parseDouble(reader.readLine());
  23. x[1] = 0; x[2] = 0;
  24. Console.WriteLine("x4= ");
  25. x[3] = Double.parseDouble(reader.readLine());
  26. System.out.prinln("Ищем стационарную точку...");
  27. return x;
  28. }
  29. public static double segIntoThree (double[] x)
  30. {
  31. while ( Math.Abs(x[3] - x[0] ) >=EPS )
  32. {
  33. x[1]=x[0]+(x[3]-x[0])/3;
  34. x[2]=x[3]-(x[3]-x[0])/3;
  35. if (f(x[1]) < f(x[2]))
  36. x[3]= x[2];
  37. else
  38. x[0] = x[1];
  39. }
  40. return (x[0] + x[3] ) / 2;
  41. }
  42. public static void main(string[] args)
  43. {
  44. try
  45. {
  46. double[] x = setSegment();
  47. Console.WriteLine("Точка минимума z = " + segIntoThree(x));
  48. Console.WriteLine("f(z) = " +f(segIntoThree(x)));
  49. Console.WriteLine("Значение функции(для проверки): f(z) = f(3) = " +f(6.6667));
  50. }
  51. catch (IOException e)
  52. {
  53. e.printStackTrace();
  54. }
  55. }
  56. } }

Решение задачи: «Причина ошибки "A get or set accessor expected"»

textual
Листинг программы
  1. using System;
  2.   using System.IO;
  3.   using System.Text;
  4.   using System.Threading;
  5.  
  6.  
  7.  
  8.   namespace optimizationMethods {
  9.   public class MethodSegmentIntoThree
  10. {
  11.  
  12.   public static readonly double EPS = 0.0001;
  13.   public static double f (double x)
  14.    {
  15.       return (Math.Sqrt(x*x + 25) + Math.Sqrt ((20-x)*(20-x)+100) +0.1);
  16.    }
  17.  
  18.  
  19.   public static double[] setSegment()
  20.      {
  21.        double[] x = new double[4];
  22.          BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  23. //error CS1041: Identifier expected; 'in' is a keyword
  24. // the type of namespace bufferedreader could not be found
  25. //  the type of namespace InputStreamReader could not be found
  26. // error CS1525: Invalid expression term 'in
  27.          Console.WriteLine("Введите отрезок [a; b], на котором будем искать стационарную точку");
  28.  
  29.          Console.WriteLine("x1 = ");
  30.          x[0] = Double.parseDouble(reader.readLine());
  31.  
  32.          x[1] = 0; x[2] = 0;
  33.          Console.WriteLine("x4= ");
  34.          x[3] = Double.parseDouble(reader.readLine());
  35.  
  36.          System.out.prinln("Ищем стационарную точку...");
  37.  
  38.          return x;
  39. }
  40.  
  41.          public static double segIntoThree (double[] x)
  42.          {
  43.                while ( Math.Abs(x[3] - x[0] ) >=EPS )
  44.                {  
  45.                    x[1]=x[0]+(x[3]-x[0])/3;
  46.                    x[2]=x[3]-(x[3]-x[0])/3;
  47.                  if (f(x[1]) < f(x[2]))
  48.                       x[3]= x[2];
  49.               else
  50.                      x[0] = x[1];
  51.                 }
  52.            return (x[0] + x[3] ) / 2;
  53.          }
  54.         public static void main(string[] args)
  55.         {
  56.            try
  57.             {
  58.                   double[] x = setSegment();
  59.                   Console.WriteLine("Точка минимума z = " + segIntoThree(x));
  60.                   Console.WriteLine("f(z) = " +f(segIntoThree(x)));
  61.                   Console.WriteLine("Значение функции(для проверки): f(z) = f(3) = " +f(6.6667));
  62.          }
  63.          catch (IOException e)
  64.           {
  65.              e.printStackTrace();
  66. //error CS1061:
  67. //'System.IO.IOException' does not contain a definition for 'printStackTrace' and no extension method 'printStackTrace' //accepting a first argument of type 'System.IO.IOException' could be found (are you missing a using directive or an //assembly reference?)
  68.  
  69.           }
  70.      }
  71. } }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

5   голосов , оценка 3.6 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут