Exemplo n.º 1
0
        public static void MainLoop(Student[] student, int itemcount)
        {
            ShowMenu();

            int yourchoice;
            string confirm = "y";

            do
            {
                Console.Write("Enter your choice(1-9): ");
                yourchoice = int.Parse(Console.ReadLine());

                switch (yourchoice)
                {

                    case 1: Add(student, ref itemcount); break;
                    case 2: Delete(student, ref itemcount); break;
                    case 3: Update(student, itemcount); break;
                    case 4: ViewAll(student, itemcount); break;
                    case 5: Average(student, itemcount); break;
                    case 6: ShowMax(student, itemcount); break;
                    case 7: ShowMin(student, itemcount); break;
                    case 8: ShowRecord(student, itemcount); break;
                    case 9: BubbleSort(student, itemcount); break;

                    default: Console.WriteLine("Invalid Choice."); break;

                }

                Console.Write("Press y or Y to continue:");
                confirm = Console.ReadLine().ToString();

            } while (confirm == "y" || confirm == "Y");



        }
Exemplo n.º 2
0
        public static void Add(Student[] student, ref int itemcount)
        {

            int loop = 0;
            while (loop == 0)
            {
                Console.WriteLine();
                Console.Write("Enter student's ID:");
                student[itemcount].Number = Console.ReadLine().ToString();
                //making sure the record to be added doesn't already exist
                if (Search(student, student[itemcount].Number, itemcount) != -1)
                {

                    Console.WriteLine("This ID already exists.");
                }
                else
                {
                    loop = 1;
                }

            }

            Console.Write("Enter student's Name: ");
            student[itemcount].Name = Console.ReadLine().ToString();

            Console.Write("Enter student's Sex(F or M): ");
            student[itemcount].Sex = Console.ReadLine().ToString();

            Console.Write("Enter student's Quiz1 score: ");
            student[itemcount].Quiz1 = float.Parse(Console.ReadLine());

            Console.Write("Enter student's Quiz2 score: ");
            student[itemcount].Quiz2 = float.Parse(Console.ReadLine());

            Console.Write("Enter student's Assigment score: ");
            student[itemcount].Assigment = float.Parse(Console.ReadLine());

            Console.Write("Enter student's Midterm score: ");
            student[itemcount].Midterm = float.Parse(Console.ReadLine());

            Console.Write("Enter student's Final score: ");
            student[itemcount].Final = float.Parse(Console.ReadLine());

            student[itemcount].Total = student[itemcount].Quiz1 + student[itemcount].Quiz2 + student[itemcount].Assigment + student[itemcount].Midterm + student[itemcount].Final;

            ++itemcount;

        }
Exemplo n.º 3
0
        public static void ShowRecord(Student[] student, int itemcount)
        {
            string id;
            Console.Write("Enter student's ID to show scores: ");
            id = Console.ReadLine();

            int index = Search(student, id.ToString(), itemcount);
            if (index != -1)
            {
                Console.Write("{0,-5}{1,-20}{2,-5}", student[index].Number, student[index].Name, student[index].Sex);
                Console.Write("{0,-5}{1,-5}{2,-5}", student[index].Quiz1, student[index].Quiz2, student[index].Assigment);
                Console.Write("{0,-5}{1,-5}{2,-5}", student[index].Midterm, student[index].Final, student[index].Total);
                Console.WriteLine();
            }
            else Console.WriteLine("That record doesn't exist.");

        }
Exemplo n.º 4
0
        public static void BubbleSort(Student[] dataset, int n)
        {
            int i, j;
            for (i = 0; i < n; i++)
                for (j = n - 1; j > i; j--)
                    if (dataset[j].Total < dataset[j - 1].Total)
                    {
                        Student temp = dataset[j];
                        dataset[j] = dataset[j - 1];
                        dataset[j - 1] = temp;
                    }

        }
Exemplo n.º 5
0
        public static void Average(Student[] student, int itemcount)
        {
            string id;
            float avg = 0;
            Console.Write("Enter student's ID to find their Average Score: ");
            id = Console.ReadLine();
            int index = Search(student, id.ToString(), itemcount);
            if (index != -1 && itemcount > 0)
            {
                avg = student[index].Total / 5;
            }

            Console.WriteLine("This student's Average Score is {0}.", avg);
        }
Exemplo n.º 6
0
        public static void ShowMin(Student[] student, int itemcount)
        {

            float min = student[0].Total;
            int index = 0;
            if (itemcount != 0)
            {
                for (int j = 0; j < itemcount - 1; ++j)
                    if (min > student[j + 1].Total)
                    {
                        min = student[j + 1].Total;
                        index = j + 1;
                    }
            }

            else
            {
                Console.WriteLine("No records found!");
                index = -1;
            }

            if (index != -1)
            {
                Console.WriteLine("The student with ID:{0} has the lowest score: {1}.", student[index].Number, min);
            }

        }
Exemplo n.º 7
0
        public static void Update(Student[] student, int itemcount)
        {
            string id;
            int ColumnIndex;
            Console.Write("Enter student's ID to be updated: ");
            id = Console.ReadLine();
            Console.Write("Which field you want to update(1-7)?:");
            ColumnIndex = int.Parse(Console.ReadLine());

            int index = Search(student, id.ToString(), itemcount);

            if ((index != -1) && (itemcount != 0))
            {
                if (ColumnIndex == 1)
                {
                    Console.Write("Enter student's Name: ");

                    student[index].Name = Console.ReadLine().ToString();
                }

                else if (ColumnIndex == 2)
                {
                    Console.Write("Enter student's Sex(F or M):");
                    student[index].Sex = Console.ReadLine().ToString();
                }
                else if (ColumnIndex == 3)
                {
                    Console.Write("Enter student's quizz1 score:");
                    student[index].Quiz1 = float.Parse(Console.ReadLine());
                }
                else if (ColumnIndex == 4)
                {
                    Console.Write("Enter student's quizz2 score:");
                    student[index].Quiz2 = float.Parse(Console.ReadLine());
                }
                else if (ColumnIndex == 5)
                {
                    Console.Write("Enter student's assigment score:");
                    student[index].Assigment = float.Parse(Console.ReadLine());
                }
                else if (ColumnIndex == 6)
                {
                    Console.Write("Enter student's mid term score:");
                    student[index].Midterm = float.Parse(Console.ReadLine());
                }
                else if (ColumnIndex == 7)
                {
                    Console.Write("Enter student's final score:");
                    student[index].Final = float.Parse(Console.ReadLine());
                }
                else Console.WriteLine("Invalid column index");
                student[index].Total = student[index].Quiz1 + student[index].Quiz2 + student[index].Assigment + student[index].Midterm + student[index].Final;


            }
            else Console.WriteLine("The record doesn't exist. Check the ID and try again.");

        }
Exemplo n.º 8
0
 public static void Remove(Student[] student, int index)
 {
     student[index].Number = null;
     student[index].Name = null;
     student[index].Sex = null;
     student[index].Quiz1 = 0;
     student[index].Quiz2 = 0;
     student[index].Assigment = 0;
     student[index].Midterm = 0;
     student[index].Final = 0;
     student[index].Total = 0;
 }
Exemplo n.º 9
0
        public static void Delete(Student[] student, ref int itemcount)
        {
            string id;
            int index;
            if (itemcount > 0)
            {
                Console.Write("Enter student's ID to be deleted:");
                id = Console.ReadLine();
                index = Search(student, id.ToString(), itemcount);

                if ((index != -1) && (itemcount != 0))
                {
                    if (index == (itemcount - 1))
                    {
                        Remove(student, index);
                        --itemcount;
                        Console.WriteLine("The record was deleted.");
                    }
                    else
                    {
                        for (int i = index; i < itemcount - 1; i++)
                        {
                            student[i] = student[i + 1];
                            Remove(student, itemcount);
                            --itemcount;
                        }
                    }

                }
                else
                {
                    Console.WriteLine("The record doesn't exist. Check the ID and try again.");
                }

            }
            else
            {
                Console.WriteLine("There are no records to delete.");
            }
        }
Exemplo n.º 10
0
        public static int Search(Student[] student, string id, int itemcount)
        {
            int found = -1;
            for (int i = 0; i < itemcount && found == -1; i++)
            {
                if (student[i].Number == id)
                {
                    found = i;
                }
            }
            return found;

        }
Exemplo n.º 11
0
        public static void ViewAll(Student[] student, int itemcount)
        {

            int i = 0;

            Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8}(column index)", "0", "1", "2", "3", "4", "5", "6", "7", "8");
            Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "ID", "NAME", "SEX", "Q1", "Q2", "As", "Mi", "Fi", "TOTAL");

            Console.WriteLine("*********************************");

            while (i < itemcount)
            {
                if (student[i].Number != null)
                {
                    Console.Write("{0,-5}{1,-20}{2,-5}", student[i].Number, student[i].Name, student[i].Sex);
                    Console.Write("{0,-5}{1,-5}{2,-5}", student[i].Quiz1, student[i].Quiz2, student[i].Assigment);
                    Console.Write("{0,-5}{1,-5}{2,-5}", student[i].Midterm, student[i].Final, student[i].Total);
                    Console.Write("\n");
                }
                i += 1;
            }
        }