Header Ads

Header ADS

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#

4 comments:

  1. i dont understand how the calculator works

    ReplyDelete
  2. ((credithour of subject1 * grade in subject1)+---------+n) / totla credit hour
    here i use A grade = 4 point
    B+ = 3.5
    B = 3
    C+ = 2.5
    C = 2
    D = 1.5
    F = 0

    ReplyDelete
  3. The application growth area, containing many different on-line software development each designed to meet up with various requirements depending on the project at hand.

    ReplyDelete
  4. Primeau Productions is your full-service online video media production company, within firm for greater than 30 years. Primeau Productions owes the success directly towards results The item achieves due to the clients. my partner and i are a results-oriented company, Equally set up from MY PERSONAL wrote number regarding long-term, repeat customers. professional-video-recording-services

    ReplyDelete

Powered by Blogger.