Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Consolee
- {
- class series
- {
- private int i;
- progression[] massive = new progression[4];
- public series(bool is_linear, params int[] files)
- {
- foreach (int elem in files)
- {
- if (is_linear)
- {
- massive[i] = new linear(elem);
- i++;
- }
- else
- {
- massive[i] = new exponential(elem);
- i++;
- }
- }
- }
- public void cons()
- {
- foreach (progression elem in massive)
- {
- elem.print();
- }
- }
- }
- abstract class progression
- {
- protected short a1, d, position, an, n;
- public progression(int first)
- {
- this.a1 = (short)first;
- Console.WriteLine("Введите номер последнего суммируемого элемена:");
- while (!(Int16.TryParse(Console.ReadLine(), out n)))
- {
- Console.WriteLine("Число!");
- }
- Console.WriteLine("Введите значение последнего суммируемого элемена:");
- while (!(Int16.TryParse(Console.ReadLine(), out an)))
- {
- Console.WriteLine("Число!");
- }
- Console.WriteLine("Введите номер искомого элемента:");
- while (!(Int16.TryParse(Console.ReadLine(), out position)))
- {
- Console.WriteLine("Число!");
- }
- Console.WriteLine("Введите разность прогрессии:");
- while (!(Int16.TryParse(Console.ReadLine(), out d)))
- {
- Console.WriteLine("Число!");
- }
- }
- public abstract double get();
- public abstract double sum();
- public abstract void print();
- }
- class linear : progression
- {
- public override double get()
- {
- return a1 + (position - 1) * d;
- }
- public override double sum()
- {
- return (a1 + an) * n / 2;
- }
- public linear(int first)
- : base(first)
- {
- }
- public override void print()
- {
- Console.WriteLine("Сумма арифметической прогрессии: {0}, Значение {1} элемента равно {2} ", sum(), position, get());
- }
- }
- class exponential : progression
- {
- public override double get()
- {
- return a1 * Math.Pow(d, (position - 1));
- }
- public override double sum()
- {
- return (a1 + an) * n / 2;
- }
- public exponential(int first)
- : base(first)
- {
- }
- public override void print()
- {
- Console.WriteLine("Сумма геометрической прогрессии: {0}, Значение {1} элемента равно {2} ", sum(), position, get());
- }
- }
- class maindd
- {
- static void Main(string[] args)
- {
- series a = new series(true, 1, 4, 5, 6);
- series b = new series(false, 1, 4, 5, 6);
- a.cons();
- b.cons();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement