Answer to Question #261412 in C# for Zeeshan

Question #261412

. Create a class Processor that has the following methods: a) InputStudentData: Gets the input for the Student object that has registration number, name, cgpa, and discipline as data members. b) PrintStudentData: Displays the students data on the console. c) StudentWithMaxGrade: Display the record of the student whose cgpa is maximum in the class. d) In Main() method take the inputs of 5 students and test the methods.


1
Expert's answer
2021-11-05T07:25:10-0400
using System;
using System.Collections.Generic;


namespace App
{
    class Student
    {
        private string registerNumber;


        public string RegisterNumber
        {
            get { return registerNumber; }
            set { registerNumber = value; }
        }
        private string name;


        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private int cgpa;


        public int Cgpa
        {
            get { return cgpa; }
            set { cgpa = value; }
        }
        private string discipline;


        public string Discipline
        {
            get { return discipline; }
            set { discipline = value; }
        }
        public Student()
        {


        }


        public Student(string registerNumber, string name, int cgpa, string discipline)
        {
            this.registerNumber = registerNumber;
            this.name = name;
            this.cgpa = cgpa;
            this.discipline = discipline;
        }




        public override string ToString()
        {
            return "Register number: " + this.registerNumber + "\nName: " + this.name + "\nCGPA: "
                    + this.cgpa.ToString() + "\nDiscipline: " + this.discipline + "\n";
        }
    }


    class Processor
    {
        private List<Student> students = new List<Student>();




        /// <summary>
        ///  InputStudentData: Gets the input for the Student object that 
        ///  has registration number, name, cgpa, and discipline as data members. 
        /// </summary>
        public void InputStudentData()
        {
            Console.Write("Enter register number: ");
            string registerNumber = Console.ReadLine();
            Console.Write("Enter name: ");
            string name = Console.ReadLine();
            Console.Write("Enter cgpa: ");
            int cgpa = int.Parse(Console.ReadLine());
            Console.Write("Enter discipline: ");
            string discipline = Console.ReadLine();
            students.Add(new Student(registerNumber, name, cgpa, discipline));
        }
        /// <summary>
        ///  PrintStudentData: Displays the students data on the console. 
        /// </summary>
        public void PrintStudentData()
        {
            for (int i = 0; i < students.Count; i++) {
                Console.WriteLine(students[i].ToString());
            }
        }
        /// <summary>
        /// StudentWithMaxGrade: Display the record of the student whose cgpa is maximum in the class
        /// </summary>
        public void StudentWithMaxGrade()
        {


            Console.WriteLine("The record of the student whose cgpa is maximum in the class is: ");
            Student maxStudent =students[0];
            for (int i = 0; i < students.Count; i++)
            {
                if (maxStudent.Cgpa<students[i].Cgpa) {
                    maxStudent = students[i];
                }
            }
            Console.WriteLine(maxStudent.ToString());
        }
    }


    class Program
    {




        static void Main(string[] args)
        {
            Processor processor = new Processor();
            for (int i = 0; i < 5; i++) {
                Console.WriteLine("Enter a information for student {0}", (i + 1));
                processor.InputStudentData();
            }
            processor.PrintStudentData();
            processor.StudentWithMaxGrade();


            Console.ReadLine();
        }




    }
}

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