Advertisement
Rolex_

Task_Classes

Jun 20th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Task1_Class
  8. {
  9.     class Square
  10.     {
  11.         private int sqSide;
  12.         public int SqSide
  13.         {
  14.             get => sqSide;
  15.             set
  16.             {
  17.                 if (value > 0)
  18.                 {
  19.                     sqSide = value;
  20.                     SqDiag = sqSide * Math.Sqrt(2);
  21.                 }
  22.             }
  23.         }
  24.  
  25.         public double SqDiag { get; private set; }
  26.         public double SqCount
  27.         {
  28.             get
  29.             {
  30.                 double Area = Math.Pow(sqSide, 2);
  31.                 return Area;
  32.             }
  33.         }
  34.         public double PerCount
  35.         {
  36.             get
  37.             {
  38.                 double Per = 4 * sqSide;
  39.                 return Per;
  40.             }
  41.         }
  42.  
  43.     }
  44.  
  45.     class ArithmeticProgression
  46.     {
  47.         private readonly int A_first;
  48.         private readonly int A_d;
  49.         private readonly int A_n;
  50.  
  51.         public ArithmeticProgression(int Ar1 = 0, int d = 0, int n = 0)
  52.         {
  53.             A_first = Ar1;
  54.             A_d = d;
  55.             A_n = n;
  56.         }
  57.  
  58.         public void GetInfo() => Console.WriteLine("Первый член прогресси: " + A_first + "Разница прогресси: " + A_d + "N-ый член прогресси: " + A_n);
  59.  
  60.         public int Avarage_APSum()
  61.         {
  62.             return A_n * ((2 * A_first) + ((A_n - 1) * A_d)) / 2;
  63.         }
  64.     }
  65.  
  66.     class Program
  67.     {
  68.         static void Main(string[] args)
  69.         {
  70.             Console.WriteLine("(1) Задача");
  71.             Console.Write("Введите сторону квадрата: ");
  72.  
  73.             Square SqObj = new Square
  74.             {
  75.                 SqSide = int.Parse(Console.ReadLine())
  76.             };
  77.  
  78.             ResultSquare(SqObj);
  79.  
  80.             DelayScreen();
  81.  
  82.             //
  83.             Console.WriteLine("(2) Задача");
  84.             InitializeProgression(out int A_1, out int D, out int A_N);
  85.  
  86.             ArithmeticProgression obj = new ArithmeticProgression(A_1, D, A_N);
  87.  
  88.             ResultProgression(A_N, obj);
  89.         }
  90.  
  91.         private static void DelayScreen()
  92.         {
  93.             Console.ReadKey(true);
  94.             Console.Clear();
  95.         }
  96.  
  97.         private static void ResultSquare(Square SqObj)
  98.         {
  99.             Console.WriteLine("Диагональ квадрата: " + SqObj.SqDiag);
  100.             Console.WriteLine("Площадь квадрата: " + SqObj.SqCount);
  101.             Console.WriteLine("Периметр квадрата: " + SqObj.PerCount);
  102.         }
  103.  
  104.         private static void InitializeProgression(out int A_1, out int D, out int A_N)
  105.         {
  106.             Console.Write("Введите первый член прогресии: ");
  107.             A_1 = int.Parse(Console.ReadLine());
  108.             Console.Write("Введите разницу прогресии: ");
  109.             D = int.Parse(Console.ReadLine());
  110.             Console.Write("Введите n-ый член прогресии: ");
  111.             A_N = int.Parse(Console.ReadLine());
  112.         }
  113.         private static void ResultProgression(int A_N, ArithmeticProgression obj)
  114.         {
  115.             Console.WriteLine($"\nСреднее арифметическое первых членов: {obj.Avarage_APSum() / A_N}");
  116.             Console.WriteLine($"Сумма первых n членов прогрессии: {obj.Avarage_APSum()}");
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement