Создание собственного класса и метода для вычисления выражения - C#

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

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

Добрый вечер. Есть программа, её нужно реализовать через метод и собственный класс. Помогите пожалуйста. Вот задание
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ConsoleApplication1
  6. {
  7. class Program
  8. {
  9. public static double r(double x, double q, double n)
  10. {
  11. double s = 0;
  12. double e = Math.Exp (x+q);
  13. double e1 = x + q;
  14. return s;
  15. }
  16. static void Main(string[] args)
  17. {
  18. double s ,x,q,n,e,e1;
  19. if (Math.Abs(x * q) < 10)
  20. {
  21. for (int i = 0; i < n; i++)
  22. {
  23. s += e;
  24. }
  25. }
  26. if (Math.Abs(x * q) == 10)
  27. {
  28. for (int i = 0; i < n; i++)
  29. {
  30. s += e1;
  31. }
  32. }
  33. Console.Write("Введите x = ");
  34. double x = Convert.ToDouble(Console.ReadLine());
  35. Console.Write("Введите q = ");
  36. double q = Convert.ToDouble(Console.ReadLine());
  37. Console.Write("Введите n = ");
  38. double n = Convert.ToDouble(Console.ReadLine());
  39. Console.WriteLine("s = " + r(x, q, n));
  40. Console.ReadKey();
  41. } } }

Решение задачи: «Создание собственного класса и метода для вычисления выражения»

textual
Листинг программы
  1. namespace ConsoleApplication1
  2. {
  3.     class myfunck
  4.     {
  5.         public static void func(double x, double q, double n)
  6.         {
  7.             double s = 0;
  8.             double e = Math.Exp(x + q);
  9.             double e1 = x + q;
  10.  
  11.             if (Math.Abs(x * q) < 10)
  12.             {
  13.                 for (int i = 0; i < n; i++)
  14.                     s += e;
  15.             }
  16.  
  17.             if (Math.Abs(x * q) == 10)
  18.             {
  19.                 for (int i = 0; i < n; i++)
  20.                     s += e1;
  21.             }
  22.  
  23.             Console.WriteLine("S= {0}", s);
  24.         }
  25.     }
  26.  
  27.     class Program
  28.     {
  29.         static void Main(string[] args)
  30.         {
  31.  
  32.         Console.WriteLine("Введите x = ");
  33.         double x = Convert.ToDouble(Console.ReadLine());
  34.         Console.WriteLine("Введите q = ");
  35.         double q = Convert.ToDouble(Console.ReadLine());
  36.         Console.WriteLine("Введите n = ");
  37.         double n = Convert.ToDouble(Console.ReadLine());
  38.  
  39.         myfunck.func(x, q, n); // вызов функции
  40.         Console.ReadLine();
  41.            
  42.         }
  43.      }
  44. }

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


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

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

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

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

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

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