Pages

Write a program that calculate Student GPA or CGPA by using 2D Array .

INPUT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace two_dimension_Array
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("******Welcome to Bahria university*******");
            Console.WriteLine("********GPA Calculator*********");
            Console.WriteLine("How many students are there in your Group?");
            int students = Convert.ToInt32(Console.ReadLine());

            string[,] marksheet = new string[students + 1, 7];
           
            int[] credithours = new int[6];
         
            double[,] gradepoint=new double[students,6];

            double[] gradepointaverage = new double[students];

            for (int i = 0; i < students + 1; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        marksheet[i, j] = "";
                    }
                    else if (i == 0)
                    {
                        Console.WriteLine("Please Enter Name of Course {0}", j);
                        marksheet[i, j] = Console.ReadLine();
                        Console.WriteLine("Please Enter the number of CREDIT HOURS of {0}",marksheet[i,j]);
                        credithours[j - 1] = Convert.ToInt32(Console.ReadLine());
                    }

                    else if (j == 0)
                    {
                        Console.WriteLine("\nPlease Enter the Name of Student Number {0}:", i);
                        marksheet[i, j] = Console.ReadLine();
                    }
                    else if (i != 0 && j != 0)
                    {
                        Console.WriteLine("Please enter marks (out of 100) of {0} in the subject {1}:", marksheet[i, 0], marksheet[0, j]);
                        marksheet[i, j] = Console.ReadLine();

                        int marks=Convert.ToInt32(marksheet[i,j]);
                        if (marks >= 87)
                        {
                            gradepoint[i - 1, j - 1] = 4.0;
                           
                        }
                        else if (marks >= 80 && marks < 87)
                        {
                            gradepoint[i - 1, j - 1] = 3.5;
                        }
                        else if (marks >= 71 && marks < 80)
                        {
                            gradepoint[i - 1, j - 1] = 3.0;
                        }
                        else if (marks >= 65 && marks < 71)
                        {
                            gradepoint[i - 1, j - 1] = 2.5;
                        }
                        else if (marks >= 57 && marks < 65)
                        {
                            gradepoint[i - 1, j - 1] = 2.0;
                        }
                        else if (marks >= 50 && marks < 57)
                        {
                            gradepoint[i - 1, j - 1] = 1.5;
                        }                       
                    }
                }
                Console.Clear();
            }


            double[] GradePointProduct=new double[6];
            double sumgpp=0;
            int sumcredithours=0;
            for (int i = 0; i < students; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    GradePointProduct[j] = gradepoint[i, j] * credithours[j];
                    sumcredithours += credithours[j];
                    sumgpp += GradePointProduct[j];
                }
                gradepointaverage[i] = sumgpp / sumcredithours;
            }

            for (int i = 0; i < students ; i++)
            {
                Console.WriteLine(" MARKSHEET ");
                Console.WriteLine("STUDENT NAME:  {0}\n\n",marksheet[i+1,0]);
                Console.WriteLine("COURSE TITLE\t\tMARKS OBTAINED\t\tGRADE POINT\n");
                for (int j = 1; j < 7; j++)
                {                    
                    Console.WriteLine("{0}\t\t{1}\t\t{2}\n", marksheet[0, j], marksheet[i+1, j], gradepoint[i , j-1]);
                }
                Console.WriteLine("GRADE POINT AVERAGE:  {0}",gradepointaverage[i]);
               
            }

        }
    }

}

OUTPUT:


2 comments:

  1. There is also a listbox that contains the GPA values from 1.0 to 4.0. here's my code so far, this is the calculate click event: Dim decMaleGPA As Decimal Dim decFemaleGPA As Decimal Dim decAverageFGPA As Decimal Dim decAverageMGPA As Decimal Dim decAverageAll As Decimal . Look on: calculator-online.net

    ReplyDelete