Пятая лаба
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication14
{
class Transport //класс Транспортное средство
{
string TrName; //поле класса имени транспорта
public double Speed; //поле экзем-а класса скорость
public Transport(string Name) //1й конструктор
{
this.TrName = Name;
}
public string Imya //свойство
{
get { return this.TrName; }
}
public void SmenaImeni(string TrName) //метод класса
{
this.TrName = TrName;
}
public virtual void PrintFnc()
{
Console.WriteLine("____________________");
Console.WriteLine("Марка: " + this.Imya);
Console.WriteLine("____________________");
}
public virtual void Speeds()
{
Console.WriteLine("====================");
Console.WriteLine("Скорость: " + this.Speed);
Console.WriteLine("====================");
}
}
class Auto : Transport //подкласс Автомобиль
{
public const string name = "Автомобиль";
public string AModel; //поля
public int ABorn;
public string AToplivo;
public Auto(string Name, string model):base(Name) //1й конструктор
{
this.AModel = model;
this.AToplivo = "Бензин";
this.ABorn = 2008;
}
public Auto(string Name, string model, string toplivo):base(Name) //2й конструктор
{
this.AModel = model;
this.AToplivo = toplivo;
this.ABorn = 2008;
}
public Auto(string Name, string model, string toplivo, int born):base(Name)
//3й конструктор
{
this.AModel = model;
this.AToplivo = toplivo;
this.ABorn = born;
}
public override void PrintFnc()
{
Console.WriteLine("____________________");
Console.WriteLine("Автомобиль марки "+this.Imya);
Console.WriteLine("Модель: {0}",AModel);
Console.WriteLine("Топливо: {0}", AToplivo);
Console.WriteLine("Создан: {0}", ABorn);
Console.WriteLine("____________________");
}
}
class Train : Transport //подкласс поезд
{
public const string name = "Поезд";
public string TModel; //поля
public int TBorn;
public string TToplivo;
public int TKolvoVag = 0;
public Train(string Name, string model):base(Name) //1й конструктор
{
this.TModel = model;
this.TToplivo = "ДТ";
this.TBorn = 2008;
}
public Train(string Name, string model, string toplivo):base(Name) //2й конструктор
{
//this.TModel = model;
this.TToplivo = toplivo;
this.TBorn = 2008;
}
public Train(string Name, string model, string toplivo, int born):base(Name)
//3й конструктор
{
this.TModel = model;
this.TToplivo = toplivo;
this.TBorn = born;
}
public int Vagon //Свойство
{
get
{
return this.TKolvoVag;
}
set
{
if (value >= 0) this.TKolvoVag = value;
}
}
public override void PrintFnc()
{
Console.WriteLine("____________________");
Console.WriteLine("Поезд марки " + this.Imya);
Console.WriteLine("Модель: {0}", TModel);
Console.WriteLine("Топливо: {0}", TToplivo);
Console.WriteLine("Создан: {0}", TBorn);
Console.WriteLine("Вагонов: {0}", this.Vagon);
Console.WriteLine("____________________");
}
}
class Express : Train //подподкласс Эксресс
{
public const string name = "Экспресс";
public string XModel; //поля
public int XBorn;
string XToplivo = "Электричество";
public int XKolvoVag = 0;
public int XKolvoLok = 1;
public Express(string Name, string model):base(Name,model) //1й конструктор
{
this.XModel = model;
this.XBorn = 2008;
}
public Express(string Name, string model, int born):base(Name,model) //2й конструктор
{
this.XModel = model;
this.XBorn = born;
}
public int Vagon //Свойство
{
get
{
return this.XKolvoVag;
}
set
{
if (value >= 0) this.XKolvoVag = value;
}
}
public int Lokomotiv //Свойство
{
get
{
return this.XKolvoLok;
}
set
{
if ((value > 0) && (value <= 2)) this.XKolvoLok = value;
}
}
public override void PrintFnc()
{
Console.WriteLine("____________________");
Console.WriteLine("Поезд марки " + this.Imya);
Console.WriteLine("Тип: " + Express.name);
Console.WriteLine("Модель: {0}", XModel);
Console.WriteLine("Топливо: {0}", XToplivo);
Console.WriteLine("Создан: {0}", XBorn);
Console.WriteLine("Вагонов: {0}", this.Vagon);
Console.WriteLine("Локомотивов: {0}", this.Lokomotiv);
Console.WriteLine("____________________");
}
}
class Airplane : Transport
{
double AirSpeed = 0;
public Airplane(string Name):base(Name) //1й конструктор
{
//this.TrName = Name;
}
public override void Speeds()
{
Console.WriteLine("====================");
Console.WriteLine("Скорость: " + this.Speed);
Console.WriteLine("Воздушная скорость: "+this.AirSpeed);
Console.WriteLine("====================");
}
public void Polet(double AirSp)
{
this.AirSpeed = AirSp;
}
}
class Program
{
static void Main(string[] args)
{
string NameOfTrnsprt = "BMW";
Transport MoyTr = new Transport(NameOfTrnsprt);
MoyTr.Speed = 100.63;
MoyTr.SmenaImeni("Ромасевич");
Auto SuperGT = new Auto("Ромасевич", "SuperGT");
Auto V13 = new Auto("Ромасевич", "V13", "Газ");
Auto NeKalina = new Auto("Ромасевич", "z5","Водород",2005);
Train TPZ1 = new Train("Ромасевич", "ТПЗ-1");
Train PVZ1 = new Train("Ромасевич", "Паравоз-1", "Уголь");
Train EV1 = new Train("Ромасевич", "ЭВ-1", "Электричество",
2006);
TPZ1.Vagon = 10;
Express X2 = new Express("Ромасевич", "X-2");
Express X1 = new Express("Ромасевич", "X-1", 2006);
X1.Lokomotiv = 2;
X2.Vagon = 30;
Airplane SuperJet = new Airplane("РомасевичВоздух");
SuperJet.Polet(1200.23);
SuperGT.PrintFnc();
V13.PrintFnc();
NeKalina.PrintFnc();
TPZ1.PrintFnc();
PVZ1.PrintFnc();
EV1.PrintFnc();
X1.PrintFnc();
X2.PrintFnc();
MoyTr.Speeds();
SuperJet.Speeds();
Console.ReadLine();
}
}
}
Третья лаба, шестое задание для Стука
using System;
using System.Collections.Generic;
using System.Text;
namespace StukLab3_6
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите количество строк");
int strok=int.Parse(Console.ReadLine());
Console.WriteLine("Введите количество столбцов");
int stolb = int.Parse(Console.ReadLine());
int[,] Massiv=new int[strok,stolb];
Random rnd = new Random();
for (int i = 0; i < strok; i++)
{
for(int j=0;j<stolb;j++)
{
Massiv[i, j] = rnd.Next(-7, 20);
}
}
int OtrInx=0, NullInx=0, ChetInx=0, NChetInx=0;
foreach (int elm in Massiv)
{
if (elm < 0) OtrInx++;
if (elm == 0) NullInx++;
if (elm / 2 * 2 == elm) ChetInx++; else NChetInx++;
}
int[] OtrMas = new int[OtrInx], NullMas = new int[NullInx], ChetMas = new
int[ChetInx], NChetMas = new int[NChetInx];
OtrInx=0;NullInx=0;ChetInx=0;NChetInx=0;
foreach (int elm in Massiv)
{
if (elm < 0) { OtrMas[OtrInx] = elm; OtrInx++; }
if (elm == 0) {NullMas[NullInx]=elm; NullInx++;}
if (elm / 2 * 2 == elm) { ChetMas[ChetInx] = elm; ChetInx++; } else { NChetMas[NChetInx]
= elm; NChetInx++; }
}
for (int i = 0; i < strok; i++)
{
for (int j = 0; j < stolb; j++)
{
Console.Write(Massiv[i, j].ToString()+"\t");
}
Console.WriteLine();
}
for(int i=0;i<OtrMas.Length;i++)
{
Console.Write(OtrMas[i].ToString() + " ");
}
Console.WriteLine();
for (int i = 0; i < NullMas.Length; i++)
{
Console.Write(NullMas[i].ToString() + " ");
}
Console.WriteLine();
for (int i = 0; i < ChetMas.Length; i++)
{
Console.Write(ChetMas[i].ToString() + " ");
}
Console.WriteLine();
for (int i = 0; i < NChetMas.Length; i++)
{
Console.Write(NChetMas[i].ToString() + " ");
}
Console.WriteLine();
Console.ReadLine();
}
}
}
Девятая лаба для Любимова
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace LyubimLab9
{
class Program
{
private static bool IsGlas(char x)
{
char[] glas ={ 'К', 'Й', 'Ц', 'Н', 'Г', 'Ш', 'Щ', 'З', 'Х', 'Ф', 'Ё', 'У',
'Е', 'Ы', 'А', 'О', 'Э', 'Я', 'И', 'Ю','В',
'П','Р','Л','Д','Ж','Ч','С','М','Т','Б' };
foreach (char elm in glas)
{
if (x == elm) return true;
}
return false;
}
static void Main(string[] args)
{
StreamReader TextFile = new StreamReader("text.txt");
string text=TextFile.ReadToEnd();
int PntInx=0;
for (int i = 0; i < text.Length; i++)
{
if (((text[i] == ' ') || (text[i] == '\n')) && (IsGlas(text[i + 1])))
PntInx++;
}
int[] PntMas = new int[PntInx];
PntInx = 0;
for (int i = 0; i < text.Length; i++)
{
if (((text[i] == ' ') || (text[i] == '\n')) && (IsGlas(text[i + 1])))
{ PntMas[PntInx] = i; PntInx++; }
}
char[] CharText = text.ToCharArray();
int Start = 0;
string text2="";
foreach (int elm in PntMas)
{
for (int i = Start; i < elm; i++)
{
text2 += CharText[i];
}
text2 += ".";
Start = elm;
}
for (int i = Start; i < CharText.Length; i++)
{
text2 += CharText[i];
}
text2 += ".";
Console.WriteLine(text2);
Console.ReadLine();
}
}
}