Создание собственного класса и метода для вычисления выражения - C#
Формулировка задачи:
Добрый вечер. Есть программа, её нужно реализовать через метод и собственный класс. Помогите пожалуйста.
Вот задание
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- public static double r(double x, double q, double n)
- {
- double s = 0;
- double e = Math.Exp (x+q);
- double e1 = x + q;
- return s;
- }
- static void Main(string[] args)
- {
- double s ,x,q,n,e,e1;
- if (Math.Abs(x * q) < 10)
- {
- for (int i = 0; i < n; i++)
- {
- s += e;
- }
- }
- if (Math.Abs(x * q) == 10)
- {
- for (int i = 0; i < n; i++)
- {
- s += e1;
- }
- }
- Console.Write("Введите x = ");
- double x = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите q = ");
- double q = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите n = ");
- double n = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("s = " + r(x, q, n));
- Console.ReadKey();
- } } }
Решение задачи: «Создание собственного класса и метода для вычисления выражения»
textual
Листинг программы
- namespace ConsoleApplication1
- {
- class myfunck
- {
- public static void func(double x, double q, double n)
- {
- double s = 0;
- double e = Math.Exp(x + q);
- double e1 = x + q;
- if (Math.Abs(x * q) < 10)
- {
- for (int i = 0; i < n; i++)
- s += e;
- }
- if (Math.Abs(x * q) == 10)
- {
- for (int i = 0; i < n; i++)
- s += e1;
- }
- Console.WriteLine("S= {0}", s);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Введите x = ");
- double x = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Введите q = ");
- double q = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Введите n = ");
- double n = Convert.ToDouble(Console.ReadLine());
- myfunck.func(x, q, n); // вызов функции
- Console.ReadLine();
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д