Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Progi / Lesson 8 / 8

.5.txt
Скачиваний:
28
Добавлен:
28.03.2015
Размер:
4.36 Кб
Скачать
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Nomer
{
static Exception e1; // = new Exception(""); // первое исключение
static Exception e2; // = new Exception(""); // второе исключение


protected double summa,dolg;
public double Dolg
{
get
{
return dolg;
}
set
{
if (value >= 0 && value < 1001)
{
dolg = value;
}
}
}
private string fam; // фамилия
private string ul; // фамилия


public void Init(double s, double d, string s1, string s2)
{
fam = s1;
ul = s2;
summa = s;
dolg = d;
}

public void Display()
{
string s, s1, s2;
s2 = "Фамилия: " + fam + ". Адрес: " + ul + ".";
Console.WriteLine(s2);
s1 = Convert.ToString(summa);
s = "Оплата за месяц: " + s1 + " ";
s1 = Convert.ToString(dolg);
s = s + "Долг: " + s1;
Console.WriteLine(s);
}
public void Read()
{
string s = "";
s = Console.ReadLine();
string[] s1;
s1 = s.Split(new char[] { ' ', '\t' },
StringSplitOptions.RemoveEmptyEntries);
summa = Convert.ToInt32(s1[0]);
dolg = Convert.ToInt32(s1[1]);
fam = Convert.ToString(s1[2]);
ul = Convert.ToString(s1[3]);
}
public double Numbersec()
{
return summa + dolg; // число секунд
}

public Nomer Add(Nomer a, Nomer b) // сложение 2 Record
{
Nomer k;
k = new Nomer();
k.summa = a.summa + b.summa;
k.dolg = a.dolg + b.dolg;
k.fam = b.fam;
k.ul = a.ul;
return k; // результат тип Record
}



static string scet(double n, double f)
{
string s1 = " ";

try
{
if (n == 0)
{
throw e1 = new Exception("Сумма не должна = 0"); // 1 исключение
}
if (f < 0)
{
throw e2 = new Exception("Долг не может быть < 0"); // 2 исключение
}
s1 = "количество = " + Convert.ToString(n) + " вес = " + Convert.ToString(f);

}
catch (Exception e1) // перехват первого исключения
{
string s;
s = e1.Message; // s="n=0"
Console.WriteLine(s);
Console.ReadKey();
System.Environment.Exit(0); // завершение программы
}
return s1;
}


static void Main(string[] args)
{
Nomer a = new Nomer();
a.Dolg = 26;
a.Dolg = 72; // не присвоилось a.sec=26 прежнее значение
double k;
k = a.Dolg; // k=26
Nomer b = new Nomer();
b.Init(2, 10, " Троицкий", "Сизова"); // 2 min, 10 sec
b.Display();
k = a.Numbersec();
Console.WriteLine("{0}", k);
Console.WriteLine(" ");
Nomer c = new Nomer();
c.Read();
c.Display();
Nomer d = new Nomer();
d = a.Add(b, c);
d.Display();


Nomer r = new Nomer();
double n, f;
string s;
f = 1;

r.Init(2, 10, " Троицкий", "Сизова");
n = r.summa;
f = r.Dolg;
try
{
s = scet(n, f);
}
catch (Exception e2) // перехват второго исключения
{
s = e2.Message;
Console.WriteLine(s);
Console.ReadKey();
System.Environment.Exit(0);
}


Console.WriteLine(s);

Console.ReadKey();
}
}

}
Соседние файлы в папке Lesson 8