Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Lab13
- {
- class Lab2
- {
- private int a;
- private int b;
- public void input()
- {
- Console.Write("Введите a = ");
- a = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите b = ");
- b = Convert.ToInt32(Console.ReadLine());
- }
- public int Perimetr()
- {
- int p = 0;
- p = (2 * (a + b));
- return p;
- }
- public void output(int p)
- {
- Console.WriteLine("Периметр прямоугольника со сторонами {0} и {1} равен {2}", a, b, p);
- }
- }
- class Lab3
- {
- private double m;
- private double x;
- public void input()
- {
- Console.Write("Введите m = ");
- m = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите x = ");
- x = Convert.ToDouble(Console.ReadLine());
- }
- public double calculate()
- {
- double z;
- z = Math.Sin(x) / (Math.Sqrt(Math.Abs(m * m * Math.Sin(1 - x) * Math.Sin(1 - x) - 10)));
- return z;
- }
- public void output(double z)
- {
- Console.WriteLine("Значение z = {0} из формулы задания №7 с переменными m = {1}, x = {2}", z, m, x);
- }
- }
- class Lab4
- {
- private double a;
- public double input()
- {
- Console.Write("Введите a = ");
- a = Convert.ToDouble(Console.ReadLine());
- return a;
- }
- public double Func(double a)
- {
- double f = 0;
- while ((a < -1) || (a > 1))
- {
- if (a < -1)
- {
- a += 2;
- }
- else if (a > 1) a -= 2;
- }
- if ((a<0)&&(a>=-1))
- {
- f = a;
- }
- if((a>=0)&&(a<=1))
- {
- f = 1 - a * a * a;
- }
- return f;
- }
- public void output(double f)
- {
- Console.WriteLine("Значение f({0}) = {1}", a, f);
- }
- }
- class Lab5
- {
- private int a;
- public void input()
- {
- Console.Write("Введите 10-чное число = ");
- a = Convert.ToInt32(Console.ReadLine());
- }
- public void calc()
- {
- int del = 1;
- int count = 1;
- while (a >= del)
- {
- del *= 2;
- count++;
- }
- int[] arr = new int[count];
- int i = 0;
- while(a!=1)
- {
- arr[i] = a % 2;
- a = a / 2;
- i++;
- }
- arr[i++] = 1;
- while (i >= 0)
- {
- Console.Write("{0}", arr[i]);
- i--;
- }
- Console.WriteLine();
- }
- }
- class Lab6
- {
- private List<int> a = new List<int>();
- int i;
- public void input()
- {
- i = 0;
- while (true)
- {
- Console.Write("Введите элемент a[{0}] = ", i);
- a.Add(Convert.ToInt32(Console.ReadLine()));
- Console.WriteLine("Нажмите ENTER, чтобы продолжить или ESC, чтобы прервать запись");
- if (Console.ReadKey(true).Key==ConsoleKey.Escape)
- {
- break;
- }
- i++;
- }
- }
- public void swap()
- {
- int max = Int32.MinValue;
- int ind = 0;
- for(int j = 1;j<=i;j++)
- {
- if (a[j] > max)
- {
- max = a[j];
- ind = j;
- }
- }
- max = a[0] + max;
- a[0] = max - a[0];
- a[ind] = max - a[0];
- }
- public void output()
- {
- for (int j = 0; j <= i; j++)
- Console.WriteLine("a[{0}] = {1}", j, a[j]);
- }
- }
- class Lab7
- {
- List<List<int>> ar = new List<List<int>>();
- List<int> row = new List<int>();
- int m = 0;
- int i = 0;
- int count = 0;
- int sum = 0;
- double srzna;
- public void input()
- {
- int j = 0;
- while (true)
- {
- row = new List<int>();
- j = 0;
- while(m == 0)//заполнение первой строчки с произвольной длиной
- {
- Console.Write("Введите элемент a[{0},{1}] = ", i,j);
- row.Add(Convert.ToInt32(Console.ReadLine()));
- sum += row[j];
- j++;
- count++;
- Console.WriteLine("Нажмите TAB, чтобы сменить строку и зафиксировать M или перейти к выходу, или ENTER, чтобы вводить дальше");
- if (Console.ReadKey(true).Key == ConsoleKey.Tab) break;
- }
- if (m == 0) m = j;
- else
- {
- for (j = 0; j < m; j++)//заполнение последующих с длиной, равной первой строчке
- {
- Console.Write("Введите элемент a[{0},{1}] = ", i, j);
- row.Add(Convert.ToInt32(Console.ReadLine()));
- sum += row[j];
- count++;
- }
- }
- ar.Add(row);
- Console.WriteLine("Нажмите ESC, если хотите прекратить заполнение, или ENTER, чтобы продолжить");
- if (Console.ReadKey(true).Key != ConsoleKey.Escape)
- {
- i++;
- }
- else break;
- }
- }
- public int calc()
- {
- srzna = sum / count;
- count = 0;
- for(int o = 0;o<=i;o++)
- {
- for(int p = 0;p<m;p++)
- {
- if (ar[o][p] < srzna)
- count++;
- }
- }
- return count;
- }
- public void output(int count)
- {
- Console.WriteLine("Количество элементов в массиве, меньших среднего = {0}", count);
- }
- }
- class Lab10
- {
- List<string> text = new List<string>();
- int n;
- public void input()
- {
- Console.Write("Введите количество строк = ");
- n = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Теперь вводите текст");
- for (int i = 0; i < n; i++)
- {
- text.Add(Console.ReadLine());
- }
- }
- public void exchange()
- {
- for (int i = 0; i < n; i++)
- {
- 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', '*');
- }
- }
- public void output()
- {
- for (int i = 0; i < n; i++)
- Console.WriteLine(text[i]);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("-= Лабораторная 13 =-\n\rВведите номер лабораторной вариант 7 (2-10)");
- int menu = 0;
- menu = Convert.ToInt32(Console.ReadLine());
- switch (menu)
- {
- case 2 :
- {
- Console.WriteLine("Расчет периметра прямоугольника со сторонами m, n");
- Lab2 p = new Lab2();
- p.input();
- p.output(p.Perimetr());
- break;
- }
- case 3:
- {
- Console.WriteLine("Расчет формулы");
- Lab3 p = new Lab3();
- p.input();
- p.output(p.calculate());
- break;
- }
- case 4:
- {
- Console.WriteLine("Периодическая функция указана на графике с заданием");
- Lab4 p = new Lab4();
- p.output(p.Func(p.input()));
- break;
- }
- case 5:
- {
- Console.WriteLine("Для вводимого целого положительного числа определите его двоичный эквивалент, используя алгоритм перевода числа в другую систему счисления путем деления числа на основание системы счисления.");
- Lab5 p = new Lab5();
- p.input();
- p.calc();
- break;
- }
- case 6:
- {
- Console.WriteLine("Дан вещественный массив А[N]. Поменять местами минимальный и последний нулевой элементы массива А.");
- Lab6 p = new Lab6();
- p.input();
- p.swap();
- p.output();
- break;
- }
- case 7:
- {
- Console.WriteLine("Дан вещественный массив А[N][М]. Определить количество элементов массива, которые меньше среднего арифметического значения всех элементов своей строки.");
- Lab7 p = new Lab7();
- p.input();
- p.output(p.calc());
- break;
- }
- case 8:
- {
- Console.WriteLine("Такой лабораторной нет в условии");
- break;
- }
- case 9:
- {
- Console.WriteLine("Такой лабораторной нет в условии");
- break;
- }
- case 10:
- {
- Console.WriteLine("В произвольном тексте, содержащем не более 10 строк, в каждой строке не более 80 символов, заменить каждую согласную букву символом *, а каждую гласную – символом #. Вывести полученный текст на экран.");
- Lab10 p = new Lab10();
- p.input();
- p.exchange();
- p.output();
- break;
- }
- }
- Console.WriteLine("Для завершения нажмите любую клавишу...");
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement