📌  相关文章
📜  计算学生在N个科目中获得的CGPA和CGPA分数

📅  最后修改于: 2021-05-04 14:03:40             🧑  作者: Mango

给定大小为N的数组arr [] ,该数组包含一个学生在N个科目中的成绩,则任务是计算该学生的CGPA和CGPA百分比。
注意:对于每个主题,考虑所有分数均不超过100。

例子:

方法:在本文中,CGPA的计算范围为10。

  • 从用户输入包含N个科目的学生成绩的数组。
  • 由于比例尺为10,因此将每个学科的分数除以10,即可得出每个学科的学生的GPA。
  • 所有GPA的平均值得出学生的总体CGPA。
  • 找到CGPA之后,可以通过以下公式计算CGPA百分比:
CGPA% = CGPA * 9.5
  • 这是刻度为10的一般公式。但是,如果整个计算是在刻度4上进行的,则此9.5将乘以2.5 ,而CGPA百分比将乘以23.75

下面是上述方法的实现:

C++
// C++ program to calculate the CGPA
// and CGPA percentage of a student
#include
using namespace std;
 
double CgpaCalc(double marks[], int n)
{
    // Variable to store the grades in
    // every subject
    double grade[n];
 
    // Variables to store CGPA and the
    // sum of all the grades
    double cgpa, sum = 0;
 
    // Computing the grades
    for(int i = 0; i < n; i++)
    {
       grade[i] = (marks[i] / 10);
    }
 
    // Computing the sum of grades
    for(int i = 0; i < n; i++)
    {
       sum += grade[i];
    }
 
    // Computing the CGPA
    cgpa = sum / n;
 
    return cgpa;
}
 
// Driver code
int main()
{
    int n = 5;
    double marks[] = { 90, 80, 70, 80, 90 };
 
    double cgpa = CgpaCalc(marks, n);
         
    cout << "CGPA = ";
    printf("%.1f\n", cgpa);
    cout << "CGPA Percentage = ";
    printf("%.2f", cgpa * 9.5);
}
 
// This code is contributed by Bhupendra_Singh


Java
// Java program to calculate the CGPA
// and CGPA percentage of a student
 
import java.util.Scanner;
class CGPA {
 
    public static double CgpaCalc(double[] marks, int n)
    {
        // Variable to store the grades in
        // every subject
        double grade[] = new double[n];
 
        // Variables to store CGPA and the
        // sum of all the grades
        double cgpa, sum = 0;
 
        // Computing the grades
        for (int i = 0; i < n; i++) {
            grade[i] = (marks[i] / 10);
        }
 
        // Computing the sum of grades
        for (int i = 0; i < n; i++) {
            sum += grade[i];
        }
 
        // Computing the CGPA
        cgpa = sum / n;
 
        return cgpa;
    }
 
    // Driver code
    public static void main(String args[])
    {
 
        int n = 5;
        double[] marks
            = { 90, 80, 70, 80, 90 };
 
        double cgpa = CgpaCalc(marks, n);
 
        System.out.println(
            "CGPA = " + cgpa);
        System.out.println(
            "CGPA Percentage = "
            + String.format("%.2f", cgpa * 9.5));
    }
}


Python3
# Python3 program to calculate the CGPA
# and CGPA percentage of a student
def CgpaCalc(marks, n):
 
    # Variable to store the grades in
    # every subject
    grade = [0] * n
   
    # Variables to store CGPA and the
    # sum of all the grades
    Sum = 0
   
    # Computing the grades
    for i in range(n):
       grade[i] = (marks[i] / 10)
   
    # Computing the sum of grades
    for i in range(n):
       Sum += grade[i]
   
    # Computing the CGPA
    cgpa = Sum / n
   
    return cgpa
   
# Driver code
n = 5
marks = [ 90, 80, 70, 80, 90 ]
 
cgpa = CgpaCalc(marks, n)
       
print("CGPA = ", '%.1f' % cgpa)
print("CGPA Percentage = ", '%.2f' % (cgpa * 9.5))
 
# This code is contributed by divyeshrabadiya07


C#
// C# program to calculate the CGPA
// and CGPA percentage of a student
using System;
 
class GFG{
 
public static double CgpaCalc(double[] marks,
                              int n)
{
     
    // Variable to store the grades in
    // every subject
    double []grade = new double[n];
 
    // Variables to store CGPA and the
    // sum of all the grades
    double cgpa, sum = 0;
 
    // Computing the grades
    for(int i = 0; i < n; i++)
    {
        grade[i] = (marks[i] / 10);
    }
 
    // Computing the sum of grades
    for(int i = 0; i < n; i++)
    {
        sum += grade[i];
    }
 
    // Computing the CGPA
    cgpa = sum / n;
 
    return cgpa;
}
 
// Driver code
public static void Main(String []args)
{
    int n = 5;
    double[] marks = { 90, 80, 70, 80, 90 };
    double cgpa = CgpaCalc(marks, n);
 
    Console.WriteLine("CGPA = " + cgpa);
    Console.WriteLine("CGPA Percentage = {0:F2}",
                      cgpa * 9.5);
}
}
 
// This code is contributed by Amit Katiyar


输出:
CGPA = 8.2
CGPA Percentage = 77.90