Guest User

Untitled

a guest
Dec 14th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 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 ConsoleApplication2
  9. {
  10. class Program
  11. {
  12. struct Gost
  13. {
  14. public string name;
  15. public double stoimost;
  16. public int mesta;
  17. public int zayavka;
  18. public int dneypredvopl;
  19. public Gost(string n, int s, int m, int z, int d)
  20. {
  21. name = n;
  22. stoimost = s;
  23. mesta = m;
  24. zayavka = z;
  25. dneypredvopl = d;
  26. }
  27. }
  28. static void Main(string[] args)
  29. {
  30. Gost[] gosts = new Gost[3];
  31. gosts[0] = new Gost("Гост", 2000, 8, 6, 10);
  32. gosts[1] = new Gost("Муром", 1500, 7, 4, 3);
  33. gosts[2] = new Gost("Рим", 3000, 15, 6, 23);
  34.  
  35. string path = @"J:\8\gost.txt ";
  36.  
  37. try
  38. {
  39. using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate)))
  40. {
  41. foreach (Gost a in gosts)
  42. {
  43. writer.Write(a.name);
  44. writer.Write(a.stoimost);
  45. writer.Write(a.mesta);
  46. writer.Write(a.zayavka);
  47. writer.Write(a.dneypredvopl);
  48. }
  49. }
  50. using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)))
  51. {
  52. while (reader.PeekChar() > -1)
  53.  
  54. {
  55. string name = reader.ReadString();
  56. int stoimost = reader.ReadInt32();
  57. int mesta = reader.ReadInt32();
  58. int zayavka = reader.ReadInt32();
  59. int dneypredvopl = reader.ReadInt32();
  60. Console.WriteLine("Гостиница: {0}, Стоимость: {1}, Количество мест: {2}, Количество заявок: {3}, Дни по предварительнойоплате: {4}", name, stoimost, mesta, zayavka, dneypredvopl);
  61. }
  62. }
  63. string path1 = @"J:\8\gosts.txt ";
  64. using (BinaryWriter w = new BinaryWriter(File.Open(path1, FileMode.OpenOrCreate)))
  65. {
  66. for (int i = 0; i < 3; i++)
  67. {
  68. if (gosts[i].dneypredvopl == 10)
  69. {
  70. gosts[i].stoimost = gosts[i].stoimost - gosts[i].stoimost * 0.05;
  71. }
  72. }
  73. for (int i = 0; i < 3; i++)
  74. {
  75. if (gosts[i].dneypredvopl > 20)
  76. {
  77. gosts[i].stoimost = gosts[i].stoimost - gosts[i].stoimost * 0.1;
  78. }
  79. w.Write(gosts[i].name + " " + gosts[i].stoimost + " " + gosts[i].mesta + " " + gosts[i].zayavka + " " + gosts[i].dneypredvopl + " ");
  80. }
  81. }
  82. }
  83.  
  84. catch (Exception e)
  85. {
  86. Console.WriteLine(e.Message);
  87. }
  88. Console.ReadLine();
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment