Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace ConsoleApplication2
- {
- class Program
- {
- struct Gost
- {
- public string name;
- public double stoimost;
- public int mesta;
- public int zayavka;
- public int dneypredvopl;
- public Gost(string n, int s, int m, int z, int d)
- {
- name = n;
- stoimost = s;
- mesta = m;
- zayavka = z;
- dneypredvopl = d;
- }
- }
- static void Main(string[] args)
- {
- Gost[] gosts = new Gost[3];
- gosts[0] = new Gost("Гост", 2000, 8, 6, 10);
- gosts[1] = new Gost("Муром", 1500, 7, 4, 3);
- gosts[2] = new Gost("Рим", 3000, 15, 6, 23);
- string path = @"J:\8\gost.txt ";
- try
- {
- using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate)))
- {
- foreach (Gost a in gosts)
- {
- writer.Write(a.name);
- writer.Write(a.stoimost);
- writer.Write(a.mesta);
- writer.Write(a.zayavka);
- writer.Write(a.dneypredvopl);
- }
- }
- using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)))
- {
- while (reader.PeekChar() > -1)
- {
- string name = reader.ReadString();
- int stoimost = reader.ReadInt32();
- int mesta = reader.ReadInt32();
- int zayavka = reader.ReadInt32();
- int dneypredvopl = reader.ReadInt32();
- Console.WriteLine("Гостиница: {0}, Стоимость: {1}, Количество мест: {2}, Количество заявок: {3}, Дни по предварительнойоплате: {4}", name, stoimost, mesta, zayavka, dneypredvopl);
- }
- }
- string path1 = @"J:\8\gosts.txt ";
- using (BinaryWriter w = new BinaryWriter(File.Open(path1, FileMode.OpenOrCreate)))
- {
- for (int i = 0; i < 3; i++)
- {
- if (gosts[i].dneypredvopl == 10)
- {
- gosts[i].stoimost = gosts[i].stoimost - gosts[i].stoimost * 0.05;
- }
- }
- for (int i = 0; i < 3; i++)
- {
- if (gosts[i].dneypredvopl > 20)
- {
- gosts[i].stoimost = gosts[i].stoimost - gosts[i].stoimost * 0.1;
- }
- w.Write(gosts[i].name + " " + gosts[i].stoimost + " " + gosts[i].mesta + " " + gosts[i].zayavka + " " + gosts[i].dneypredvopl + " ");
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment