1
0
oop-1-labs/Lab4/Lab4.LetterFrequency/InOut.cs

41 lines
1.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Lab4.LetterFrequency
{
static class InOut
{
/** Prints repetition of letters using two columns into a given file.
@param fout name of the file for the output
@param letters object having letters and their repetitions */
public static void PrintRepetitions(string fout, LettersFrequency letters)
{
using (var writer = File.CreateText(fout))
{
foreach (var pair in letters.GetOrderedFrequencies())
{
writer.WriteLine("{0, 3:c} {1, 4:d}", pair.Item1, pair.Item2);
}
}
}
/** Inputs from the given data file and counts repetition of letters.
@param fin name of data file
@param letters object having letters and their repetitions*/
public static void Repetitions(string fin, LettersFrequency letters)
{
using (StreamReader reader = new StreamReader(fin))
{
string line;
while ((line = reader.ReadLine()) != null)
{
letters.line = line;
letters.CountLetters();
}
}
}
}
}