0 like 0 dislike
13.4k views

Finish the function compute_GPA below. The function should return the average of the grades (assume that A=4,B=3,C=2,D=1, and F=0). The grades array will contain letter grades (A,B,C,D, or F, either upper-case or lower-case 大寫小寫), n is the length of the array

寫compute_GPA函數。函數會return成績平均(A = 4, B = 3, C = 2, D = 1, F = 0)

#include <stdio.h>
float compute_GPA(char grades[],int n)
{
   /*INSERT YOUR CODE HERE*/


   /*END OF YOUR CODE*/
   //The function should return the average of the grades(assume that A=4,B=3,C=2,D=1, and F=0).
}

int main(void)
{
   char G[100];
   int n;

   /*INSERT YOUR CODE HERE*/


   /*END OF YOUR CODE*/

   printf("%g",compute_GPA(G,n));

   return 0;
}

Example input: 

The first input is the number of elements need to compute GPA (4); The array values follow; 

第一行是成績數目,第二行是成績(A/B/C/D/F)

4
A B C D

Example output

2.5

Remember: You may correct the cases, but your code always be revised!

[Exercise] Coding (C) - asked in Chapter 9: Functions by (5.2k points)
ID: 37278 - Available when: 2017-12-14 18:00 - Due to: Unlimited

edited by | 13.4k views

50 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
float compute_GPA(char grades[],int n)
{
*** * ***** * * av;
   float a,b,c,d;int i;
* ** ***** **
   for (i=0; i<n; i++)
   {
** * *** * **** * *** *** ** ** ** * * *** ** (grades[i]=='A')
* * **** * * ** ** * * ** * * *
* * ** * * * ** ** ****** * * * * * ***** **** * * ***
* ** ** * ******* * * **** *** *
* ** * ***** *** ** * * **** ** * * * **** **** * **
*** * ** * * * * *** **** *** **
*** * * ** * * **** * *** ** * * ** * * * * * * * ***
* * ** * * ******* * * * * ** ** *** ***
* * * ******** * ** ** ** ** ** ** *** **********
* * * * * * * ** * ** * ** * ** *
*** ** ******* * ** * * * ** * * * * * ** * ** ** ****
** *** * *** ** * *** **** * *
*** *** ** ** * * ***** * ** *** (grades[i]=='D')
* *** * * * ** ** *** *** ** *
*** * * * **** ** * * * * * * ** * *** * * ** * *
* * * * ***** * * **** * *** ** *
   }
**** * * * * ******* * *** ******* * * **** ** ** **
* * * ** * *** ** **** * **** * * * * * av;
}

int main(void)
{
   char G[100];
   int n,c,v;
* ** * * * * ** ***** * * * &n);
   v=0;
   for (c=0; c<n; c++)
   {
* * *** **** * *** * ** *** * * ** *
* *** * ** * * ** * * ** ** * ** * * * * * *
** * *** ** ***** ** * ******** ********** * ** * * *
***** ** * * * * **** ** ***** *** * * **
** **** * ** ** ** *** *** * * ***
**** **** ** *** * *** ***** * ***** *
* ** *** * *** * * * ** * ** ** ** *** **** * *** * * *** *** * %s",&G[c]);
** * * *** ********* *** * * ** *
** * ** ***** ** ** * ***** *** ** * ** *
   }

** * * *** * ***** *** * * * * ** ** *

