Beispiel #1
0
 public static void OutputData(StreamWriter streamWriter, TaskNum task)
 {
     foreach (INumber i in task.numbers)
     {
         i.OutputData(streamWriter);
     }
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            string inPath       = @"inputData.txt";
            var    file         = new FileStream(inPath, FileMode.Open, FileAccess.Read);
            var    streamReader = new StreamReader(file);

            string       outPath      = @"outputData.txt";
            StreamWriter streamWriter = new StreamWriter(outPath, true, System.Text.Encoding.Default);


            TaskNum task = new TaskNum();

            task = TaskNum.InputData(streamReader);
            //TaskNum.OutputData(streamWriter, task);
            INumber sum = task.Sum();

            streamWriter.WriteLine($"Sum : {sum}");

            TaskNum task1 = task.Clone() as TaskNum;
            //TaskNum.OutputData(streamWriter, task);
            INumber avg     = task1.Average();
            INumber dobutok = task1.Dobutok();

            streamWriter.WriteLine($"Average : {avg}    Dobutok : {dobutok}");

            streamReader.Close();
            streamWriter.Close();

            Console.Read();
        }
Beispiel #3
0
        public static TaskNum InputData(StreamReader streamReader)
        {
            string  line;
            TaskNum task = new TaskNum();

            while ((line = streamReader.ReadLine()) != null)
            {
                if (line.IndexOf('/') != -1)
                {
                    INumber newNum = new RationalNumber();
                    newNum.InputData(line);
                    task.numbers.Add(newNum);
                }
                else
                {
                    INumber newNum = new IntegerNumber();
                    newNum.InputData(line);
                    IntegerNumber  intNum = newNum as IntegerNumber;
                    RationalNumber ratNum = new RationalNumber {
                        numerator = intNum.number, denominator = 1
                    };
                    task.numbers.Add(ratNum);
                }
            }
            return(task);
        }