How to calculate your GPA with simple application C#

  This is simplest GPA calculator in which user input the previous CGPA and previous Credit Hours (not for first semester these two fields) and no of new subjects and then enters the grade and credit hours of the subjects and insert in data grid view one by one if he by mistake put the wrong Grade or Credit Hours they can delete the wrong input by selecting the row and input again after input all Grades and Credit Hours then click on calculate button calculator calculate the new GPA and CGPA and display it.
Calculation code is:-
//to calculate GPA
            float Gradepoint = 0;
            int k = 0;
            //for read data from datagridview
            for (int i = 0; i < l - 1; i++)
            {
                //grade is A then CH * 4
                if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "A")
 Gradepoint += 4 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                //grade is B+ then CH * 3.5
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "B+")
Gradepoint += 7 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()) / 2;
                //grade is B then CH * 3
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "B")
Gradepoint += 3 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                //grade is C+ then CH * 2.5
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "C+")
Gradepoint += 5 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()) / 2;
                //grade is C then CH * 2
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "C")
Gradepoint += 2 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                //grade is D then CH * 1.5
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "D")
Gradepoint += 3 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()) / 2;
                //adding total CH in k
                k += int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
            }
            //calculate the GPA and displaying maskedtextbox
            maskedTextBox5.Text = ((Gradepoint / k).ToString());
            //to calculate CGPA
            if (maskedTextBox1.Text == "" || maskedTextBox2.Text == "")
                maskedTextBox6.Text = maskedTextBox5.Text;
            else
            {
float h = float.Parse(maskedTextBox1.Text) * (int.Parse(maskedTextBox2.Text));
                h += Gradepoint;
                int CH = int.Parse(maskedTextBox2.Text) + k;
                maskedTextBox6.Text = (h / CH).ToString();
            }
Delete the selected Row code is:-
DialogResult Result = MessageBox.Show("Do You really want to Delete???",      "Confirmation", MessageBoxButtons.YesNo);
            if (Result == DialogResult.Yes)
            {
                dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
                l--;
                label4.Text = "Grade of Subject ";
                label5.Text = "C H of Subject ";
                if (l <= k)
                {
                    label4.Text += l;
                    label5.Text += l;
                }
            }
If the user want to find the new GPA or CGPA then click on New button the New button reset all the field.
Code of New button:-
            dataGridView1.Rows.Clear();
            l = 1;
            k = 0;
            g = 0;
            label4.Text = "Grade of Subject ";
            label5.Text = "C H of Subject ";
            maskedTextBox3.ReadOnly = false;
            maskedTextBox1.Text = "";
            maskedTextBox2.Text = "";
            maskedTextBox3.Text = "";
            maskedTextBox5.Text = "";
            maskedTextBox6.Text = "";
            comboBox1.Text = "";
            comboBox2.Text = "";
            button2.Enabled = false;
            button1.Enabled = false;


Screen Shot

How to calculate your GPA with simple application C#

Popular posts from this blog

Real marksheet using HTML

Salary Calculate Application in C#