* * ******** * **** 0;
}
answered by (-168 points)
edited by
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
float compute_GPA(char grades[],int n)
{
** * * * ** * ** av;
*** * * * * * * a,b,c,d;int i;
* ** **** **** ***
* * *** ******* * * (i=0; i<n; i++)
   {
* *** * ** * * ** * * * **** * * * *** ** ** (grades[i]=='A')
* * * ** ** *** * **** * * *** * *
******* ** * ** ** ******* **** ***** ** ** ** * ** ** * **
* *** * ** ** ** * ** * * * * *** ******
** * ** ** * ** * * * * * *** ***
* *** ** * * ****** *** **** * **
** * **** * **** * * * * * *** ** * **** * ****** * * * ****
* *** ***** * ** ** ***
* *** * *** *** * * * *** * * **** * *
* *** *** * ***** ** * * * ** * * * *** *
* **** * ** * * * * * * ** * ******** *** * * * ** * **** *
** * * * ** *** * *** **
* ** * ** * ** *** * * *** * *** ** (grades[i]=='D')
* * ** * ** * * ** * ***** ** ** * * *
* ******* ** * * * ** * * * * *** *** ****** * * * ** * *
* * * * ** **** *** * ** * **** ****** * ****
   }
* * ** * * * ** * *** ** * ** *** * **** * *
** **** **** * ** * **** * * ** ** ** * av;
}

int main(void)
{
* *** * *** G[100];
   int n,c;
** ***** ** * **** * ****** ** &n);
   for (c=0; c<n; c++)
   {
** **** *** ** ** ** * * *** ** ** * * * **** ** * * ** **
   }
* * * ** * * *** * ****** * **** *** *** ***

* ******* * * * * * 0;
}
answered by (-168 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
float compute_GPA(char grades[],int n)
{
**** * *** * ****** * av;
* * ** *** * *** ******* a,b,c,d;int i;
**** * * * ******** *
** * * ****** ** *** (i=0; i<n; i++)
   {
* * ** * * * * * * *** **** (grades[i]=='A')
*** * * * * ** * * ** * **** * ** *****
* * * * * ** ** * ** *** * **** * *** ** * * * ** **
** *** * * * * * * * * *** ** *
******* * * * * * ** ** ** * *** * ****** * **
* *** **** * *** * * * ** ** * *
* * ** * ** * ** ** * * * * * * ***** * * **** *** **** *
** *** * * * ** ** * * * * ** *
* ** ** ** * * * ** ** ** * ** ** *** ** *
* *** * * ** ** ** * * * ** * ***** *
* ***** * ***** ** *** *** * ** * * ********* ****** *** * ** * **
* * * * **** * * * * ** * *
** * * ** * * ** ** * *** * * * (grades[i]=='D')
** * ** ** ** ***** ** ******** **
* * **** * * ** ** * * **** ** *** * * ** * * * ** ** ** * ****
*** ** **** *** * * * * * ** * *
   }
* * * * ** * ** * * ***** ** ******* ** * **
* *** * * * ** *** ** *** * * ***** **** av;
}

int main(void)
{
**** ** ** * * * G[100];
   int n,c;
** * ********* ** * *** * ** * &n);
   for (c=0; c<n; c++)
   {
*** ** * *** ** * * * * ** * * *** **** * * ***
   }
* *** * * * * * ** * * * * ** * * * ** *

* ** ** ** ** * ** 0;
}
answered by (-168 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
float compute_GPA(char grades[],int n)
{


* **** * * * ** ** YOUR CODE HERE*/
* * * ** * *** * * i;
** * *** ** * * ** gpa,sum=0;
***** * * * ** * ** ** ** * ***
* *** * * * *** * **
** * * * * **** * *** ** * **** || grades[i]=='a')
****** ** *** * ** * **** * * * ** *** *** *
** ** *** * ** * ******* || grades[i]=='b')
* * *** ** * * * **** * * * ** ** **** ****
*** * *** *** ** ** * ** * ** *** * || grades[i]=='c')
*** * ** * ** ** * ** * ** ** * * ****
*** * ***** ** ** **** * * *** * || grades[i]=='d')
* * ** * * ** * *** *** ******* ** * **** *

* * * * ** *****
* * * *** * ** ** *** ** ***
* * * **** ** * ***** * * gpa;
** * * ** *** **** * * * * OF YOUR CODE*/
* *** ** ******* *** function should return the average of the grades(assume that A=4,B=3,C=2,D=1, and F=0).
}

int main(void)
{
*** ** * * * * G[100];
** ** * * *** ****** * n;

** * *** ** * ** * * YOUR CODE HERE*/
** **** * ** ** *** ** * ** ** ** i;
** * *** * ***** ** * * * ** * ** **
* *** * * ** ** *** * * * * ***
** ** *** ** ** *
*** * * ******* ** *** ** *** * * ** * ** *** ** * *
** ** *** ** ** * *


* ** ** * **** OF YOUR CODE*/

*** * * *** *** ** * * ** * * * ***

****** * ***** * 0;
}
answered by (-196 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
float compute_GPA(char grades[],int n)
{
** * ***** * ** * YOUR CODE HERE*/
*** ** ** * * * * i;
* * * *** * * ***** *** total=0;
* ** ** ** ** ********* * *** * ** * ** *
* * * ** * * ** * ***** **** **** * ** ** ** * **** *** *****
** *** * **** * ** * **** * * *********** *** ** *** * * ** ** * * * ** *****
* *** * ** * ** * ** ****** * **** * * *** **** ***** ****** *
* ******* * ** * *** **** *** * ** **** * * * ** ******* *** ***
* *** ***** * ** ** ** ** * ** * * * *** * ** ** ** * ****** * ** * ***
*** **** *** *** **** * ** **
** * ** * ** *** *** = total/n;

* * * ** ** * * ** * total;

   /*END OF YOUR CODE*/
** ** ** *** function should return the average of the grades(assume that A=4,B=3,C=2,D=1, and F=0).
}

int main(void)
{
   char G[100];
   int n;

* * ** * * * *** * YOUR CODE HERE*/
* *** * * * * ** * ** * **** * **** * **
* * * ** ** * * i;
* ** * * * * * * ****** *** *
* * ****** ** * * * ** ** * * ****
* ** ** ** ** ***** **** ** * ** ** * ***** * * *** *
*** * * ** *** ******* * * * **** * ** * * '){
* *** * ****** * * * ** * ******* * * ** *** * * ** ** * * *** ** * **** * ** * tag;
* * *** *** ** * * * ******* ** * * **
* ** * ** ** *** * ****

* * * * * **** *** * OF YOUR CODE*/

* * * *** ** ** * * * *** * * * *

** * * * *** * * ** * 0;
}
answered by (-286 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include * ***** * **
float ** * ** **** n)
{
* ** * * * **** * YOUR CODE HERE*/
** * *** * * ****
** ** *** ** ** sum=0;
* * **** ** * **** i;
** *** * ** * ** * * *
*** *** *** ** *
* * * ** ** * * *** *** * **** **** *
***** *** ** *** * * **** * * *** * {
** * ** *** ** * * * * * * * * * * ** ** * * * * * * *
*** * * ** ** * ** }
** *** * * ** * * **
** ** * ** * {
* * * * * * ** * ** * * * *   sum=sum+3;
* * **       }
* ***   * ** ** * ** * **
**       {
* * * *       * ** * ** ****
* * * ** * * ** * }
* * * ** *** * * * * ***
*** * * * ** *** * {
*** * * * * * * * * ** * * * **
* * * ** * * * ** * * }
* ** * ** * * * * ** **
* * * **** * *** **** {
** ** * ** * ** * * * ** ** * * * *
*** * ** ** * ** * **** * }
*** ** * *
* ****** * *** *
** * * * * *** * * ** * *
** * ** *** return sum;
**** * *


*** * * * * * * *** OF YOUR CODE*/
*** **** ** * ** function should return the average of the * * * that * ** * and F=0).
}

int ** **
{
* * * ** * * * * G[100];
*** ** ** * * n;

* ** * *** * *** ** YOUR CODE HERE*/
** *** *
* *** * int i;
** ** ** **** char trash;
* **** * ** ** **** ** * ** **** * *
*** * * ** ** * * * *
**** * * * ** {
**** ** * * * ** **** * * * * * * ** * *** * * ***
* * * * **** **** * ****** ** * *** * *
* ** ** * ** ** ***
      ****
* ** * }
* * * ** *
**
* * *

***** * *** * * OF YOUR CODE*/

* *** * *** *** * * * *** ** *** * ***

* *** *** ** ** ** * 0;
}
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include * **** *****
float *** * * * ** n)
{
** * * ** * ** * * * YOUR CODE HERE*/
* ******** * * * *
* *** ** **** sum=0;
** * ** * * *** **** * i;
* ***** ** ****** ** * ***** **
* ** * ***** * **
** ** * ***** ** **** * * * *** * ** **
** *** * *** * * * ** * ** ***** {
* * * ** * * * * * ** ** * * * * *** *** * * ***** * * * *
** * * * * ****** *** *** }
** * * * ** * ***** ***
*** * * ** * **** ******* {
******* **** ** * ** ** * ** ** * * sum=sum+3;
*       }
* * **   ** ** *
* **       {
****       ** *** * ****
* ** * * * ** * * }
** *** * ** * ** ****
* * **** * * * * *** * * * {
* ***** * ** ***** **** ** *** * * * * * *
** * * ** * * * ** }
******* * * ***** *** *
*** ** ***** * * {
* ** * ***** ** ** **** ***** ** *** * **
* ** * * ** * ** * }
* * *** * *****
* * ************
* * **** * * * ****** *
* ** ** return sum;
*** * * ** * ** *


* ** ** * ** * * * OF YOUR CODE*/
* * * ** * *** **** function should return the average of the * that * ****** * and F=0).
}

int * * *
{
* ** ****** * * ** G[100];
*** * *** ** ** ** ** * n;

*** * ** * ** ** YOUR CODE HERE*/
* *** *
* *** int i;
* * char trash;
* *** *** ** * ********* * ** * *
* *** *** * *
** *** ** * * {
*** ** * * * *** * * * * * ***** *** *
**** * *** * **** * * ** * *** * ** * * * *
*** * ** ** * *
      * *
** * * ** *** }
** ****
* * *
* ** * *** *

**** * * * * * * * OF YOUR CODE*/

** * * * * * * ******** *** * * * ***** ** ****** *

*** * ** * ** 0;
}
answered by (-249 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include * * * * *
float * ***** * * n)
{
* *** ** * * ** * *** * * YOUR CODE HERE*/
* * * ******
** * * * * * ** ** * sum=0;
* * * * * ****** ** i;
* * ** ** * ***** ***
***** * * * *
*** * * * * * * ** ** * * ** * * **** * *
*** ** * *** ** * ** ** *** *** {
* *** **** **** * *** ** * * * ** * ** *** ** * * * ** **
**** ** * ** }
* * ** * * * * * **
* * *** *** {
* **       sum=sum+3;
*** ** * }
* *** *** **** * * ** *
** ** * ** ** {
* * *** ** * ***** ** * * *
* ** * * }
* * ** ** ** * ** * ****
* ** * ** {
* *** * * * * **** ** ** sum=sum+1;
* **** * ** }
***   * * * ***
* **   {
** * * *   * * *
** ****** }
* ** **
* * * ** ****
**** *** ** * ** *** * **
* ** ** return sum;
** * *** * * *


** * *** ** ***** ** OF YOUR CODE*/
* * **** ** * function should return the average of the * * that * **** * and F=0).
}

int ** *
{
* ** *** * * ** G[100];
* * *** * *** ** * ** n;

** ** * **** **** * * YOUR CODE HERE*/
** *** * *
* * ** * int i;
** * * * * char trash;
** ** ** * * * ** **** * ** ** ****
**** * ** ** *** * *****
* * * {
***** ** **** * ** * ** * * * * *** ** * ** * * **
* * ** * * * ** ** **** ** ***** * ****
* ** * * ****
******* *** **    
* * ** * }
** ** *** *
* *** * * *
***** * *

* ** ** ** * ***** * ** OF YOUR CODE*/

* * **** * ** * * * *** * * ** * ** * *

** * ****** ** * ** * 0;
}
answered by (-249 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include * *** * * * *
float **** * ** * *** ** n)
{
********* ******* * ** YOUR CODE HERE*/
* * **** * A=4;
* * * *** * *** ** ** B=3;
** ** ** *** * * * C=2;
* ** ** * * * D=1;
*** ***** ** *** * ** F=0;
* ** ** * * ** i;
* * ** * ** sum=0;
* * ** * * * * * * * ****
*** ** *** * * *
* ***** ** ** ***** * * * ** * ***
*** * *** * * * * * * {
* * ** * * ** * * * ***** * * *** * ** **
    }
** * ** *** ***** *
**** * ** * {
* ** * * * *** ** * **** sum+=3;
** * * ** * }
* ** ** * * *
*   {
* *** *** ** * **** * * sum+=2;
* * * ** * }
**** * * *** ****** *
** * *** {
****** * * * ** * *** ** sum+=1;
** * * ** }
****   * * * ***
* ***   {
**** * ** ** * * sum+=0;
**** * * }
** * *** * * sum/=n;
* ** *** *** return sum;
** ** * ** ** *
** * **** * **


**** **** ** *** OF YOUR CODE*/
*** *** *** * function should return the average of the *** ** *** that ** * * ** and F=0).
}

int * ***
{
*** *** ** *** * ** * G[100];
**** ** * * * ** *** n;

* * *** * * ** * * YOUR CODE HERE*/
** ** * **
** * * *** * int i;
* * ***** ** char trash;
* * *** * * ** ** * ** ** *
* ** ** *** * * * *
* *** * * {
* * * * *** * * * * * ** *** **** *** *** *
***** ** * * ** ** **** * * * ** **
* * * * * * * ** **
** * * ** * }
* * * * *
* * * *
***** ** * **

** ******** *** * OF YOUR CODE*/

** * * ** * ** * ** ** **** * **** ** ** * **

**** * **** *** * 0;
}
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include *** * **
float * ** **** ** ** ** n)
{
* * ** **** ** YOUR CODE HERE*/
** * *** * ** * A=4;
**** * * * *** B=3;
** * * * * * * * C=2;
* * * D=1;
****** * ** * *** * * F=0;
**** **** * i;
* *** * **** **** * * sum=0;
* ***** * * * ** ** * * *
**** * ** *
** * ** * *** * * * *** * *
*** *** *** * ** * * * * * **** {
* *** *** * * * * * * *** * **** * ** *** ** ** **
* ** * ***** * }
** ** *** * * * *
* *** * * * * * {
* ****** * * * * sum+=3;
*   }
*** **** * ** * *** **
* * * * ** {
* ** * * **** * * *** * * sum+=2;
* * * * }
**** * ** ***** * * * * **
* * * * ***** {
* * ** * ***   sum+=1;
******** * * * }
* * ** * * * ** * * *
* *** {
* * * *** ***** * ** * sum+=0;
***** ** }
* **** ****** sum/=n;
* * *** * * return sum;
* *** **
* ** ** * * ** *


* ** *** * ***** OF YOUR CODE*/
*** *** * ** * **** * function should return the average of the * * * * that * * ** * and F=0).
}

int *
{
*** *** ** ** * * ** G[100];
* * *** * *** * ** n;

** * *** ****** ** YOUR CODE HERE*/
***** * ****
  * * int i;
* * * *** ** * ** * ***** ** * * *
***   ** *** *******
*** * * * {
* * * *** **** * ** * * ***** * * * *
* ** ** }
* * * * *
*

* * ** *** * OF YOUR CODE*/

*** *** * * ***** * ** * **** * ** ** * * **

*** *** * **** 0;
}
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.64
©2016-2026

Related questions

0 like 0 dislike
38 answers
[Exercise] Coding (C) - asked Dec 13, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 37277 - Available when: 2017-12-14 18:00 - Due to: Unlimited
| 9.8k views
0 like 0 dislike
41 answers
[Exercise] Coding (C) - asked Dec 14, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 37370 - Available when: 2017-12-14 18:00 - Due to: Unlimited
| 9.7k views
0 like 0 dislike
45 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 35784 - Available when: 2017-12-07 18:00 - Due to: Unlimited
| 10.5k views
12,783 questions
183,442 answers
172,219 comments
4,824 users