Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. namespace Laba8
  6. {
  7.     class Program
  8.     {
  9.         private const string INPUT_PATH = @"E:\ОАИП\Кирилл\laba8 Aleks\Laba8\input.dat";
  10.         private const string OUTPUT_PATH = @"E:\ОАИП\Кирилл\laba8 Aleks\Laba8\output.dat";
  11.         private static List<Student> students = new List<Student>();
  12.         static void Main(string[] args)
  13.         {
  14.             Console.WriteLine("Введите кол-во учеников:");
  15.             int count = Convert.ToInt32(Console.ReadLine());
  16.             for (int i = 0; i < count; i++)
  17.             {
  18.                 Student st = new Student();
  19.                 Console.WriteLine("Введите " + (i + 1).ToString()+"-го ученика!");
  20.                 Console.Write("ФИО:");
  21.                 st.fullname = Console.ReadLine();
  22.                 Console.Write("Группа:");
  23.                 st.groupId = Convert.ToInt32(Console.ReadLine());
  24.                 Console.Write("Оценки:");
  25.                 string[] marks = Console.ReadLine().Split(new char[1] { ' ' });
  26.                 int[] intmarks = new int[3];
  27.                 for (int j = 0; j < 3; j++)
  28.                 {
  29.                     intmarks[j] = Convert.ToInt32(marks[j]);
  30.                 }
  31.                 st.marks = intmarks;
  32.                 Console.Write("Размер стипендии:");
  33.                 st.money = Convert.ToDouble(Console.ReadLine());
  34.                 Console.WriteLine();
  35.                 students.Add(st);
  36.             }
  37.               using (BinaryWriter bw = new BinaryWriter(File.Open(INPUT_PATH, FileMode.Create)))
  38.             {
  39.                 foreach (Student student in students)
  40.                 {
  41.                     bw.Write(student.fullname);
  42.                     bw.Write(student.groupId);
  43.                     for (int i = 0; i < 3; i++)
  44.                     {
  45.                         bw.Write(student.marks[i]);
  46.                     }
  47.                     bw.Write(student.money);
  48.                 }
  49.             }
  50.             using (BinaryWriter bw = new BinaryWriter(File.Open(OUTPUT_PATH, FileMode.Create)))
  51.             {
  52.                 foreach (Student student in students)
  53.                 {
  54.                     bool hasBadMark = false;
  55.                     for (int i = 0; i < 3; i++)
  56.                     {
  57.                         if (student.marks[i] < 3) {
  58.                             hasBadMark = true;
  59.                             break;
  60.                         }
  61.                     }
  62.                     bw.Write(student.fullname);
  63.                     bw.Write(student.groupId);
  64.                     for (int i = 0; i < 3; i++)
  65.                     {
  66.                         bw.Write(student.marks[i]);
  67.                     }
  68.                     if (!hasBadMark)
  69.                         student.setMoney(student.money * 1.3);
  70.                     bw.Write(student.money);
  71.                 }
  72.             }
  73.             using (BinaryReader reader = new BinaryReader(File.Open(OUTPUT_PATH, FileMode.Open)))
  74.             {
  75.                 while (reader.PeekChar() > 0)
  76.                 {
  77.                     Console.WriteLine();
  78.                     Console.WriteLine("ФИО:" + reader.ReadString());
  79.                     Console.WriteLine("Группа:" + reader.ReadInt32());
  80.                     for (int i = 0; i < 3; i++)
  81.                     {
  82.                         int curMark = reader.ReadInt32();
  83.                         Console.Write(curMark.ToString() + " ");
  84.                     }
  85.                     Console.WriteLine();
  86.                     Console.WriteLine("Стипендия:" + reader.ReadDouble());
  87.                 }
  88.             }
  89.             Console.ReadLine();
  90.         }
  91.     }
  92.  
  93.     struct  Student
  94.     {
  95.         public string fullname;
  96.         public int groupId;
  97.         public int[] marks;
  98.         public double money;
  99.  
  100.         public void setMoney(double money)
  101.         {
  102.             this.money = money;
  103.         }
  104.  
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement