In: Computer Science
In the C# programming language...
Write a program to perform student record manage for class IST311. Create student record class (Student.cs) and it should get the student information from the user and set up student record class. The program will perform recording student’s grade information and compute final grade, and then print out the student’s class information. Student class definitions: It should contain attributes as following: first name, last name, 5 labs grade, 3 grade, final grade. Its member functions are default constructor, 2 regular constructors, display student’s information and override ToString(), which only display class type, last name, first name, and final grade. (Note: labs grade and grade are store in an array with 8 elements) Student class implementation: Your implementation: All base attributes (fields) to store student’s information. Default constructor: set student class variables to default value. String variables set to “None”, double variable set to 0, and all elements in the array set to 0. Two regular constructors: one, set student class variables in student information by different number of pass in parameter list; another set student information use pass in object. Compute grade: base on the % of final grade to compute final grade. Labs grade is 50% of final grade 1 and 2 are 15% of final grade 3 is 20% of final grade Display: print out student’s information in following sequence: Last name, First name each grade each labs grade final grade Main program (StudentReeord.cs for testing your Student class only): The main program begins with ask the user to enter input student information, then storing information into a student class variable. Compute student’s final grade for each student, who enter by the user. Next, print out each student’s information use student class displayAllGrade( ) function. Output Example: LastName, FirstName 1 2 3 lab1 lab2 lab3 lab4 lab5 final Anderson, Baily 67 89 75 92 83 78 68 67 77.2 LastName, FirstName 1 2 3 lab1 lab2 lab3 lab4 lab5 final Thomas, Daily 99 88 77 66 55 44 33 22 65.45 Your project should have two .cs file, which are StudentRecord.cs and Student.cs.
Thanks!
Short Summary:
Source Code:
Student.cs File:
using System;
namespace StudentDemo
{
class Student
{
// Constants
private const int TOTAL_GRADES = 8;
//private attributes
private string firstName;
private string lastName;
private double[] grades;
private double finalGrade;
/// <summary>
/// Default constructor
/// </summary>
public Student()
{
this.firstName = "None";
this.lastName = "None";
this.finalGrade = 0;
// Set all grades to zero
grades = new double[TOTAL_GRADES];
for(int index = 0; index < grades.Length; index++)
{
grades[index] = 0;
}
}
/// <summary>
/// Constructor
/// student class variables in student information by different number of pass in parameter list;
/// </summary>
public Student(string fname, string lname, double lab1, double lab2, double lab3, double lab4, double lab5,
double grade1, double grade2, double grade3)
{
this.firstName = fname;
this.lastName = lname;
grades = new double[TOTAL_GRADES];
this.grades[0] = lab1;
this.grades[1] = lab2;
this.grades[2] = lab3;
this.grades[3] = lab4;
this.grades[4] = lab5;
this.grades[5] = grade1;
this.grades[6] = grade2;
this.grades[7] = grade3;
// Compute final grade
ComputeGrade();
}
/// <summary>
/// Constrctor
/// set student information use pass in object.
/// </summary>
/// <param name="other"></param>
public Student(Student other)
{
this.firstName = other.firstName;
this.lastName = other.lastName;
this.grades = other.grades;
this.finalGrade = other.finalGrade;
}
/// <summary>
/// Compute grade: base on the % of final grade to compute final grade.
/// </summary>
private void ComputeGrade()
{
// Calculate lab grades
double labGrades = 0;
for(int index = 0; index < 5; index++)
{
labGrades += grades[index];
}
labGrades = labGrades / 5;
//Labs grade is 50% of final grade 1 and 2 are 15% of final grade 3 is 20% of final grade
this.finalGrade = (labGrades * 50 / 100) + (grades[5] * 15 / 100) + (grades[6] * 15 / 100) +
(grades[7] * 30 / 100);
}
/// <summary>
/// print out student’s information in following sequence:
/// Last name, First name each grade each labs grade final grade
/// </summary>
public void displayAllGrade()
{
string allGrades = "";
for(int index = 0; index < grades.Length; index++)
{
allGrades += grades[index] + " ";
}
Console.WriteLine(this.lastName + ", " + this.firstName + " " + allGrades + " " + this.finalGrade.ToString("0.00"));
}
/// <summary>
/// override ToString(), which only display class type, last name, first name, and final grade.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return this.GetType() + " " + this.lastName + " " + this.firstName + " " + this.finalGrade.ToString("0.00");
}
}
}
StudentRecord.cs File:
using System;
namespace StudentDemo
{
class StudentRecord
{
static void Main(string[] args)
{
// Get names
Console.Write("Enter Student's First Name: ");
string firstName = Console.ReadLine();
Console.Write("Enter Student's Last Name: ");
string lastName = Console.ReadLine();
double lab1 = 0, lab2 = 0, lab3 = 0, lab4 = 0, lab5 = 0,
grade1 = 0, grade2 = 0, grade3 = 0;
// Get lab grades
for (int index = 1; index <= 5; index++)
{
Console.Write("Enter Lab " + index + " Grade: ");
double lab;
double.TryParse(Console.ReadLine(), out lab);
if (index % 5 == 1)
{
lab1 = lab;
}
else if (index % 5 == 2)
{
lab2 = lab;
}
else if (index % 5 == 3)
{
lab3 = lab;
}
else if (index % 5 == 4)
{
lab4 = lab;
}
else if (index % 5 == 0)
{
lab5 = lab;
}
}
// Get grade
for (int index = 1; index <= 3; index++)
{
Console.Write("Enter Grade " + index + ": ");
double grade;
double.TryParse(Console.ReadLine(), out grade);
if (index % 3 == 1)
{
grade1 = grade;
}
else if (index % 3 == 2)
{
grade2 = grade;
}
else if (index % 3 == 0)
{
grade3 = grade;
}
}
// Create student object
Student student = new Student(firstName, lastName, lab1, lab2, lab3, lab4, lab5, grade1, grade2, grade3);
student.displayAllGrade();
Console.ReadKey();
}
}
}
Sample Run:
**************************************************************************************
Feel free to rate the answer and comment your questions, if you have any.
Please upvote the answer and appreciate our time.
Happy Studying!!!
**************************************************************************************