Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Lab13
  5. {
  6.     class Lab2
  7.     {
  8.         private int a;
  9.         private int b;
  10.         public void input()
  11.         {
  12.             Console.Write("Введите a = ");
  13.             a = Convert.ToInt32(Console.ReadLine());
  14.             Console.Write("Введите b = ");
  15.             b = Convert.ToInt32(Console.ReadLine());
  16.         }
  17.         public int Perimetr()
  18.         {
  19.             int p = 0;
  20.             p = (2 * (a + b));
  21.             return p;
  22.         }
  23.         public void output(int p)
  24.         {
  25.             Console.WriteLine("Периметр прямоугольника со сторонами {0} и {1} равен {2}", a, b, p);
  26.         }
  27.     }
  28.     class Lab3
  29.     {
  30.         private double m;
  31.         private double x;
  32.         public void input()
  33.         {
  34.             Console.Write("Введите m = ");
  35.             m = Convert.ToDouble(Console.ReadLine());
  36.             Console.Write("Введите x = ");
  37.             x = Convert.ToDouble(Console.ReadLine());
  38.         }
  39.         public double calculate()
  40.         {
  41.             double z;
  42.             z = Math.Sin(x) / (Math.Sqrt(Math.Abs(m * m * Math.Sin(1 - x) * Math.Sin(1 - x) - 10)));
  43.             return z;
  44.         }
  45.         public void output(double z)
  46.         {
  47.             Console.WriteLine("Значение z = {0} из формулы задания №7 с переменными m = {1}, x = {2}", z, m, x);
  48.         }
  49.     }
  50.     class Lab4
  51.     {
  52.         private double a;
  53.         public double input()
  54.         {
  55.             Console.Write("Введите a = ");
  56.            
  57.             a = Convert.ToDouble(Console.ReadLine());
  58.             return a;
  59.         }
  60.        
  61.         public double Func(double a)
  62.         {
  63.             double f = 0;
  64.             while ((a < -1) || (a > 1))
  65.             {
  66.                 if (a < -1)
  67.                 {
  68.                     a += 2;
  69.                 }
  70.                 else if (a > 1) a -= 2;
  71.             }
  72.             if ((a<0)&&(a>=-1))
  73.             {
  74.                 f = a;
  75.             }
  76.             if((a>=0)&&(a<=1))
  77.             {
  78.                 f = 1 - a * a * a;
  79.             }
  80.             return f;
  81.         }
  82.         public void output(double f)
  83.         {
  84.             Console.WriteLine("Значение f({0}) = {1}", a, f);
  85.         }
  86.     }
  87.     class Lab5
  88.     {
  89.         private int a;
  90.         public void input()
  91.         {
  92.             Console.Write("Введите 10-чное число = ");
  93.             a = Convert.ToInt32(Console.ReadLine());
  94.         }
  95.         public void calc()
  96.         {
  97.             int del = 1;
  98.             int count = 1;
  99.             while (a >= del)
  100.             {
  101.                 del *= 2;
  102.                 count++;
  103.             }
  104.             int[] arr = new int[count];
  105.             int i = 0;
  106.             while(a!=1)
  107.             {
  108.                 arr[i] = a % 2;
  109.                 a = a / 2;
  110.                 i++;
  111.             }
  112.             arr[i++] = 1;
  113.             while (i >= 0)
  114.             {
  115.                 Console.Write("{0}", arr[i]);
  116.                 i--;
  117.             }
  118.             Console.WriteLine();
  119.         }
  120.     }
  121.     class Lab6
  122.     {
  123.         private List<int> a = new List<int>();
  124.         int i;
  125.         public void input()
  126.         {
  127.             i = 0;
  128.             while (true)
  129.             {
  130.                 Console.Write("Введите элемент a[{0}] = ", i);
  131.                 a.Add(Convert.ToInt32(Console.ReadLine()));
  132.                 Console.WriteLine("Нажмите ENTER, чтобы продолжить или ESC, чтобы прервать запись");
  133.                 if (Console.ReadKey(true).Key==ConsoleKey.Escape)
  134.                 {
  135.                     break;
  136.                 }
  137.                 i++;
  138.             }
  139.         }
  140.         public void swap()
  141.         {
  142.             int max = Int32.MinValue;
  143.             int ind = 0;
  144.             for(int j = 1;j<=i;j++)
  145.             {
  146.                 if (a[j] > max)
  147.                 {
  148.                     max = a[j];
  149.                     ind = j;
  150.                 }
  151.             }
  152.             max = a[0] + max;
  153.             a[0] = max - a[0];
  154.             a[ind] = max - a[0];
  155.         }
  156.         public void output()
  157.         {
  158.             for (int j = 0; j <= i; j++)
  159.                 Console.WriteLine("a[{0}] = {1}", j, a[j]);
  160.         }
  161.     }
  162.     class Lab7
  163.     {
  164.         List<List<int>> ar = new List<List<int>>();
  165.         List<int> row = new List<int>();
  166.         int m = 0;
  167.         int i = 0;
  168.         int count = 0;
  169.         int sum = 0;
  170.         double srzna;
  171.         public void input()
  172.         {
  173.             int j = 0;
  174.             while (true)
  175.             {
  176.                 row = new List<int>();
  177.                 j = 0;
  178.                 while(m == 0)//заполнение первой строчки с произвольной длиной
  179.                 {
  180.                     Console.Write("Введите элемент a[{0},{1}] = ", i,j);
  181.                     row.Add(Convert.ToInt32(Console.ReadLine()));
  182.                     sum += row[j];
  183.                     j++;
  184.                     count++;
  185.                     Console.WriteLine("Нажмите TAB, чтобы сменить строку и зафиксировать M или перейти к выходу, или ENTER, чтобы вводить дальше");
  186.                     if (Console.ReadKey(true).Key == ConsoleKey.Tab) break;
  187.                 }
  188.                 if (m == 0) m = j;
  189.                 else
  190.                 {
  191.                     for (j = 0; j < m; j++)//заполнение последующих с длиной, равной первой строчке
  192.                     {
  193.                         Console.Write("Введите элемент a[{0},{1}] = ", i, j);
  194.                         row.Add(Convert.ToInt32(Console.ReadLine()));
  195.                         sum += row[j];
  196.                         count++;
  197.                     }
  198.                 }
  199.                 ar.Add(row);
  200.                 Console.WriteLine("Нажмите ESC, если хотите прекратить заполнение, или ENTER, чтобы продолжить");
  201.                 if (Console.ReadKey(true).Key != ConsoleKey.Escape)
  202.                 {
  203.                     i++;
  204.                 }
  205.                 else break;
  206.             }
  207.            
  208.         }
  209.         public int calc()
  210.         {
  211.             srzna = sum / count;
  212.             count = 0;
  213.             for(int o = 0;o<=i;o++)
  214.             {
  215.                 for(int p = 0;p<m;p++)
  216.                 {
  217.                     if (ar[o][p] < srzna)
  218.                         count++;
  219.                 }
  220.             }
  221.             return count;
  222.         }
  223.         public void output(int count)
  224.         {
  225.             Console.WriteLine("Количество элементов в массиве, меньших среднего = {0}", count);
  226.         }
  227.     }
  228.     class Lab10
  229.     {
  230.         List<string> text = new List<string>();
  231.         int n;
  232.         public void input()
  233.         {
  234.             Console.Write("Введите количество строк = ");
  235.             n = Convert.ToInt32(Console.ReadLine());
  236.             Console.WriteLine("Теперь вводите текст");
  237.             for (int i = 0; i < n; i++)
  238.             {
  239.                 text.Add(Console.ReadLine());
  240.             }
  241.         }
  242.         public void exchange()
  243.         {
  244.             for (int i = 0; i < n; i++)
  245.             {
  246.                 text[i] = text[i].Replace('a', '#').Replace('i', '#').Replace('e', '#').Replace('o', '#').Replace('u', '#').Replace('q', '*').Replace('w', '*').Replace('r', '*').Replace('t', '*').Replace('p', '*').Replace('d', '*').Replace('s', '*').Replace('f', '*').Replace('g', '*').Replace('h', '*').Replace('j', '*').Replace('k', '*').Replace('l', '*').Replace('z', '*').Replace('x', '*').Replace('c', '*').Replace('v', '*').Replace('b', '*').Replace('n', '*').Replace('m', '*');
  247.             }
  248.  
  249.         }
  250.         public void output()
  251.         {
  252.             for (int i = 0; i < n; i++)
  253.                 Console.WriteLine(text[i]);
  254.         }
  255.     }
  256.     class Program
  257.     {
  258.         static void Main(string[] args)
  259.         {
  260.             Console.WriteLine("-= Лабораторная 13 =-\n\rВведите номер лабораторной вариант 7 (2-10)");
  261.             int menu = 0;
  262.             menu = Convert.ToInt32(Console.ReadLine());
  263.             switch (menu)
  264.             {
  265.                 case 2 :
  266.                     {
  267.                         Console.WriteLine("Расчет периметра прямоугольника со сторонами m, n");
  268.                         Lab2 p = new Lab2();
  269.                         p.input();
  270.                         p.output(p.Perimetr());
  271.                         break;
  272.                     }
  273.                 case 3:
  274.                     {
  275.                         Console.WriteLine("Расчет формулы");
  276.                         Lab3 p = new Lab3();
  277.                         p.input();
  278.                         p.output(p.calculate());
  279.                         break;
  280.                     }
  281.                 case 4:
  282.                     {
  283.                         Console.WriteLine("Периодическая функция указана на графике с заданием");
  284.                         Lab4 p = new Lab4();
  285.                         p.output(p.Func(p.input()));
  286.                         break;
  287.                     }
  288.                 case 5:
  289.                     {
  290.                         Console.WriteLine("Для вводимого целого положительного числа определите его двоичный эквивалент, используя алгоритм перевода числа в другую систему счисления путем деления числа на основание системы счисления.");
  291.                         Lab5 p = new Lab5();
  292.                         p.input();
  293.                         p.calc();
  294.                         break;
  295.                     }
  296.                 case 6:
  297.                     {
  298.                         Console.WriteLine("Дан вещественный массив А[N]. Поменять местами минимальный и последний нулевой элементы массива А.");
  299.                         Lab6 p = new Lab6();
  300.                         p.input();
  301.                         p.swap();
  302.                         p.output();
  303.                         break;
  304.                     }
  305.                 case 7:
  306.                     {
  307.                         Console.WriteLine("Дан вещественный массив А[N][М]. Определить количество элементов массива, которые меньше среднего арифметического значения всех элементов своей строки.");
  308.                         Lab7 p = new Lab7();
  309.                         p.input();
  310.                         p.output(p.calc());
  311.                         break;
  312.                     }
  313.                 case 8:
  314.                     {
  315.                         Console.WriteLine("Такой лабораторной нет в условии");
  316.                         break;
  317.                     }
  318.                 case 9:
  319.                     {
  320.                         Console.WriteLine("Такой лабораторной нет в условии");
  321.                         break;
  322.                     }
  323.                 case 10:
  324.                     {
  325.                         Console.WriteLine("В произвольном тексте, содержащем не более 10 строк, в каждой строке не более 80 символов, заменить каждую согласную букву символом *, а каждую гласную – символом #. Вывести полученный текст на экран.");
  326.                         Lab10 p = new Lab10();
  327.                         p.input();
  328.                         p.exchange();
  329.                         p.output();
  330.                         break;
  331.                     }
  332.  
  333.             }
  334.             Console.WriteLine("Для завершения нажмите любую клавишу...");
  335.             Console.ReadKey(true);
  336.         }
  337.     }
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement