0

i need help with my code

Give the class methods to provide name and SID to a newly created Object
(a constructor) and a method to determine the Grade of a piece of work.
and to Write a Main method in another class which creates an instance of this class and tests the methods.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework_task_F
{
    class StudentDetails //class for Declarations
    {

        public string studentname;
        public string studentsid;
        public string studentgrade;

    }

    class Students
    {

        public List<StudentDetails> studList = new List<StudentDetails>();

        //This list contains the student list

        public int MaxStudents;

          //This Function Adds the Record
        public int AddRecord(string name, string sid, string grades)
        {
            StudentDetails stud = new StudentDetails();

            stud.studentname = name;
            stud.studentsid = sid;
            stud.studentgrade = grades;

            studList.Add(stud);
            MaxStudents = studList.Count;

            return 1;
        }     
    }
    class Program
    {

        static public Students theStudents = new Students();
        public static double Grade;     

        //This method is to view Records as Report

        static public void ViewRecords()
        {

            Console.WriteLine("__________________________________________________________________________");

            Console.WriteLine("SNo Student Name    SID      Grade                                        ");

            Console.WriteLine("__________________________________________________________________________");

            for (int i = 0; i < theStudents.MaxStudents; i++)
            {

                Console.Write("{0, -5}", i + 1);

                Console.Write("{0, -15}", theStudents.studList[i].studentname);

                Console.Write("{0, -10}", theStudents.studList[i].studentsid);

                Console.Write("{0, -20}", theStudents.studList[i].studentgrade);


                if (Grade >= 70 && Grade <= 100)
                {
                    Console.Write("you Pass First Class \n");
                }
                if (Grade >= 60 && Grade <= 69)
                {
                    Console.Write(" you is Pass Upper Second Class \n");
                }
                if (Grade >= 50 && Grade <= 59)
                {
                    Console.Write(" you Pass Lower Second Class \n");
                }
                if (Grade >= 40 && Grade <= 49)
                {
                    Console.Write(" you Pass 3rd Class \n");
                }
                if (Grade >= 0 && Grade <= 39)
                {
                    Console.Write(" sorry you failed \n");
                }
                if (Grade >100)
                {
                    Console.Write("Error \n");
                }

            }

            Console.WriteLine("__________________________________________________________________________");

           }

        static public void InputRecords()
        {

            Console.Write("Student Name: \n");
            string name; 
            name = Console.ReadLine();
            Console.Write("Student SID: \n");
            string sid;
            sid = Console.ReadLine();
            Console.Write("Student Grade: \n");
            string grade;
            grade = Console.ReadLine();

            theStudents.AddRecord(name, sid, grade);

        }

        static void Main(string[] args)
        {

            Console.WriteLine("Student MarkList Application");

            Console.Write("Enter the Total number  of students: ");

            int numStudents = -1;

            string s = Console.ReadLine();

            numStudents = Convert.ToInt32(s);

            for (int i = 1; i <= numStudents; i++)
            {
                Console.WriteLine("\nEnter " + i.ToString() + " Student Information\n");

                InputRecords();
            }
            ViewRecords();

            Console.ReadKey();
        }
    }
}
2
Contributors
7
Replies
37
Views
3 Years
Discussion Span
Last Post by castajiz_2
0

i don t know if it s too early in the morning but i really don t understand what you want. Can you please be more specific

0

the cod is not working proble because when it gets the the grade pit of the code with the if parts of the code it only shows one of them

0

i copied and pasted your code and it s working quite OK. By saying that your code doesn t work are you reffering to the "Sorry you failed" output on the right side of the console?

0

yes i am because it should change depending on the grade that the user and put in

0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Homework_task_F
{
    class StudentDetails //class for Declarations
    {
        public string studentname;
        public string studentsid;
        public string studentgrade;
    }
    class Students
    {
        public List<StudentDetails> studList = new List<StudentDetails>();
        //This list contains the student list
        public int MaxStudents;
          //This Function Adds the Record
        public int AddRecord(string name, string sid, string grades)
        {
            StudentDetails stud = new StudentDetails();
            stud.studentname = name;
            stud.studentsid = sid;
            stud.studentgrade = grades;
            studList.Add(stud);
            MaxStudents = studList.Count;
            return 1;
        }     
    }
    class Program
    {
        static public Students theStudents = new Students();

        //This method is to view Records as Report
        static public void ViewRecords()
        {
            Console.WriteLine("__________________________________________________________________________");
            Console.WriteLine("SNo Student Name    SID      Grade                                        ");
            Console.WriteLine("__________________________________________________________________________");
            for (int i = 0; i < theStudents.MaxStudents; i++)
            {
                Console.Write("{0, -5}", i + 1);
                Console.Write("{0, -15}", theStudents.studList[i].studentname);
                Console.Write("{0, -10}", theStudents.studList[i].studentsid);
                Console.Write("{0, -20}", theStudents.studList[i].studentgrade);
                double Grade = Convert.ToDouble(theStudents.studList[i].studentgrade);
                if (Grade >= 70 && Grade <= 100)
                {
                    Console.Write("you Pass First Class \n");
                }
                if (Grade >= 60 && Grade <= 69)
                {
                    Console.Write(" you is Pass Upper Second Class \n");
                }
                if (Grade >= 50 && Grade <= 59)
                {
                    Console.Write(" you Pass Lower Second Class \n");
                }
                if (Grade >= 40 && Grade <= 49)
                {
                    Console.Write(" you Pass 3rd Class \n");
                }
                if (Grade >= 0 && Grade <= 39)
                {
                    Console.Write(" sorry you failed \n");
                }
                if (Grade >100)
                {
                    Console.Write("Error \n");
                }
            }
            Console.WriteLine("__________________________________________________________________________");
           }
        static public void InputRecords()
        {
            Console.Write("Student Name: \n");
            string name; 
            name = Console.ReadLine();
            Console.Write("Student SID: \n");
            string sid;
            sid = Console.ReadLine();
            Console.Write("Student Grade: \n");
            string grade;
            grade = Console.ReadLine();
            theStudents.AddRecord(name, sid, grade);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Student MarkList Application");
            Console.Write("Enter the Total number  of students: ");
            int numStudents = -1;
            string s = Console.ReadLine();
            numStudents = Convert.ToInt32(s);
            for (int i = 1; i <= numStudents; i++)
            {
                Console.WriteLine("\nEnter " + i.ToString() + " Student Information\n");
                InputRecords();
            }
            ViewRecords();
            Console.ReadKey();
        }
    }
}

I don t know if you can do it like this but this should work, just copy paste

Edited by castajiz_2: wd

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.