Guest User

Untitled

a guest
Sep 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Xml.Serialization;
  9.  
  10. namespace ConsoleApp10
  11. {
  12.  
  13.  
  14. public static class Prices
  15. {
  16. public static int _intern = 5;
  17. public static int _extern = 10;
  18. }
  19.  
  20. [Serializable]
  21. public class Subscriber
  22. {
  23. static Random ran = new Random();
  24.  
  25.  
  26. public int ID;
  27.  
  28. public string Surname;
  29.  
  30. public string Name;
  31.  
  32. public int balance;
  33.  
  34. public int externalCalls;
  35.  
  36. public int internalCalls;
  37.  
  38. public static int operator +(Subscriber s, int C)
  39. {
  40. s.balance += C;
  41. return s.balance;
  42. }
  43.  
  44. public static bool operator true (Subscriber s)
  45. {
  46. return (s.balance >= (s.internalCalls * Prices._intern + s.externalCalls * Prices._extern));
  47. }
  48.  
  49. public static bool operator false(Subscriber s)
  50. {
  51. return (s.balance < (s.internalCalls * Prices._intern + s.externalCalls * Prices._extern));
  52. }
  53.  
  54. public override string ToString()
  55. {
  56. return $"ID : {ID}\nName: {Name}\nSurname: {Surname}\nBalance: {balance}" +
  57. $"\nExternal calls time: {externalCalls}\nInternal calls time: {internalCalls}\n\n";
  58. }
  59.  
  60. public Subscriber(int id, string name, string surname, int balance, int i, int e)
  61. {
  62. ID = id + 1000;
  63. this.Name = name;
  64. this.Surname = surname;
  65. this.balance = balance;
  66. this.internalCalls = i;
  67. this.externalCalls = e;
  68. }
  69.  
  70. public Subscriber()
  71. {
  72. }
  73. }
  74.  
  75. [Serializable]
  76. public class Subscribers
  77. {
  78. public int K;
  79. public Subscriber[] subs;
  80.  
  81. public Subscribers() { }
  82.  
  83. public Subscribers(Subscriber[] ar)
  84. {
  85. subs = ar;
  86. K = ar.Length;
  87. }
  88. }
  89.  
  90.  
  91. class Program
  92. {
  93. static Random ran = new Random();
  94. static void Main(string[] args)
  95. {
  96. int N;
  97. Console.WriteLine("enter number");
  98. N = int.Parse(Console.ReadLine());
  99.  
  100. Subscriber[] arr = new Subscriber[N];
  101.  
  102. for (int i = 0; i < N; i++)
  103. {
  104. arr[i] = new Subscriber(ran.Next(), "Vasya" + i, "Pupkin" + i, ran.Next(10, 10001), ran.Next(100, 500), ran.Next(10, 1001));
  105. }
  106. Subscribers subscrss = new Subscribers(arr);
  107.  
  108. foreach (Subscriber s in subscrss.subs)
  109. {
  110. Console.WriteLine(s.ToString());
  111. }
  112.  
  113. XmlSerializer ser = new XmlSerializer(typeof(Subscribers));
  114. FileStream fs = new FileStream("@../../../../subs.ser", FileMode.Create, FileAccess.ReadWrite);
  115.  
  116. ser.Serialize(fs, subscrss);
  117. Console.WriteLine("success");
  118. fs.Close();
  119.  
  120. FileStream newfs = new FileStream("@../../../../subs.ser", FileMode.Open, FileAccess.ReadWrite);
  121. Subscribers newsubs = (Subscribers)ser.Deserialize(newfs);
  122.  
  123. newfs.Close();
  124.  
  125. foreach (Subscriber s in newsubs.subs)
  126. {
  127. Console.WriteLine(s.ToString());
  128. }
  129.  
  130.  
  131. var poor =
  132. from s in arr
  133. let s1 = s
  134. where s1.Equals(false)
  135. select s1;
  136.  
  137. foreach (Subscriber p in poor)
  138. {
  139. Console.WriteLine("\n\n\n\n\n\n");
  140. Console.WriteLine(p.ToString());
  141. }
  142. }
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment