Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to use visual studio 2015 C# to make a program that maintain stduent scores

ID: 3595098 • Letter: H

Question

How to use visual studio 2015 C# to make a program that maintain stduent scores in the form. The program allows user to add new student name with scores or without scores, remove stduent scores, and update studens name or scores from the list. The 5 required forms should look as the following:

Project 2-2 Maintain student scores For this project, you'll develop an application that lets the user add students to a list, change the scores for a student in the list, and delete a student from the list. Prerequisites: chapters 1-10 The design of the Student Scores form Student Scores Students: Joel Murach97763Add New Doug Lowel99(93197 Anne Boehm/100 1001100 Update... Delete Score total: 251 Score count: 3 Average: 83 Exit Operation To display the total, count, and average for a student, the user selects the student from the list box. If the list box is empty, the total, count, and average labels should be cleared. .To add a new student, the user clicks the Add New button to display the Add New Student dialog box . To update an existing student's scores, the user selects the student in the list box and clicks the Update button to display the Update Student Scores dialog box . To delete a student, the user selects the student in the list box and clicks the Delete button

Explanation / Answer

StudentDB.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace project6
{
    public class StudentDB
    {
        private const string dir = @"C:C#.NETFiles";
        private const string path = dir + "StudentScores.txt";

        public static void SaveStudents(List<Student> students)
        {
            StreamWriter textOut =
                new StreamWriter(
                new FileStream(path, FileMode.Create, FileAccess.Write));

            foreach (Student student in students)
            {
                string scoresList = "";

                for (int i = 0; i < student.ScoreList.Count(); i++)
                {
                    int value = student.ScoreList[i];

                    scoresList += (value + ",");
                }

                textOut.Write(student.Name + "|");
                textOut.WriteLine(scoresList.TrimEnd(','));
            }
            textOut.Close();
        }

        public static List<Student> GetStudents()
        {
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            StreamReader textIn =
                new StreamReader(
                new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));

            List<Student> students = new List<Student>();

            while (textIn.Peek() != -1)
            {
                string row = textIn.ReadLine();
                string[] columns = row.Split('|');
                Student student = new Student();

                List<int> scoreList = new List<int>();

                if (columns[1] != "")
                {
                    int[] scoreArray = columns[1].Split(',').Select(n => Convert.ToInt32(n)).ToArray();

                    scoreList = scoreArray.ToList();
                    student.ScoreList = scoreList;
                }
                else
                {
                    student.ScoreList = new List<int>();
                }

                student.Name = columns[0];
                students.Add(student);

            }

            textIn.Close();

            return students;
        }

        public static void LoadSampleStudents()
        {
          
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (!File.Exists(path))
            {

                StreamWriter textOut =
                new StreamWriter(
                new FileStream(path, FileMode.Create, FileAccess.Write));

                textOut.WriteLine("Joel Murach|97,71,83");
                textOut.WriteLine("Doug Lowe|99,93,97");
                textOut.WriteLine("Anne Prince|100,100,100");

                textOut.Close();
            }
        }
    }
}

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project6
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmStudentScores());
        }
    }
}

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

namespace project6
{
    public class Student
    {
        private string name;
        private List<int> scoreList;

        public Student()
        {
        }

        public Student(string name, List<int> scoreList)
        {
            this.Name = name;
            this.ScoreList = scoreList;
        }

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

        public List<int> ScoreList
        {
            get
            {
                return scoreList;
            }
            set
            {
                scoreList = value;
            }
        }

        public string GetDisplayText()
        {
            string total = "";
            foreach (int score in scoreList)
            {
                total += "|" + score;
            }
            return name + total;
        }
    }
}

Validator.cs

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

namespace project6
{
    public static class Validator
    {
        public static string title = "Entry Error";

        public static bool IsPresent(TextBox textBox, string name)
        {
            if (textBox.Text == String.Empty)
            {
                MessageBox.Show(name + " is a required field.", title);
                textBox.Focus();
                return false;
            }
            return true;
        }

        public static bool IsInt32(TextBox textBox, string name)
        {
            int number = 0;
            if (Int32.TryParse(textBox.Text, out number))
            {
                return true;
            }
            else
            {
                MessageBox.Show(name + " must be an integer.", title);
                textBox.Focus();
                return false;
            }
        }

        public static bool IsWithinRange(TextBox textBox, string name, int min, int max)
        {
            int number = Convert.ToInt32(textBox.Text);
            if (number < min || number > max)
            {
                MessageBox.Show(name + " must be between " + min + " and " + max + ".", title);
                textBox.Focus();
                return false;
            }
            return true;
        }
    }
}

frmAddScore.Designer.cs
namespace project6
{
    partial class frmAddScore
    {
        private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.btnAdd = new System.Windows.Forms.Button();
            this.txtBoxScore = new System.Windows.Forms.TextBox();
            this.btnCancel = new System.Windows.Forms.Button();
            this.SuspendLayout();
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(38, 25);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(38, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Score:";
            this.btnAdd.Location = new System.Drawing.Point(12, 58);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(75, 23);
            this.btnAdd.TabIndex = 1;
            this.btnAdd.Text = "&Add";
            this.btnAdd.UseVisualStyleBackColor = true;
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            this.txtBoxScore.Location = new System.Drawing.Point(82, 22);
            this.txtBoxScore.Name = "txtBoxScore";
            this.txtBoxScore.Size = new System.Drawing.Size(75, 20);
            this.txtBoxScore.TabIndex = 2;
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Location = new System.Drawing.Point(93, 58);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(75, 23);
            this.btnCancel.TabIndex = 3;
            this.btnCancel.Text = "&Cancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            this.AcceptButton = this.btnAdd;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(184, 91);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.txtBoxScore);
            this.Controls.Add(this.btnAdd);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmAddScore";
            this.Text = "Add Score";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button btnAdd;
        private System.Windows.Forms.TextBox txtBoxScore;
        private System.Windows.Forms.Button btnCancel;
    }
}

frmAddScore.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project6
{
    public partial class frmAddScore : Form
    {
        private int score = -1;

        public frmAddScore()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
          
            if (IsValidData())
            {
                score = Convert.ToInt32(txtBoxScore.Text);
                this.Close();
            }
          
        }

        public int GetNewScore()
        {
            this.ShowDialog();
            return score;
        }

        private bool IsValidData()
        {
            return Validator.IsPresent(txtBoxScore, "Score") &&
                Validator.IsInt32(txtBoxScore, "Score") &&
                Validator.IsWithinRange(txtBoxScore, "Score", 0, 100);
        }
    }
}

frmAddStudent.Designer.cs
namespace project6
{
    partial class frmAddStudent
    {
        private System.ComponentModel.IContainer components = null;
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        private void InitializeComponent()
        {
            this.lblName = new System.Windows.Forms.Label();
            this.txtName = new System.Windows.Forms.TextBox();
            this.btnCancel = new System.Windows.Forms.Button();
            this.btnOk = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.txtScore = new System.Windows.Forms.TextBox();
            this.btnAddScore = new System.Windows.Forms.Button();
            this.lblScores = new System.Windows.Forms.Label();
            this.btnClearScores = new System.Windows.Forms.Button();
            this.SuspendLayout();
            this.lblName.AutoSize = true;
            this.lblName.Location = new System.Drawing.Point(23, 24);
            this.lblName.Name = "lblName";
            this.lblName.Size = new System.Drawing.Size(38, 13);
            this.lblName.TabIndex = 0;
            this.lblName.Text = "Name:";
            this.txtName.Location = new System.Drawing.Point(67, 21);
            this.txtName.Name = "txtName";
            this.txtName.Size = new System.Drawing.Size(205, 20);
            this.txtName.TabIndex = 1;
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Location = new System.Drawing.Point(197, 154);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(75, 23);
            this.btnCancel.TabIndex = 2;
            this.btnCancel.Text = "&Cancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            this.btnOk.Location = new System.Drawing.Point(116, 154);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(75, 23);
            this.btnOk.TabIndex = 3;
            this.btnOk.Text = "&OK";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(23, 52);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(38, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "Score:";
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(18, 83);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(43, 13);
            this.label2.TabIndex = 5;
            this.label2.Text = "Scores:";
            this.txtScore.Location = new System.Drawing.Point(67, 49);
            this.txtScore.Name = "txtScore";
            this.txtScore.Size = new System.Drawing.Size(124, 20);
            this.txtScore.TabIndex = 6;
            this.btnAddScore.Location = new System.Drawing.Point(197, 47);
            this.btnAddScore.Name = "btnAddScore";
            this.btnAddScore.Size = new System.Drawing.Size(75, 23);
            this.btnAddScore.TabIndex = 7;
            this.btnAddScore.Text = "&Add Score";
            this.btnAddScore.UseVisualStyleBackColor = true;
            this.btnAddScore.Click += new System.EventHandler(this.btnAddScore_Click);
            this.lblScores.AutoSize = true;
            this.lblScores.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.lblScores.Location = new System.Drawing.Point(67, 83);
            this.lblScores.MinimumSize = new System.Drawing.Size(205, 20);
            this.lblScores.Name = "lblScores";
            this.lblScores.Size = new System.Drawing.Size(205, 20);
            this.lblScores.TabIndex = 8;
            this.btnClearScores.Location = new System.Drawing.Point(197, 115);
            this.btnClearScores.Name = "btnClearScores";
            this.btnClearScores.Size = new System.Drawing.Size(75, 23);
            this.btnClearScores.TabIndex = 9;
            this.btnClearScores.Text = "&Clear Scores";
            this.btnClearScores.UseVisualStyleBackColor = true;
            this.btnClearScores.Click += new System.EventHandler(this.btnClearScores_Click);
            this.AcceptButton = this.btnOk;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(284, 187);
            this.Controls.Add(this.btnClearScores);
            this.Controls.Add(this.lblScores);
            this.Controls.Add(this.btnAddScore);
            this.Controls.Add(this.txtScore);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.btnOk);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.txtName);
            this.Controls.Add(this.lblName);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmAddStudent";
            this.Text = "Add Student";
            this.Load += new System.EventHandler(this.frmAddStudent_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label lblName;
        private System.Windows.Forms.TextBox txtName;
        private System.Windows.Forms.Button btnCancel;
        private System.Windows.Forms.Button btnOk;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox txtScore;
        private System.Windows.Forms.Button btnAddScore;
        private System.Windows.Forms.Label lblScores;
        private System.Windows.Forms.Button btnClearScores;
    }
}

frmAddStudent.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project6
{
    public partial class frmAddStudent : Form
    {
        public frmAddStudent()
        {
            InitializeComponent();
        }

        private Student student = null;

        public Student GetNewStudent()
        {
            this.ShowDialog();
            return student;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (Validator.IsPresent(txtName, "Name"))
            {
                student = new Student(txtName.Text, tempList);
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        List<int> tempList = new List<int>();

        private void btnAddScore_Click(object sender, EventArgs e)
        {
            if (IsValidData())
            {
                tempList.Add(Convert.ToInt32(txtScore.Text));
                string total = "";
                foreach (int scores in tempList)
                {
                    total += Convert.ToString(scores) + " ";
                }
                lblScores.Text = total;
            }
        }

        private void frmAddStudent_Load(object sender, EventArgs e)
        {
          
        }

        private void btnClearScores_Click(object sender, EventArgs e)
        {
            tempList.Clear();
            lblScores.Text = String.Empty;
        }

        private bool IsValidData()
        {
            return Validator.IsPresent(txtScore, "Score") &&
                Validator.IsInt32(txtScore, "Score") &&
                Validator.IsWithinRange(txtScore, "Score", 0, 100);
        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project6
{
    public partial class frmStudentScores : Form
    {
        public frmStudentScores()
        {
            InitializeComponent();
        }

        private List<Student> students = null;

        private void FillStudentListBox()
        {
            lstBoxStudents.Items.Clear();
            foreach (Student s in students)
            {
                lstBoxStudents.Items.Add(s.GetDisplayText());
            }
        }

        private void frmStudentScores_Load(object sender, EventArgs e)
        {
            StudentDB.LoadSampleStudents();
            students = StudentDB.GetStudents();
            FillStudentListBox();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddStudent addStudentForm = new frmAddStudent();
            Student student = addStudentForm.GetNewStudent();

            if (student != null)
            {
                students.Add(student);
                StudentDB.SaveStudents(students);
                FillStudentListBox();
                int i = students.Count - 1;
                lstBoxStudents.SetSelected(i, true);
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            int i = lstBoxStudents.SelectedIndex;
            if (i != -1)
            {
                Student selectedStudent = students[i];
                frmUpdateStudentScores updateStudentScoresForm = new frmUpdateStudentScores(selectedStudent);
                updateStudentScoresForm.GetUpdatedStudent();
                StudentDB.SaveStudents(students);
                FillStudentListBox();
                lstBoxStudents.SetSelected(i, true);
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            int i = lstBoxStudents.SelectedIndex;

            if (i != -1)
            {
                Student student = students[i];
                students.Remove(student);
                StudentDB.SaveStudents(students);
                FillStudentListBox();
                lblScoreTotal.Text = String.Empty;
                lblScoreCount.Text = String.Empty;
                lblAverage.Text = String.Empty;
            }
        }

        private void lstBoxStudents_SelectedIndexChanged(object sender, EventArgs e)
        {
            Calculations();
        }

        private void Calculations()
        {
            int i = lstBoxStudents.SelectedIndex;
          
            if (i != -1)
            {
                Student selectedStudent = students[i];
                if (selectedStudent.ScoreList.Count() == 0)
                {
                    lblScoreTotal.Text = "n/a";
                    lblScoreCount.Text = "0";
                    lblAverage.Text = "n/a";
                }
                else
                {
                    int total = 0;
                    foreach (int score in selectedStudent.ScoreList)
                    {
                        total += score;
                    }
                    int count = selectedStudent.ScoreList.Count();
                    decimal average = Convert.ToDecimal(total) / Convert.ToDecimal(count);

                    lblScoreTotal.Text = Convert.ToString(total);
                    lblScoreCount.Text = Convert.ToString(count);
                    lblAverage.Text = average.ToString("#.##");

                }
            }
        }
    }
}

i cant able to include below files due to limited character

frmStudentScores.Designer.cs
frmUpdateScores.Designer.cs
frmUpdateScores.cs
frmUpdateStudeScores.Designer.cs
frmUpdateStudeScores.cs

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote