C 如果是文字成绩,我如何计算大学平均成绩?

C 如果是文字成绩,我如何计算大学平均成绩?,c,average,C,Average,我正在尝试编写一个C程序,从用户那里获取数据并计算他/她的平均值 它只得到讲座的学分和讲座的信用等级。文字等级系统如下所示: AA=4 BA=3.5 BB=3 CB=2.5 CC=2 DC=1.5 DD=1 FF=0 将字母等级(如AA=4)的对应值与课程的学分数相乘,即可获得增益。例如,如果等级为“AA”,则该讲座的收益对平均值的贡献将为4*讲座的学分 重量等级平均值通过总增益/总积分数计算得出 每堂课 计算增益 收益是相互叠加的 计算平均值 另一个例子 #include <stdi

我正在尝试编写一个C程序,从用户那里获取数据并计算他/她的平均值

它只得到讲座的学分和讲座的信用等级。文字等级系统如下所示:

  • AA=4
  • BA=3.5
  • BB=3
  • CB=2.5
  • CC=2
  • DC=1.5
  • DD=1
  • FF=0
将字母等级(如AA=4)的对应值与课程的学分数相乘,即可获得增益。例如,如果等级为“AA”,则该讲座的收益对平均值的贡献将为
4*讲座的学分

重量等级平均值通过
总增益/总积分数计算得出

每堂课

  • 计算增益
  • 收益是相互叠加的
  • 计算平均值
  • 另一个例子

    #include <stdio.h>
    #include <string.h>
    
    typedef struct
    {
      char  literal[3];
      float numeric;
    } GradeInfo_t; 
    
    typedef struct
    {
      /* Add all the extra info relevant to you: lecture name etcetera */
      unsigned int credits;
      char         grade[3];
    } LectureInfo_t;
    
    如果我目前的平均体重等级是3.00,47个学分,那么这意味着到目前为止我有141个加分。这学期我修了2门课,其中一门是AA,3学分,另一门是BB,3学分。本学期我的收益为21(4*3+3*3)。21被加到先前的增益(141)上。总收益现在是162。总学分为47+3+3=53。新的weitgh等级平均值为162/53=3.05

    我的代码

    #include <stdio.h>
    #include <string.h>
    
    typedef struct
    {
      char  literal[3];
      float numeric;
    } GradeInfo_t; 
    
    typedef struct
    {
      /* Add all the extra info relevant to you: lecture name etcetera */
      unsigned int credits;
      char         grade[3];
    } LectureInfo_t;
    
    我不能做的是,当用户输入
    AA
    BA
    时,如何使用条件状态设置增益?如果用户以3个学分输入
    aa
    ,则增益为12,如果用户以2个学分输入
    ba
    ,则增益为7

    简单地说,到目前为止,我获得了47个学分,平均成绩为2.66

    这学期我修了6门课

    • 课程a为4学分aa
    • 课程b是3学分的ba
    • 课程c为3学分dd等
    我的期末平均成绩是多少

    int main(){
        int sayi,i,j /*credit number of the lectur*/;
        int kredi /*obtained credit*/, abd, gain;
        float gurtalama; //current grade average
    
        int x[2],n[5];// x will be letter grade n will be name of the lecture.
    
        printf("number of obtained credits: "); //gets the number of obtained credits
        scanf("%d",&kredi);
    
        printf("current grade average : "); // current weight grade average
        scanf("%f",&gurtalama);
    
        printf("how many lectures you take this semestr? : "); // number of lectures are get to decide how many times the for loop will work
        scanf("%d",&sayi);
    
        for(i=0;i<sayi;i++) {
            printf("Name of the lecture: "); // this is for not to confuse it may not be necessary
            scanf("%s",&n);
    
            printf("Credit number of lecture: "); //for each lecture, lecture credit
            scanf("%d",&j);
    
            printf("Letter grade of lecture: "); // letter grade to convert it into 4 based system
            scanf("%s",&x);
    
            printf("%s ",n);            //Name of the lecture
            printf("%d Kredi. ",j);     //Credit of lecture
            printf("%s \n",x);          //letter grade of lecture
        }
    }
    
    intmain(){
    int sayi,i,j/*讲师的学分号*/;
    int kredi/*获得信贷*/,abd,收益;
    float gurtalama;//当前等级平均值
    int x[2],n[5];//x为字母,n级为讲座名称。
    printf(“获得的学分数:”;//获取获得的学分数
    scanf(“%d”&kredi);
    printf(“当前等级平均:”;//当前重量等级平均值
    scanf(“%f”和gurtalama);
    printf(“本学期你参加了多少次讲座?”:”;//讲座的次数决定for循环的工作次数
    scanf(“%d”和&sayi);
    
    对于(i=0;i,您的问题是将文字等级转换为数值-

    有不同的方法可以实现您的目标:我选择了一种解决方案,它可以直接比较输入分数与允许的分数集。这可以通过定义一个查找表来实现

    建议的解决方案将不包含:

    • 用户的输入检索。这取决于您,特别是因为如果您正确定义了引擎,则用户界面是一个可以以不同方式实现的细节(不仅可以使用
      scanf
      s循环,还可以处理输入文本文件等)
    • 不区分大小写的管理。只允许使用大写字母等级(如“BA”)。您可以轻松接受较低的字符等级,只需稍作更改
    • 额外讲座信息的管理,如讲座名称
    示例代码

    #include <stdio.h>
    #include <string.h>
    
    typedef struct
    {
      char  literal[3];
      float numeric;
    } GradeInfo_t; 
    
    typedef struct
    {
      /* Add all the extra info relevant to you: lecture name etcetera */
      unsigned int credits;
      char         grade[3];
    } LectureInfo_t;
    
    在这里,我使用先前定义的结构来定义两个数组:

  • 查找表,包含所有等级字符串文字及其相应的数值
  • 一组带有学分和分数的课程测试。在中插入了一个错误的分数。我希望程序放弃它。预期平均分数为275581395348837

  • 请正确格式化您的代码,并请给我们一个。AA,BA…是什么意思?我们将获得多少BA分数?如何计算?如果
    n
    是一个字符数组,那么您需要
    scanf(“%s”,n)
    。您可以显式编写
    &n[0]
    ,但只写
    n
    更为惯用。写
    &n
    @williampersell是错误的,
    n
    是一个
    int
    数组,而
    scanf(“%s”,n)
    是读取字符串(到
    int
    数组中)@RamblinRose:Not
    get()
    -已弃用且危险;使用
    fgets()
    Grade QQ (index 6) is wrong and has not been processed!
    Average grade is 2.76