コード例 #1
0
        static void Task1()
        {
            List <int> lst = FileOperations.Read();

            String choice = "";

            PrintLst(lst);


            while (choice != "0")
            {
                Console.Write("0 - Iziet, 1- Pievienot sarakstam, 2 - Dzēst, 3 - Skaitļu summa, 4 - Vidējā vērtība: ");
                choice = Console.ReadLine();
                //choice = readFromKey();
                Console.WriteLine(" ");

                switch (choice)
                {
                case "1":
                    AddElement(lst);
                    PrintLst(lst);
                    break;

                case "2":
                    RemoveElement(lst);
                    PrintLst(lst);
                    break;

                case "0":
                    break;

                case "3":
                    Console.WriteLine("Saraksta skaitļu summa ir " + sumList(lst));
                    Console.WriteLine(" ");
                    break;

                case "4":
                    double avg = avgList(lst);
                    if (avg != 0)
                    {
                        Console.WriteLine("Saraksta skaitļu vidējais ir " + avg);
                        Console.WriteLine(" ");
                    }
                    break;

                default:
                    Console.WriteLine("Nepareiza ievade");
                    break;
                }
            }
        }
コード例 #2
0
        static void Task1()
        {
            List <int> lst = FileOperations.Read();

            String choice = " ";

            while (choice != "0")
            {
                Console.WriteLine("1- Pievienot");
                Console.WriteLine("2- Dzēst");
                Console.WriteLine("0- Iziet");
                Console.WriteLine("3- Saskaitīt visus skaitļus");
                Console.WriteLine("4 - izrēķināt vidējo aritmētisko");

                choice = Console.ReadLine();

                switch (choice)
                {
                case "1":
                    AddElement(lst);
                    break;

                case "2":
                    DeleteElement(lst);
                    break;

                case "0":
                    FileOperations.Write(lst);
                    break;

                case "3":
                    Console.WriteLine();
                    Console.WriteLine(sumElements(lst));
                    Console.WriteLine();
                    break;

                case "4":
                    Console.WriteLine();
                    Console.WriteLine(averageSum(lst));
                    Console.WriteLine();
                    break;

                default:
                    Console.WriteLine("Nepareiza ievade");
                    break;
                }
            }
        }
コード例 #3
0
        static void Task01()
        {
            List <int> values = FileOperations.Read();
            String     choice = "";
            double     sum    = 0;
            double     avg    = 0;

            while (choice != "Exit")
            {
                Console.Write("Choose an action - Add, Show, Exit, Remove, Count, Average: ");
                choice = Console.ReadLine();

                if (choice == "Add")
                {
                    Console.Write("How many values would you like to add? : ");
                    int amount = Convert.ToInt32(Console.ReadLine());

                    for (int i = 0; i < amount; i++)
                    {
                        try
                        {
                            Console.Write("Insert value [" + i + "]: ");
                            values.Add(Convert.ToInt32(Console.ReadLine()));
                            FileOperations.Write(values);
                        }
                        catch
                        {
                            Console.WriteLine("Wrong input");
                            i--;
                        }
                    }
                }
                else if (choice == "Show")
                {
                    if (values.Count == 0)
                    {
                        Console.WriteLine("List contains no values!");
                    }

                    for (int i = 0; i < values.Count; i++)
                    {
                        Console.WriteLine("Value [" + i + "] is " + values[i]);
                    }
                }
                else if (choice == "Exit")
                {
                    break;
                }
                else if (choice == "Remove")
                {
                    Console.Write("Which index would you like to remove? : ");
                    int remove = Convert.ToInt32(Console.ReadLine());
                    try
                    {
                        values.RemoveAt(remove);
                        Console.WriteLine();
                    }
                    catch
                    {
                        Console.WriteLine("Wrong input");
                    }
                    FileOperations.Write(values);
                }
                else if (choice == "Count")
                {
                    for (int i = 0; i < values.Count; i++)
                    {
                        sum += values[i];
                    }
                    Console.Write("Sum of all values is: " + sum);
                    Console.WriteLine();
                    sum = 0;
                }
                else if (choice == "Average")
                {
                    for (int i = 0; i < values.Count; i++)
                    {
                        sum += values[i];
                        if (i < values.Count)
                        {
                            avg = sum / values.Count;
                        }
                    }
                    Console.WriteLine("Average of all index values is: " + avg);
                    avg = 0;
                    sum = 0;
                }
            }
        }