Answer to Question #295487 in C# for Azarack

Question #295487

Enter how many students [Max=25]: 5


Enter name of Student: John Wayne


Enter name of Student: James Bond


Enter name of Student: Bruce Almighty


Enter name of Student: Peter Parker


Enter name of Student: Tony Stark



Enter Grades for John Wayne


Prelim : 95


Midterm : 96


Final : 97


Enter Grades for James Bond


Prelim : 91


Midterm : 92


Final : 93


Enter Grades for Bruce Almighty


Prelim : 98


Midterm : 99


Final : 97


Enter Grades for Peter Parker


Prelim : 92


Midterm : 94


Final : 93


Enter Grades for Tony Stark


Prelim : 99


Midterm : 99


Final : 98



Course: Programming 101


List of Students Prelim Midterm Final Grade Rating


John Wayne 95 96 97 96 1.25


James Bond 91 92 93 92 1.75


Bruce Almighty 98 99 97 98 1.25


Peter Parker 92 94 93 93 1.5


Tony Stark 99 99 98 99 1.0


Computations


Grade = Prelim (30%) + Midterm (30%) + Final (40%)


Grade Rating


99-100 1.0


96-98 1.25


93-95 1.5


90-92 1.75


87-89 2.0


84-86 2.25


81-83 2.5


78-80 2.75


75-77 3.0


74 and below 5.0


1
Expert's answer
2022-02-09T02:03:17-0500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Student> students = new List<Student>(25);
            Console.Write("Enter how many students[Max = 25]: ");
            int count = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("Enter name of Student: ");
                string name = Console.ReadLine();
                Student s = new Student();
                s.Name = name;
                students.Add(s);
            }

            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("Enter Grades {0}", students[i].Name);
                Console.Write("Prelim : ");
                int prelim = Convert.ToInt32(Console.ReadLine());
                Console.Write("Midterm : ");
                int midterm = Convert.ToInt32(Console.ReadLine());
                Console.Write("Final : ");
                int final = Convert.ToInt32(Console.ReadLine());

                students[i].Prelim = prelim;
                students[i].Midterm = midterm;
                students[i].Final = final;

            }

            Console.WriteLine("Course: Programming 101");



            Console.WriteLine("List of Students     Prelim  Midterm Final   Grade Rating");
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine( students[i].ToString());
            }


                Console.ReadKey();
        }
    }

    class Student
    {
        public string Name;
        public int Prelim;
        public int Midterm;
        public int Final;

        public int Grade
        {
            get
            {
                return Convert.ToInt32( Prelim * 0.3 + Midterm * 0.3 + Final * 0.4);
            }
        }

        public decimal Rating
        {
            get
            {
                decimal r = 0;

                switch (Grade)
                {
                    case int n when(n >= 99):
                        r = 1m; break;
                    case int n when (n >= 96 && n <= 98):
                        r = 1.25m; break;
                    case int n when (n >= 93 && n <= 95):
                        r = 1.5m; break;
                    case int n when (n >= 90 && n <= 92):
                        r = 1.75m; break;
                    case int n when (n >= 87 && n <= 89):
                        r = 2m; break;
                    case int n when (n >= 84 && n <= 86):
                        r = 2.25m; break;
                    case int n when (n >= 84 && n <= 86):
                        r = 2.25m; break;
                    case int n when (n >= 81 && n <= 83):
                        r = 2.5m; break;
                    case int n when (n >= 78 && n <= 80):
                        r = 2.75m; break;
                    case int n when (n >= 75 && n <= 77):
                        r = 3m; break;
                    case int n when (n <= 74):
                        r = 5m; break;
                }

                return r;
            }
        }

        public override string ToString()
        {
            return string.Format("{0, -20}{1,6} {2,6} {3,6} {4,6} {5, 6}", Name, Prelim, Midterm, Final, Grade, Rating);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS