Write a C# program which allows the user to enter student information and outputs the appropriate grade for the student. This assignment involves the use of classes, arrays or collections, loops and methods.
1
Expert's answer
2011-07-13T16:53:29-0400
Program.cs
using System; using System.Collections.Generic; using System.Text;
namespace Result { class Result { & private static int numberofStudent = 0; & private static int key=0; & private static List<Student> studentlist = new List<Student>(); & /// <summary> & /// Calculate Grade of each student & /// </summary> & /// <param name="std"></param> & private static void CalculateGrade(Student std){
if (std.getMark() >= 0 && std.getMark() < 50) { std.setGrade("Fx"); } if (std.getMark() >= 50 && std.getMark() < 60) { std.setGrade("E"); } if (std.getMark() >= 60 && std.getMark() < 70) { std.setGrade("D"); } if (std.getMark() >= 70 && std.getMark() < 80) { std.setGrade("C"); } if (std.getMark() >= 80 && std.getMark() < 90) { std.setGrade("B"); } if (std.getMark() >= 90 && std.getMark() < 100) { std.setGrade("A"); } & } & static void Main(string[] args) & { try { Student st; Console.WriteLine("Please enter number of student marks you would like to add"); numberofStudent = int.Parse(Console.ReadLine());
for (int i = 0; i < numberofStudent; i++) { & st = new Student(); & Console.WriteLine("Please enter name of student " + (i + 1).ToString()); & st.setName(Console.ReadLine()); & Console.WriteLine("Please enter mark for student " + (i + 1).ToString()); & st.setMark(Double.Parse(Console.ReadLine())); & CalculateGrade(st); & studentlist.Add(st); } string name=""; double mark = 0; do { & Console.WriteLine("1. Display a Student Mark"); & Console.WriteLine("2. Change Student Mark"); & Console.WriteLine("3. Print out information for all students"); & Console.WriteLine("4. Exit program"); & key = int.Parse(Console.ReadLine()); & switch (key) & { case 1: Console.WriteLine("Display a student mark"); & Console.Write("Please enter name of student you would display mark for& "); & name = Console.ReadLine(); foreach(Student std in studentlist){ & if (std.getName() == name) & { Console.WriteLine("Marks for " + std.getName().ToString() + " is " + std.getMark().ToString()); break; & } & else { Console.WriteLine("I am sorry. Student: '" + std.getName().ToString() + "' does not exist"); break; & } } break; case 2: Console.WriteLine("Change Student Mark"); & Console.Write("Please enter name of student you would like to change mark for:"); & name = Console.ReadLine(); & foreach (Student std in studentlist) & { if (std.getName() == name) { Console.WriteLine("Current marks for& " + std.getName().ToString() + " is: " + std.getMark().ToString()); Console.Write("Enter new mark for " + std.getName().ToString()+": "); mark = double.Parse(Console.ReadLine()); if (mark > 0 && mark < 100) { & std.setMark(mark); & CalculateGrade(std); & Console.WriteLine("New grade for " + std.getName().ToString() + " is: " + std.getGrade()); }
else { & Console.WriteLine("Invalid Entry! Marks must be between 0 - 100!"); } } else { Console.WriteLine("I am sorry. Student: '" + std.getName().ToString() + "' does not exist"); } & } break; case 3: Console.WriteLine(" Print out information for all students"); Console.WriteLine("Name Mark Grade"); foreach (Student std in studentlist) {
using System; using System.Collections.Generic; using System.Text;
namespace Result { public class Student { & private string name; & private double mark; & private string grade; & public Student() & { & & } & public Student(string name, double mark, string grade) { this.name = name; this.mark = mark; this.grade = grade; & } & public string getName(){ return name; & } // to return name of student & public double getMark(){ return mark; & } // to return mark of student & public string getGrade(){ return grade; & }// to return student grade
& public void setName(string name) & { this.name = name; & }& & public void setMark(double mark){ this.mark=mark; & } // to set student mark & public void setGrade(string grade) & { this.grade = grade; & }& // mark is first checked using a
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment