예제 #1
0
 private static void PromptMatrix(string text, Macierz.Macierz m)
 {
     Console.WriteLine("\n " + text + ": ");
     Console.WriteLine("Dimensions: " + m.GetLength(0) + " x " + m.GetLength(1));
     Console.WriteLine(m.ToString());
     Console.WriteLine("Sum of all cells: " + m.Sum());
 }
예제 #2
0
 private static void PromptMatrix(char symbol, Macierz.Macierz m)
 {
     if (m.IsZero)
     {
         Console.WriteLine("\n Matrix " + symbol + " is empty.");
     }
     else
     {
         Console.WriteLine("\n Matrix " + symbol + ": ");
         Console.WriteLine("Dimensions: " + m.GetLength(0) + " x " + m.GetLength(1));
         Console.WriteLine(m.ToString());
         Console.WriteLine("Sum of all cells: " + m.Sum());
     }
 }
예제 #3
0
        private static void WriteFile(Macierz.Macierz m)
        {
            if (!m.IsZero)
            {
                try
                {
                    for (;;)
                    {
                        bool fc = false;
                        Console.Write("Enter filename (without the .txt extension)[Q to break]: ");
                        var crl = Console.ReadLine();
                        crl.Trim();
                        if (crl == "Q" || crl == "q")
                        {
                            break;
                        }
                        char[] arr = crl.ToCharArray();
                        foreach (var a in arr)
                        {
                            if (a == '<' || a == '>' || a == '?' || a == '\\' || a == '/' || a == '/' || a == '*' || a == ':' || a == '?' || a == '|' || a == '"')
                            {
                                fc = true;
                                break;
                            }
                        }
                        if (fc)
                        {
                            Console.Write("String contains forbidden characters.\nTry entering a diffrent filename.\n");
                            continue;
                        }
                        if (File.Exists(crl + ".txt"))
                        {
                            Console.Write("File already exits, try diffrent name \n");
                            Console.Write("Type 'overwrite' to overwrite of any key to change name \n");
                            var crl1 = Console.ReadLine();
                            if (crl1?.Trim() != "overwrite")
                            {
                                continue;
                            }
                        }
                        StreamWriter sw = new StreamWriter(crl + ".txt");
                        sw.WriteLine(m.GetLength(0) + " " + m.GetLength(1));
                        var      matat = m.ToString();
                        string[] lines = matat.Split('\n');
                        foreach (var l in lines)
                        {
                            sw.WriteLine(l);
                        }
                        sw.Close();
                        Console.Write("\n =============File saved.============\n");
                        break;
                    }
                }


                catch (Exception e)
                {
                    Console.Write("Exception occurred while writing file");
                    Console.WriteLine(e);
                }
            }
            else
            {
                Console.WriteLine("Matrix is empty");
                Console.WriteLine("No files were created");
            }
        }