Raizekas

Untitled

Jan 14th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.18 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. using System.IO;
  7.  
  8. namespace Ruoðimasis_egzaminui_1
  9. {
  10.     class Butas
  11.     {
  12.         public string Adresas { get; set; }
  13.         public double Plotas { get; set; }
  14.         public int KambSk { get; set; }
  15.  
  16.         public Butas(string adresas, double plotas, int kambSk)
  17.         {
  18.             this.Adresas = adresas;
  19.             this.Plotas = plotas;
  20.             this.KambSk = kambSk;
  21.         }
  22.     }
  23.  
  24.     class Namas
  25.     {
  26.         public const int MaxButuSk = 100;
  27.  
  28.         public Butas[] Butai { get; set; }
  29.         public int CountButai { get; set; }
  30.         public double didButas {get; set; }
  31.  
  32.         public Namas()
  33.         {
  34.             Butai = new Butas[MaxButuSk];
  35.         }
  36.  
  37.         public void AddButai(Butas but)
  38.         {
  39.             Butai[CountButai] = but;
  40.             CountButai++;
  41.         }
  42.  
  43.         public double DidziausiasButas()
  44.         {
  45.             double max = Butai[0].Plotas; ;
  46.  
  47.             for (int i = 1; i < CountButai; i++)
  48.             {
  49.                 if (Butai[i].Plotas > max)
  50.                 {
  51.                     max = Butai[i].Plotas;
  52.                 }
  53.             }
  54.             Console.WriteLine(max);
  55.             return max;
  56.         }
  57.     }
  58.  
  59.     class Program
  60.     {
  61.         const int MaxNamaiNumb = 100;
  62.         static void Main(string[] args)
  63.         {
  64.             int count = 0;
  65.             Namas[] N = new Namas[MaxNamaiNumb];
  66.             ReadAllButaiData("Butas.txt", ref N, ref count);
  67.             for (int i = 0; i < count; i++)
  68.             {
  69.                 N[i].didButas = N[i].DidziausiasButas();
  70.                 Console.WriteLine("Didziausio buto name dydis: " + N[i].didButas);
  71.             }
  72.         }
  73.  
  74.         private static void ReadAllButaiData(string file, ref Namas[] N, ref int count)
  75.         {
  76.             using (StreamReader reader = new StreamReader(file, System.Text.Encoding.GetEncoding(1257)))
  77.             {
  78.                 string line = null;
  79.                 line = reader.ReadLine();
  80.  
  81.                 while ((line != null) && (line.Contains(';')))
  82.                 {
  83.                     N[count] = new Namas();
  84.                     string[] value = line.Split(';');
  85.                     string adresas = value[0];
  86.                     double plotas = double.Parse(value[1]);
  87.                     int kambSk = int.Parse(value[2]);
  88.  
  89.                     Butas but = new Butas(adresas, plotas, kambSk);
  90.  
  91.                     if (!N[count].Butai.Contains(but))
  92.                     {
  93.                         N[count].AddButai(but);
  94.                     }
  95.                     line = reader.ReadLine();
  96.                     count++;
  97.                 }
  98.                
  99.             }
  100.         }
  101.         static double MaxButoPlotas(Namas N)
  102.         {
  103.             double max = N.Butai[0].Plotas; ;
  104.  
  105.             for (int i = 1; i < N.CountButai; i++)
  106.             {
  107.                 if (N.Butai[i].Plotas > max)
  108.                 {
  109.                     max = N.Butai[i].Plotas;
  110.                 }
  111.             }
  112.             Console.WriteLine(max);
  113.             return max;
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment