Create a class called Student.cs. This class contains the following:
a) class data fields name, mark and grade
b) public Student (string name, double mark, string grade)
// constructor
c) public string getName() / / to return name of student
d) public double getMark() // to return mark of student
e) public string getGrade() // to return student grade
f) public void setMark(double mark) // to set student mark
g) public string setGrade(double mark) // mark is first checked using a nested if-else and switch to determine grade.
The possible grades are:
0 <= mark < 50 -
50 <= mark < 60 -
60 <= mark < 70 -
70 <= mark < 80 -
80 <= mark < 100 -
Sample Output:
Please enter number of student marks you would like to add: 2
Please enter name of student 1 : Sam
Please enter mark for student 1 : 33
Please enter name of student 2 : John
Please enter mark for student 2 : 88
Choose an option:
1. Display a Student Mark
2. Change Student Mark
3. Print out information for all students
4. Exit program
Enter Option: 1
Display a student mark
Please enter name of student you would display mark for: jjj
I am sorry. Student: 'jjj' does not exist
Choose an option:
1. Display a Student Mark
2. Change Student Mark
3. Print out information for all students
4. Exit program
Enter Option: 1
Display a student mark
Please enter name of student you would display mark for: Sam
Marks for Sam is: 33.0
Choose an option:
1. Display a Student Mark
2. Change Student Mark
3. Print out information for all students
4. Exit program
Enter Option: 2
Change Student Mark
Please enter name of student you would like to change mark for: John
Current marks for John is: 88.0
Enter new mark for John: 3333
Invalid Entry! Marks must be between 0 - 100!
Enter new mark for John: 70
New grade for John is: D
Choose an option:
1. Display a Student Mark
2. Change Student Mark
3. Print out information for all students
4. Exit program
Enter Option: 3
Print out information for all students
Name Mark Grade
Sam 33.0 F
John 70.0 D
Choose an option:
1. Display a Student Mark
2. Change Student Mark
3. Print out information for all students
4. Exit program
Enter Option: 4
1
Expert's answer
2011-07-11T05:53:06-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 studentlist = new List(); /// /// Calculate Grade of each student /// /// 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) {
Student.cs 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
The expert did excellent work as usual and was extremely helpful for me.
"Assignmentexpert.com" has experienced experts and professional in the market. Thanks.
Comments
Leave a comment