Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Serialization;
- namespace ConsoleApp10
- {
- public static class Prices
- {
- public static int _intern = 5;
- public static int _extern = 10;
- }
- [Serializable]
- public class Subscriber
- {
- static Random ran = new Random();
- public int ID;
- public string Surname;
- public string Name;
- public int balance;
- public int externalCalls;
- public int internalCalls;
- public static int operator +(Subscriber s, int C)
- {
- s.balance += C;
- return s.balance;
- }
- public static bool operator true (Subscriber s)
- {
- return (s.balance >= (s.internalCalls * Prices._intern + s.externalCalls * Prices._extern));
- }
- public static bool operator false(Subscriber s)
- {
- return (s.balance < (s.internalCalls * Prices._intern + s.externalCalls * Prices._extern));
- }
- public override string ToString()
- {
- return $"ID : {ID}\nName: {Name}\nSurname: {Surname}\nBalance: {balance}" +
- $"\nExternal calls time: {externalCalls}\nInternal calls time: {internalCalls}\n\n";
- }
- public Subscriber(int id, string name, string surname, int balance, int i, int e)
- {
- ID = id + 1000;
- this.Name = name;
- this.Surname = surname;
- this.balance = balance;
- this.internalCalls = i;
- this.externalCalls = e;
- }
- public Subscriber()
- {
- }
- }
- [Serializable]
- public class Subscribers
- {
- public int K;
- public Subscriber[] subs;
- public Subscribers() { }
- public Subscribers(Subscriber[] ar)
- {
- subs = ar;
- K = ar.Length;
- }
- }
- class Program
- {
- static Random ran = new Random();
- static void Main(string[] args)
- {
- int N;
- Console.WriteLine("enter number");
- N = int.Parse(Console.ReadLine());
- Subscriber[] arr = new Subscriber[N];
- for (int i = 0; i < N; i++)
- {
- arr[i] = new Subscriber(ran.Next(), "Vasya" + i, "Pupkin" + i, ran.Next(10, 10001), ran.Next(100, 500), ran.Next(10, 1001));
- }
- Subscribers subscrss = new Subscribers(arr);
- foreach (Subscriber s in subscrss.subs)
- {
- Console.WriteLine(s.ToString());
- }
- XmlSerializer ser = new XmlSerializer(typeof(Subscribers));
- FileStream fs = new FileStream("@../../../../subs.ser", FileMode.Create, FileAccess.ReadWrite);
- ser.Serialize(fs, subscrss);
- Console.WriteLine("success");
- fs.Close();
- FileStream newfs = new FileStream("@../../../../subs.ser", FileMode.Open, FileAccess.ReadWrite);
- Subscribers newsubs = (Subscribers)ser.Deserialize(newfs);
- newfs.Close();
- foreach (Subscriber s in newsubs.subs)
- {
- Console.WriteLine(s.ToString());
- }
- var poor =
- from s in arr
- let s1 = s
- where s1.Equals(false)
- select s1;
- foreach (Subscriber p in poor)
- {
- Console.WriteLine("\n\n\n\n\n\n");
- Console.WriteLine(p.ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment