Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace Laba8
- {
- class Program
- {
- private const string INPUT_PATH = @"E:\ОАИП\Кирилл\laba8 Aleks\Laba8\input.dat";
- private const string OUTPUT_PATH = @"E:\ОАИП\Кирилл\laba8 Aleks\Laba8\output.dat";
- private static List<Student> students = new List<Student>();
- static void Main(string[] args)
- {
- Console.WriteLine("Введите кол-во учеников:");
- int count = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < count; i++)
- {
- Student st = new Student();
- Console.WriteLine("Введите " + (i + 1).ToString()+"-го ученика!");
- Console.Write("ФИО:");
- st.fullname = Console.ReadLine();
- Console.Write("Группа:");
- st.groupId = Convert.ToInt32(Console.ReadLine());
- Console.Write("Оценки:");
- string[] marks = Console.ReadLine().Split(new char[1] { ' ' });
- int[] intmarks = new int[3];
- for (int j = 0; j < 3; j++)
- {
- intmarks[j] = Convert.ToInt32(marks[j]);
- }
- st.marks = intmarks;
- Console.Write("Размер стипендии:");
- st.money = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine();
- students.Add(st);
- }
- using (BinaryWriter bw = new BinaryWriter(File.Open(INPUT_PATH, FileMode.Create)))
- {
- foreach (Student student in students)
- {
- bw.Write(student.fullname);
- bw.Write(student.groupId);
- for (int i = 0; i < 3; i++)
- {
- bw.Write(student.marks[i]);
- }
- bw.Write(student.money);
- }
- }
- using (BinaryWriter bw = new BinaryWriter(File.Open(OUTPUT_PATH, FileMode.Create)))
- {
- foreach (Student student in students)
- {
- bool hasBadMark = false;
- for (int i = 0; i < 3; i++)
- {
- if (student.marks[i] < 3) {
- hasBadMark = true;
- break;
- }
- }
- bw.Write(student.fullname);
- bw.Write(student.groupId);
- for (int i = 0; i < 3; i++)
- {
- bw.Write(student.marks[i]);
- }
- if (!hasBadMark)
- student.setMoney(student.money * 1.3);
- bw.Write(student.money);
- }
- }
- using (BinaryReader reader = new BinaryReader(File.Open(OUTPUT_PATH, FileMode.Open)))
- {
- while (reader.PeekChar() > 0)
- {
- Console.WriteLine();
- Console.WriteLine("ФИО:" + reader.ReadString());
- Console.WriteLine("Группа:" + reader.ReadInt32());
- for (int i = 0; i < 3; i++)
- {
- int curMark = reader.ReadInt32();
- Console.Write(curMark.ToString() + " ");
- }
- Console.WriteLine();
- Console.WriteLine("Стипендия:" + reader.ReadDouble());
- }
- }
- Console.ReadLine();
- }
- }
- struct Student
- {
- public string fullname;
- public int groupId;
- public int[] marks;
- public double money;
- public void setMoney(double money)
- {
- this.money = money;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement