简 介: 本文测试了在 AI Studio中进行C语言编程的过程。使用与 搭建AI Studio 中Python开发环境 同样的 “AIS” python文件,可以在Windows 与AI Studio之间进行C,Python文件传输、编写与运行。

关键词AI*Studio作业题

#mermaid-svg-YtzPySOoIBPDWo42 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-YtzPySOoIBPDWo42 .error-icon{fill:#552222;}#mermaid-svg-YtzPySOoIBPDWo42 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-YtzPySOoIBPDWo42 .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-YtzPySOoIBPDWo42 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-YtzPySOoIBPDWo42 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-YtzPySOoIBPDWo42 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-YtzPySOoIBPDWo42 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-YtzPySOoIBPDWo42 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-YtzPySOoIBPDWo42 .marker.cross{stroke:#333333;}#mermaid-svg-YtzPySOoIBPDWo42 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-YtzPySOoIBPDWo42 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-YtzPySOoIBPDWo42 .cluster-label text{fill:#333;}#mermaid-svg-YtzPySOoIBPDWo42 .cluster-label span{color:#333;}#mermaid-svg-YtzPySOoIBPDWo42 .label text,#mermaid-svg-YtzPySOoIBPDWo42 span{fill:#333;color:#333;}#mermaid-svg-YtzPySOoIBPDWo42 .node rect,#mermaid-svg-YtzPySOoIBPDWo42 .node circle,#mermaid-svg-YtzPySOoIBPDWo42 .node ellipse,#mermaid-svg-YtzPySOoIBPDWo42 .node polygon,#mermaid-svg-YtzPySOoIBPDWo42 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-YtzPySOoIBPDWo42 .node .label{text-align:center;}#mermaid-svg-YtzPySOoIBPDWo42 .node.clickable{cursor:pointer;}#mermaid-svg-YtzPySOoIBPDWo42 .arrowheadPath{fill:#333333;}#mermaid-svg-YtzPySOoIBPDWo42 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-YtzPySOoIBPDWo42 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-YtzPySOoIBPDWo42 .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-YtzPySOoIBPDWo42 .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-YtzPySOoIBPDWo42 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-YtzPySOoIBPDWo42 .cluster text{fill:#333;}#mermaid-svg-YtzPySOoIBPDWo42 .cluster span{color:#333;}#mermaid-svg-YtzPySOoIBPDWo42 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-YtzPySOoIBPDWo42 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}

问题来源
目 录
Contents
题目要求
作业分析
程序要求
产生学生成
绩单CSV文件
C语言程序
程序代码
运行结果
总 结
程序改进

§01 问题来源


  我是名大二的学生,这边有问题,有个简单编程作业想问下你,价钱好说 :

一、题目要求

1、成绩处理

▲ 图1.1 作业要求

▲ 图1.2 作业要求

2、结果要求

  c语言,文件没啥要求,有程序代码就行了。

  类似于这种:

▲ 图1.1.3 作业结果要求

3、提交时间

  明天就要交了,麻烦你了

§02 作业分析


一、程序要求

1、编程语言

  编程语言是C语言。可以看到这是一个大学一年级 C语言课程的作业题目;

2、编程环境

  前面同学显示的变换环境为 VS。

  因此只要是基本的C语言,他都可以进行调试。

3、程序输入、输出

(1)程序输入

  程序中没有给出学生的成绩表格的要求。因此可以采用最简单的 CSV 格式来表示学生的成绩。

  • 每一行表示一个学生的信息。有两个字段:学号成绩;
  • 学号采用字符串:“202109nnn”,其中nnn从 101 ~ 299,表示由199 位同学;
  • 成绩采用浮点数: nn.m: 采用平均值为85,方差为30的正态分布;

(2)程序的输出

  可以看到只需要屏幕输出即可。

二、产生学生成绩单CSV文件

  使用AI Studio的终端环境,通过Python语言产生。由于这只是用于测试主程序,所以使用Python语言产生。

1、Python代码

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# SCORESVS.PY                  -- by Dr. ZhuoQing 2021-12-08
#
# Note:
#============================================================
from headm import *
from numpy import *
outfilename = 'score.txt'
student_number = 199
score_average = 85
score_variance = 35
score = random.normal(score_average,score_variance,student_number)
score = [s if s < 100 else 99 for s in score]
score = [s if s > 0 else 0 for s in score]
score = [floor(s*10)/10 for s in score]
with open(outfilename, 'w') as f:for i in range(student_number):student_id = '202109%03d'%(101+i)f.write('%s,%3.1f\n'%(student_id, score[i]))
printf(score)
plt.hist(score)
plt.xlabel("分数段")
plt.ylabel("人数")
plt.title('成绩分布')
plt.grid(True)
plt.tight_layout()
plt.show()
#------------------------------------------------------------
#        END OF FILE : SCORESVS.PY
#============================================================

2、结果:

(1)成绩数值

[99.0, 13.5, 99.0, 45.7, 99.0, 88.5, 99.0, 99.0, 93.1, 99.0, 66.9, 99.0, 99.0, 35.2, 95.3, 95.5, 92.9, 0.0, 74.8, 99.0, 99.0, 88.6, 76.4, 99.0, 99.0, 89.9, 99.0, 78.5, 40.2, 99.0, 77.2, 40.4, 99.0, 69.4, 50.1, 74.2, 99.0, 99.0, 98.2, 82.3, 99.0, 32.1, 99.0, 92.5, 99.0, 55.0, 99.0, 75.5, 74.2, 24.4, 71.7, 0.0, 47.3, 34.7, 96.2, 99.0, 93.6, 52.3, 99.0, 87.9, 87.7, 96.3, 29.1, 99.0, 99.0, 56.4, 58.3, 99.0, 51.6, 27.0, 54.7, 99.0, 36.6, 97.0, 34.4, 29.4, 83.5, 27.9, 99.0, 99.0, 99.0, 55.2, 96.0, 45.7, 97.8, 3.8, 22.6, 89.0, 90.8, 99.0, 99.0, 99.0, 92.9, 99.0, 64.6, 99.0, 75.3, 60.8, 93.2, 40.2, 99.0, 89.2, 56.4, 93.7, 80.1, 87.9, 85.0, 99.0, 72.6, 69.6, 49.7, 80.8, 55.9, 48.3, 67.3, 22.7, 41.6, 45.4, 99.0, 99.0, 72.3, 99.0, 72.5, 49.5, 82.5, 99.0, 92.2, 49.3, 79.1, 99.0, 44.9, 99.0, 99.0, 88.0, 47.4, 99.0, 57.1, 50.6, 99.0, 49.3, 68.7, 99.0, 99.0, 58.3, 99.0, 53.7, 93.5, 48.4, 99.0, 44.3, 15.9, 70.0, 71.2, 99.0, 65.5, 55.9, 99.0, 92.4, 99.0, 87.7, 99.9, 99.0, 81.8, 82.1, 68.2, 99.0, 71.7, 97.2, 66.8, 67.7, 98.1, 99.0, 99.0, 83.2, 99.0, 57.9, 65.2, 99.0, 99.0, 78.3, 99.0, 29.9, 69.4, 47.4, 94.3, 52.4, 67.8, 99.0, 62.4, 99.0, 81.3, 25.1, 85.7, 99.0, 99.0, 99.0, 99.0, 80.5, 75.7]

(2)成绩分布

▲ 图2.2.1 成绩分布

(3)打开score.txt中的内容

▲ 图2.2.2 成绩CSV格式

§03 C语言程序


  下面编写作业所需要的C语言程序。

一、程序代码

1、C文件

/*
**==============================================================================
** SCORESTA.C:             -- by Dr. ZhuoQing, 2021-12-08
**
**==============================================================================
*///------------------------------------------------------------------------------
#define SCORESTA_GLOBALS        1              // Define the global variables
#include "SCORESTA.H"
#include "stdio.h"
#include "string.h"//------------------------------------------------------------------------------
#define LINE_LENGTH             0x1000
#define MAX_STUDENT             0x1000
#define STUDENT_ID_LENGTH       0x20//------------------------------------------------------------------------------
char g_szStudentID[MAX_STUDENT][STUDENT_ID_LENGTH];
float g_fStudentScore[MAX_STUDENT];
int g_nStudentNumber;int SegmentInfor(float fBegin, float fEnd) { // Show every segment student inforint nNumber = 0;int i;for(i = 0; i < g_nStudentNumber; i ++) {if(g_fStudentScore[i] >= fBegin && g_fStudentScore[i] < fEnd) {nNumber ++;}}if(fBegin >= 60) {printf("%d - %d 分数的人数为:%d。他们的学号、成绩为:\n", (int)fBegin, (int)fEnd, nNumber);} else {printf("不及格的人数为:%d。他们的学号、成绩为:\n", nNumber);}nNumber = 0;for(i = 0; i < g_nStudentNumber; i ++) {if(g_fStudentScore[i] >= fBegin && g_fStudentScore[i] < fEnd) {nNumber ++;printf("%02d. %s, %3.1f\n", nNumber, g_szStudentID[i], g_fStudentScore[i]);}}printf("\n");return 0;}//------------------------------------------------------------------------------
int main(void) {FILE * pInputFile;char szLine[LINE_LENGTH];int nStudentNumber;//--------------------------------------------------------------------------// Open the score file.//pInputFile = fopen(SCORE_FILE_NAME, "r");if(pInputFile == (FILE *)NULL) {printf("ERROR: Can not open the score file !");printf("Notes: Score file is score.txt.");return 0;}//--------------------------------------------------------------------------// Read the student score//nStudentNumber = 0;while(!feof(pInputFile)) {fgets(szLine, LINE_LENGTH - 1, pInputFile);if(!feof(pInputFile)) {//            printf("%s", szLine);char * p = strchr(szLine, ',');if(p != (char *)NULL) {*(p) = 0;strcpy(g_szStudentID[nStudentNumber], szLine);sscanf(p + 1, "%f", &g_fStudentScore[nStudentNumber]);nStudentNumber ++;if(nStudentNumber >= MAX_STUDENT) {break;}}}}fclose(pInputFile);printf("Total student number: %d.\n", nStudentNumber);g_nStudentNumber = nStudentNumber;//----------------------------------------------------------------------    // Sort student scoreint i, j, k;for(i = 1; i < nStudentNumber; i ++) {for(j = 0; j < i; j ++) {if(g_fStudentScore[j] < g_fStudentScore[i]) {float fTemp = g_fStudentScore[i];char szTemp[STUDENT_ID_LENGTH];strcpy(szTemp, g_szStudentID[i]);for(k = i; k > j; k --) {g_fStudentScore[k] = g_fStudentScore[k-1];strcpy(g_szStudentID[k], g_szStudentID[k-1]);}g_fStudentScore[j] = fTemp;strcpy(g_szStudentID[j], szTemp);break;}}}//----------------------------------------------------------------------    // Output the statistic result//SegmentInfor(90, 100);SegmentInfor(80, 89.9);SegmentInfor(70, 79.9);SegmentInfor(60, 69.9);SegmentInfor(0, 59.9);//--------------------------------------------------------------------------float fSigma = 0;for(i = 0 ; i < nStudentNumber; i ++)fSigma += g_fStudentScore[i];float fAverage = fSigma / nStudentNumber;printf("\n全班平均程序:%3.2f 分, 总分: %3.2f\n", fAverage, fSigma);//--------------------------------------------------------------------------// Display all the students inforprintf("\n全班学生排名,从高到低:\n");for(i = 0; i < nStudentNumber; i ++)printf("%s %3.2f\n", g_szStudentID[i], g_fStudentScore[i]);//----------------------------------------------------------------------    // Display top 3 students inforprintf("\n前三名同学成绩:\n");for(i = 0; i < 3; i ++) printf("%s %3.2f\n", g_szStudentID[i], g_fStudentScore[i]);//--------------------------------------------------------------------------// Display last 3 students inforprintf("\n最后三名同学成绩:\n");for(i = 0; i < 3; i ++) printf("%s %3.2f\n", g_szStudentID[nStudentNumber - 1 - i], g_fStudentScore[nStudentNumber - 1 - i]);printf("\n");
}//==============================================================================
//                END OF FILE : SCORESTA.C
//------------------------------------------------------------------------------

2、头文件

/*
**==============================================================================
** SCORESTA.H:            -- by Dr. ZhuoQing, 2021-12-08
**
**  Description:
**
**==============================================================================
*/
#ifndef __SCORESTA__
#define __SCORESTA__
//------------------------------------------------------------------------------
#ifdef SCORESTA_GLOBALS#define SCORESTA_EXT
#else#define SCORESTA_EXT extern
#endif // SCORESTA_GLOBALS
//------------------------------------------------------------------------------
//==============================================================================//------------------------------------------------------------------------------
#define SCORE_FILE_NAME  "score.txt"//==============================================================================
//             END OF FILE : SCORESTA.H
//------------------------------------------------------------------------------
#endif // __SCORESTA__

二、运行结果

  使用如下命名,将程序运行结果存储在 result.txt文件中。

aistudio@jupyter-262579-3200047:~$ ./scoresta >result.txt

1、运行结果

Total student number: 199.
90 - 100 分数的人数为:80。他们的学号、成绩为:
01. 202109287, 99.5
02. 202109107, 99.0
03. 202109109, 99.0
04. 202109113, 99.0
05. 202109116, 99.0
06. 202109117, 99.0
07. 202109118, 99.0
08. 202109127, 99.0
09. 202109131, 99.0
10. 202109132, 99.0
11. 202109136, 99.0
12. 202109138, 99.0
13. 202109145, 99.0
14. 202109147, 99.0
15. 202109149, 99.0
16. 202109150, 99.0
17. 202109151, 99.0
18. 202109160, 99.0
19. 202109161, 99.0
20. 202109163, 99.0
21. 202109164, 99.0
22. 202109166, 99.0
23. 202109168, 99.0
24. 202109169, 99.0
25. 202109176, 99.0
26. 202109178, 99.0
27. 202109179, 99.0
28. 202109188, 99.0
29. 202109191, 99.0
30. 202109201, 99.0
31. 202109204, 99.0
32. 202109206, 99.0
33. 202109207, 99.0
34. 202109210, 99.0
35. 202109215, 99.0
36. 202109220, 99.0
37. 202109221, 99.0
38. 202109222, 99.0
39. 202109230, 99.0
40. 202109235, 99.0
41. 202109237, 99.0
42. 202109239, 99.0
43. 202109243, 99.0
44. 202109244, 99.0
45. 202109245, 99.0
46. 202109246, 99.0
47. 202109247, 99.0
48. 202109248, 99.0
49. 202109251, 99.0
50. 202109256, 99.0
51. 202109257, 99.0
52. 202109259, 99.0
53. 202109261, 99.0
54. 202109264, 99.0
55. 202109265, 99.0
56. 202109268, 99.0
57. 202109270, 99.0
58. 202109274, 99.0
59. 202109275, 99.0
60. 202109281, 99.0
61. 202109283, 99.0
62. 202109284, 99.0
63. 202109286, 99.0
64. 202109288, 99.0
65. 202109293, 99.0
66. 202109296, 99.0
67. 202109299, 99.0
68. 202109158, 98.7
69. 202109135, 96.3
70. 202109146, 96.3
71. 202109238, 95.8
72. 202109125, 95.2
73. 202109143, 94.6
74. 202109106, 93.6
75. 202109140, 93.5
76. 202109159, 93.1
77. 202109123, 92.7
78. 202109139, 92.3
79. 202109195, 90.9
80. 202109110, 90.480 - 89 分数的人数为:19。他们的学号、成绩为:
01. 202109266, 89.3
02. 202109234, 88.4
03. 202109223, 88.2
04. 202109203, 88.1
05. 202109209, 87.5
06. 202109252, 87.3
07. 202109102, 87.2
08. 202109165, 87.2
09. 202109122, 86.5
10. 202109297, 86.0
11. 202109285, 85.4
12. 202109108, 84.7
13. 202109185, 84.2
14. 202109170, 84.1
15. 202109208, 83.9
16. 202109260, 83.7
17. 202109184, 82.5
18. 202109294, 81.4
19. 202109232, 81.170 - 79 分数的人数为:22。他们的学号、成绩为:
01. 202109229, 79.5
02. 202109119, 79.0
03. 202109172, 79.0
04. 202109152, 78.5
05. 202109217, 78.2
06. 202109273, 77.5
07. 202109269, 77.4
08. 202109278, 77.4
09. 202109190, 77.2
10. 202109157, 76.7
11. 202109193, 76.3
12. 202109226, 75.8
13. 202109295, 75.4
14. 202109148, 75.2
15. 202109292, 75.2
16. 202109291, 75.0
17. 202109279, 74.9
18. 202109298, 74.6
19. 202109153, 74.4
20. 202109241, 72.1
21. 202109111, 70.6
22. 202109196, 70.660 - 69 分数的人数为:22。他们的学号、成绩为:
01. 202109197, 69.8
02. 202109173, 69.2
03. 202109263, 67.9
04. 202109224, 65.9
05. 202109280, 65.8
06. 202109182, 64.9
07. 202109282, 64.5
08. 202109240, 64.4
09. 202109250, 64.0
10. 202109289, 63.4
11. 202109192, 63.0
12. 202109167, 62.8
13. 202109242, 62.7
14. 202109103, 62.4
15. 202109128, 62.1
16. 202109211, 61.5
17. 202109144, 61.4
18. 202109276, 61.4
19. 202109171, 60.9
20. 202109267, 60.8
21. 202109177, 60.7
22. 202109290, 60.5不及格的人数为:55。他们的学号、成绩为:
01. 202109129, 59.8
02. 202109212, 59.5
03. 202109219, 59.0
04. 202109155, 58.6
05. 202109183, 57.7
06. 202109162, 57.6
07. 202109112, 57.2
08. 202109156, 55.6
09. 202109121, 55.3
10. 202109205, 52.3
11. 202109272, 51.9
12. 202109271, 51.7
13. 202109120, 50.0
14. 202109104, 49.9
15. 202109258, 49.4
16. 202109213, 49.3
17. 202109187, 49.2
18. 202109199, 48.9
19. 202109194, 48.1
20. 202109180, 48.0
21. 202109225, 48.0
22. 202109227, 47.9
23. 202109255, 47.4
24. 202109130, 47.2
25. 202109154, 47.0
26. 202109142, 46.2
27. 202109253, 45.1
28. 202109133, 44.6
29. 202109233, 44.3
30. 202109262, 43.7
31. 202109214, 42.7
32. 202109115, 42.5
33. 202109137, 40.1
34. 202109114, 39.7
35. 202109126, 36.0
36. 202109134, 33.2
37. 202109174, 33.0
38. 202109200, 32.7
39. 202109202, 29.7
40. 202109101, 28.3
41. 202109249, 24.5
42. 202109236, 22.3
43. 202109141, 22.0
44. 202109186, 21.4
45. 202109124, 21.1
46. 202109105, 20.8
47. 202109218, 17.4
48. 202109254, 16.0
49. 202109175, 15.3
50. 202109181, 12.6
51. 202109198, 10.2
52. 202109228, 2.6
53. 202109189, 2.0
54. 202109216, 1.1
55. 202109277, 0.0全班平均程序:74.03 分, 总分: 14731.60全班学生排名,从高到低:
202109287 99.50
202109107 99.00
202109109 99.00
202109113 99.00
202109116 99.00
202109117 99.00
202109118 99.00
202109127 99.00
202109131 99.00
202109132 99.00
202109136 99.00
202109138 99.00
202109145 99.00
202109147 99.00
202109149 99.00
202109150 99.00
202109151 99.00
202109160 99.00
202109161 99.00
202109163 99.00
202109164 99.00
202109166 99.00
202109168 99.00
202109169 99.00
202109176 99.00
202109178 99.00
202109179 99.00
202109188 99.00
202109191 99.00
202109201 99.00
202109204 99.00
202109206 99.00
202109207 99.00
202109210 99.00
202109215 99.00
202109220 99.00
202109221 99.00
202109222 99.00
202109230 99.00
202109235 99.00
202109237 99.00
202109239 99.00
202109243 99.00
202109244 99.00
202109245 99.00
202109246 99.00
202109247 99.00
202109248 99.00
202109251 99.00
202109256 99.00
202109257 99.00
202109259 99.00
202109261 99.00
202109264 99.00
202109265 99.00
202109268 99.00
202109270 99.00
202109274 99.00
202109275 99.00
202109281 99.00
202109283 99.00
202109284 99.00
202109286 99.00
202109288 99.00
202109293 99.00
202109296 99.00
202109299 99.00
202109158 98.70
202109135 96.30
202109146 96.30
202109238 95.80
202109125 95.20
202109143 94.60
202109106 93.60
202109140 93.50
202109159 93.10
202109123 92.70
202109139 92.30
202109195 90.90
202109110 90.40
202109266 89.30
202109234 88.40
202109223 88.20
202109203 88.10
202109209 87.50
202109252 87.30
202109102 87.20
202109165 87.20
202109122 86.50
202109297 86.00
202109285 85.40
202109108 84.70
202109185 84.20
202109170 84.10
202109208 83.90
202109260 83.70
202109184 82.50
202109294 81.40
202109232 81.10
202109231 79.90
202109229 79.50
202109119 79.00
202109172 79.00
202109152 78.50
202109217 78.20
202109273 77.50
202109269 77.40
202109278 77.40
202109190 77.20
202109157 76.70
202109193 76.30
202109226 75.80
202109295 75.40
202109148 75.20
202109292 75.20
202109291 75.00
202109279 74.90
202109298 74.60
202109153 74.40
202109241 72.10
202109111 70.60
202109196 70.60
202109197 69.80
202109173 69.20
202109263 67.90
202109224 65.90
202109280 65.80
202109182 64.90
202109282 64.50
202109240 64.40
202109250 64.00
202109289 63.40
202109192 63.00
202109167 62.80
202109242 62.70
202109103 62.40
202109128 62.10
202109211 61.50
202109144 61.40
202109276 61.40
202109171 60.90
202109267 60.80
202109177 60.70
202109290 60.50
202109129 59.80
202109212 59.50
202109219 59.00
202109155 58.60
202109183 57.70
202109162 57.60
202109112 57.20
202109156 55.60
202109121 55.30
202109205 52.30
202109272 51.90
202109271 51.70
202109120 50.00
202109104 49.90
202109258 49.40
202109213 49.30
202109187 49.20
202109199 48.90
202109194 48.10
202109180 48.00
202109225 48.00
202109227 47.90
202109255 47.40
202109130 47.20
202109154 47.00
202109142 46.20
202109253 45.10
202109133 44.60
202109233 44.30
202109262 43.70
202109214 42.70
202109115 42.50
202109137 40.10
202109114 39.70
202109126 36.00
202109134 33.20
202109174 33.00
202109200 32.70
202109202 29.70
202109101 28.30
202109249 24.50
202109236 22.30
202109141 22.00
202109186 21.40
202109124 21.10
202109105 20.80
202109218 17.40
202109254 16.00
202109175 15.30
202109181 12.60
202109198 10.20
202109228 2.60
202109189 2.00
202109216 1.10
202109277 0.00前三名同学成绩:
202109287 99.50
202109107 99.00
202109109 99.00最后三名同学成绩:
202109277 0.00
202109216 1.10
202109189 2.00

※ 总  结 ※


  本文测试了在 AI Studio中进行C语言编程的过程。使用与 搭建AI Studio 中Python开发环境 同样的 “AIS” python文件,可以在Windows 与AI Studio之间进行C,Python文件传输、编写与运行。

一、程序改进

  在前面产生学生成绩分布的时候,由于对于超过100之后的分数都设定为99分,造成成绩几种在99分的比较严重,下面对于产生测试学生成绩的Python做些改动。

1、改动后的Python程序

from headm import *
from numpy import *outfilename = 'score.txt'student_number = 199
score_average = 85
score_variance = 15score = random.normal(score_average,score_variance,student_number)score = [s if s < 100 else 100-s/5 for s in score]
score = [s if s > 0 else 0 for s in score]
score = [floor(s*10)/10 for s in score]with open(outfilename, 'w') as f:for i in range(student_number):student_id = '202109%03d'%(101+i)f.write('%s,%3.1f\n'%(student_id, score[i]))printf(score)
plt.hist(score)
plt.xlabel("分数段")
plt.ylabel("人数")
plt.title('成绩分布')
plt.grid(True)
plt.tight_layout()
plt.show()

2、成绩分布

▲ 图4.1 产生的成绩分布

3、C语言结果

  在这组数据下,对应的运行结果还算是看得上眼。

Total student number: 199.
90 - 100 分数的人数为:37。他们的学号、成绩为:
01. 202109261, 99.3
02. 202109130, 99.0
03. 202109141, 99.0
04. 202109228, 98.9
05. 202109201, 98.8
06. 202109207, 98.6
07. 202109202, 98.5
08. 202109269, 98.3
09. 202109199, 96.6
10. 202109258, 96.2
11. 202109249, 96.1
12. 202109118, 96.0
13. 202109296, 95.9
14. 202109126, 95.8
15. 202109243, 95.7
16. 202109186, 94.8
17. 202109293, 94.6
18. 202109103, 94.3
19. 202109280, 93.8
20. 202109218, 93.6
21. 202109256, 93.6
22. 202109164, 93.3
23. 202109125, 93.2
24. 202109159, 93.2
25. 202109116, 92.8
26. 202109294, 92.8
27. 202109174, 92.5
28. 202109183, 92.5
29. 202109132, 92.3
30. 202109291, 91.7
31. 202109122, 91.6
32. 202109177, 91.5
33. 202109180, 90.6
34. 202109255, 90.6
35. 202109234, 90.4
36. 202109176, 90.1
37. 202109211, 90.080 - 89 分数的人数为:51。他们的学号、成绩为:
01. 202109253, 89.7
02. 202109298, 89.7
03. 202109244, 89.6
04. 202109204, 89.5
05. 202109136, 89.1
06. 202109227, 89.1
07. 202109153, 88.9
08. 202109169, 88.9
09. 202109172, 88.7
10. 202109271, 88.2
11. 202109257, 88.1
12. 202109154, 88.0
13. 202109187, 88.0
14. 202109268, 87.6
15. 202109286, 87.5
16. 202109115, 87.2
17. 202109292, 87.1
18. 202109223, 87.0
19. 202109220, 86.7
20. 202109112, 86.4
21. 202109168, 86.3
22. 202109235, 85.7
23. 202109150, 85.6
24. 202109178, 85.5
25. 202109239, 85.2
26. 202109209, 84.4
27. 202109276, 84.4
28. 202109252, 84.3
29. 202109120, 84.2
30. 202109146, 84.0
31. 202109275, 83.9
32. 202109127, 83.6
33. 202109212, 83.6
34. 202109208, 83.4
35. 202109144, 83.3
36. 202109270, 83.3
37. 202109282, 83.2
38. 202109238, 82.8
39. 202109194, 82.5
40. 202109205, 82.2
41. 202109189, 82.0
42. 202109131, 81.8
43. 202109272, 81.5
44. 202109279, 81.5
45. 202109162, 81.2
46. 202109274, 81.2
47. 202109278, 81.2
48. 202109108, 80.8
49. 202109232, 80.7
50. 202109229, 80.5
51. 202109107, 80.270 - 79 分数的人数为:76。他们的学号、成绩为:
01. 202109109, 79.7
02. 202109151, 79.7
03. 202109182, 79.7
04. 202109254, 79.7
05. 202109157, 79.6
06. 202109236, 79.6
07. 202109214, 79.5
08. 202109173, 79.4
09. 202109231, 79.4
10. 202109110, 79.2
11. 202109111, 79.2
12. 202109117, 79.2
13. 202109135, 79.2
14. 202109139, 79.2
15. 202109288, 79.2
16. 202109124, 79.1
17. 202109161, 79.1
18. 202109105, 79.0
19. 202109226, 79.0
20. 202109266, 79.0
21. 202109295, 79.0
22. 202109129, 78.9
23. 202109262, 78.9
24. 202109290, 78.9
25. 202109137, 78.8
26. 202109140, 78.8
27. 202109203, 78.8
28. 202109221, 78.7
29. 202109192, 78.6
30. 202109123, 78.4
31. 202109233, 78.3
32. 202109101, 78.2
33. 202109246, 78.1
34. 202109196, 78.0
35. 202109289, 77.9
36. 202109160, 77.8
37. 202109171, 77.7
38. 202109200, 77.7
39. 202109104, 77.5
40. 202109241, 77.5
41. 202109152, 77.3
42. 202109167, 77.3
43. 202109237, 77.2
44. 202109175, 76.7
45. 202109283, 76.7
46. 202109147, 76.4
47. 202109260, 76.4
48. 202109287, 76.4
49. 202109106, 76.2
50. 202109191, 76.2
51. 202109193, 76.1
52. 202109197, 76.1
53. 202109217, 76.1
54. 202109195, 76.0
55. 202109102, 75.9
56. 202109181, 75.9
57. 202109264, 75.5
58. 202109158, 75.2
59. 202109149, 75.0
60. 202109143, 74.9
61. 202109179, 74.4
62. 202109188, 74.3
63. 202109267, 74.0
64. 202109119, 73.4
65. 202109145, 73.2
66. 202109185, 72.6
67. 202109263, 72.4
68. 202109210, 72.1
69. 202109225, 71.7
70. 202109265, 71.3
71. 202109284, 71.0
72. 202109299, 71.0
73. 202109222, 70.9
74. 202109133, 70.4
75. 202109215, 70.2
76. 202109163, 70.160 - 69 分数的人数为:27。他们的学号、成绩为:
01. 202109219, 69.6
02. 202109273, 69.6
03. 202109213, 68.1
04. 202109230, 67.9
05. 202109142, 67.7
06. 202109138, 67.4
07. 202109166, 67.3
08. 202109247, 67.0
09. 202109277, 67.0
10. 202109216, 66.5
11. 202109148, 66.4
12. 202109251, 66.4
13. 202109184, 66.2
14. 202109206, 66.2
15. 202109297, 66.1
16. 202109259, 65.9
17. 202109285, 65.7
18. 202109155, 65.5
19. 202109128, 64.9
20. 202109240, 64.8
21. 202109224, 64.6
22. 202109242, 64.1
23. 202109248, 63.6
24. 202109281, 62.7
25. 202109250, 62.4
26. 202109114, 62.2
27. 202109190, 61.8不及格的人数为:7。他们的学号、成绩为:
01. 202109121, 57.9
02. 202109170, 57.9
03. 202109156, 56.5
04. 202109165, 56.5
05. 202109134, 55.3
06. 202109198, 52.0
07. 202109245, 48.6全班平均程序:79.89 分, 总分: 15897.41全班学生排名,从高到低:
202109261 99.30
202109130 99.00
202109141 99.00
202109228 98.90
202109201 98.80
202109207 98.60
202109202 98.50
202109269 98.30
202109199 96.60
202109258 96.20
202109249 96.10
202109118 96.00
202109296 95.90
202109126 95.80
202109243 95.70
202109186 94.80
202109293 94.60
202109103 94.30
202109280 93.80
202109218 93.60
202109256 93.60
202109164 93.30
202109125 93.20
202109159 93.20
202109116 92.80
202109294 92.80
202109174 92.50
202109183 92.50
202109132 92.30
202109291 91.70
202109122 91.60
202109177 91.50
202109180 90.60
202109255 90.60
202109234 90.40
202109176 90.10
202109211 90.00
202109253 89.70
202109298 89.70
202109244 89.60
202109204 89.50
202109136 89.10
202109227 89.10
202109153 88.90
202109169 88.90
202109172 88.70
202109271 88.20
202109257 88.10
202109154 88.00
202109187 88.00
202109268 87.60
202109286 87.50
202109115 87.20
202109292 87.10
202109223 87.00
202109220 86.70
202109112 86.40
202109168 86.30
202109235 85.70
202109150 85.60
202109178 85.50
202109239 85.20
202109209 84.40
202109276 84.40
202109252 84.30
202109120 84.20
202109146 84.00
202109275 83.90
202109127 83.60
202109212 83.60
202109208 83.40
202109144 83.30
202109270 83.30
202109282 83.20
202109238 82.80
202109194 82.50
202109205 82.20
202109189 82.00
202109131 81.80
202109272 81.50
202109279 81.50
202109162 81.20
202109274 81.20
202109278 81.20
202109108 80.80
202109232 80.70
202109229 80.50
202109107 80.20
202109109 79.70
202109151 79.70
202109182 79.70
202109254 79.70
202109157 79.60
202109236 79.60
202109214 79.50
202109173 79.40
202109231 79.40
202109110 79.20
202109111 79.20
202109117 79.20
202109135 79.20
202109139 79.20
202109288 79.20
202109124 79.10
202109161 79.10
202109105 79.00
202109226 79.00
202109266 79.00
202109295 79.00
202109129 78.90
202109262 78.90
202109290 78.90
202109137 78.80
202109140 78.80
202109203 78.80
202109221 78.70
202109192 78.60
202109123 78.40
202109233 78.30
202109101 78.20
202109246 78.10
202109196 78.00
202109289 77.90
202109160 77.80
202109171 77.70
202109200 77.70
202109104 77.50
202109241 77.50
202109152 77.30
202109167 77.30
202109237 77.20
202109175 76.70
202109283 76.70
202109147 76.40
202109260 76.40
202109287 76.40
202109106 76.20
202109191 76.20
202109193 76.10
202109197 76.10
202109217 76.10
202109195 76.00
202109102 75.90
202109181 75.90
202109264 75.50
202109158 75.20
202109149 75.00
202109143 74.90
202109179 74.40
202109188 74.30
202109267 74.00
202109119 73.40
202109145 73.20
202109185 72.60
202109263 72.40
202109210 72.10
202109225 71.70
202109265 71.30
202109284 71.00
202109299 71.00
202109222 70.90
202109133 70.40
202109215 70.20
202109163 70.10
202109113 69.90
202109219 69.60
202109273 69.60
202109213 68.10
202109230 67.90
202109142 67.70
202109138 67.40
202109166 67.30
202109247 67.00
202109277 67.00
202109216 66.50
202109148 66.40
202109251 66.40
202109184 66.20
202109206 66.20
202109297 66.10
202109259 65.90
202109285 65.70
202109155 65.50
202109128 64.90
202109240 64.80
202109224 64.60
202109242 64.10
202109248 63.60
202109281 62.70
202109250 62.40
202109114 62.20
202109190 61.80
202109121 57.90
202109170 57.90
202109156 56.50
202109165 56.50
202109134 55.30
202109198 52.00
202109245 48.60前三名同学成绩:
202109261 99.30
202109130 99.00
202109141 99.00最后三名同学成绩:
202109245 48.60
202109198 52.00
202109134 55.30

■ 相关文献链接:

  • CSV
  • 搭建AI Studio 中Python开发环境

● 相关图表链接:

  • 图1.1 作业要求
  • 图1.2 作业要求
  • 图1.1.3 作业结果要求
  • 图2.2.1 成绩分布
  • 图2.2.2 成绩CSV格式
  • 图4.1 产生的成绩分布

AI Studio下C语言编程:一道简单的C语言作业题目相关推荐

  1. 海伦公C语言表达式,一道简单的C语言海伦公式问题

    2017-12-23 错误信息: http://www.043198.cn/debug1.jpg var hello="fff"; var world="fff" ...

  2. c语言编程期刊论文管理系统,C语言编程下计算机软件论文

    1计算机软件C语言的编程实验 1.1计算机软件C语言的编程技巧 计算机软件C语言的编程中,最主要的依据是指针应用,C语言指针能够根据软件程序的编写需求,构建可行的函数,而程序员在设计函数编程的过程中, ...

  3. c语言程序设计需要学多久,九江c语言编程学习,九江学c语言编程报班,九江学c语言编程一般要多久才能学会...

    九江c语言编程学习,九江学c语言编程报班,九江学c语言编程一般要多久才能学会 首页 > C语言 > 九江c语言编程学习 作者:镀金池   发布时间:2017-10-18 14:11 据ID ...

  4. C语言报名里面培训怎么填,庄河c语言编程学习,庄河学c语言编程培训,庄河学c语言编程报个培训班怎么样...

    庄河c语言编程学习,庄河学c语言编程培训,庄河学c语言编程报个培训班怎么样 首页 > 软件 > 庄河c语言编程学习 作者:镀金池   发布时间:2017-11-29 11:13 明天利用时 ...

  5. 罗定c语言,罗定学c语言编程,罗定学c语言编程培训,罗定学c语言编程一般怎么收费...

    罗定学c语言编程,罗定学c语言编程培训,罗定学c语言编程一般怎么收费 首页 > 软件 > 罗定学c语言编程 作者:镀金池   发布时间:2018-10-04 23:40 依照c语言的法则, ...

  6. 安庆师范大学c语言程序设计,安庆c语言编程学习,安庆学c语言编程培训,安庆学c语言编程一般能拿多少工资...

    安庆c语言编程学习,安庆学c语言编程培训,安庆学c语言编程一般能拿多少工资 首页 > C语言 > 安庆c语言编程学习 作者:镀金池   发布时间:2017-10-18 15:20 假定我们 ...

  7. 高斯消元法的c语言编程,列主元高斯消元法的C语言编程

    列主元高斯消元法的C语言编程 列主元高斯消元法 基本思想:用高斯消元法求解线性方程组时,为避免小的主元,在进行第k步消元前,应该在第k列(k)元素aik(i k,(k)(k)例如|aikk| max| ...

  8. c语言程序设计自学跟谁好,双辽c语言编程学习,双辽学c语言编程哪个好,双辽学c语言编程自学好还是报班好...

    双辽c语言编程学习,双辽学c语言编程哪个好,双辽学c语言编程自学好还是报班好 首页 > 软件 > 双辽c语言编程学习 作者:镀金池   发布时间:2017-12-07 05:48 一个C语 ...

  9. c语言编程学多久,丰城c语言编程学习,丰城学c语言编程的学校,丰城学c语言编程一般要多久才能学会...

    丰城c语言编程学习,丰城学c语言编程的学校,丰城学c语言编程一般要多久才能学会 首页 > 软件 > 丰城c语言编程学习 作者:镀金池   发布时间:2018-04-09 16:40 在之后 ...

  10. 江门C语言培训,江门c语言编程学习,江门学c语言编程培训,江门学c语言编程效果怎么样...

    江门c语言编程学习,江门学c语言编程培训,江门学c语言编程效果怎么样 首页 > C语言 > 江门c语言编程学习 作者:镀金池   发布时间:2017-10-18 09:25 在初期的C语言 ...

最新文章

  1. php类方法语法错误捕获,php语法错误捕获
  2. linux-security-limits
  3. C指针原理(29)-Ncurses-文本终端的图形
  4. 动态数组,数组初始化,数组内存释放,向数组中添加一个元素,向数组中添加多个元素,数组打印,顺序查找,二分查找,查找数组并返回地址,冒泡排序,改变数组中某个元素的值,删除一个数值,删除所有,查找含有
  5. 【汇编】汇编学习入门-系列更新20180705
  6. base64转图片_从一道面试题说起:GET 请求能传图片吗?
  7. 个人代码库のC#可移动按钮“相关代码”
  8. 首届Ceph亚太峰会来了!内有粉丝福利
  9. Dojo笔记(较旧)
  10. 一个特别NB的技术网站
  11. 写DM9000网卡芯片驱动的预备知识
  12. 老打印机USB改无线连接
  13. 小型软件企业组织结构
  14. C语言怎么提出大写字母,c语言函数toupper()如何将小写字母转换为大写字母
  15. Java中按字母顺序对字符串字符进行排序的4种不同方法
  16. 《Python神经网络编程(Make Your Own Neural Network)》读书笔记
  17. Linux 中CPU占用过高问题
  18. UNIX和Linux Shell正则表达式语法介绍
  19. HDU - 1284 钱币兑换问题 (找规律/完全背包)
  20. SPI driver

热门文章

  1. Nginx(二) 虚拟主机配置
  2. centos6.5 安装mysql5.6单实例和多实例(单配置文件)
  3. 关于使用mail命令产生:-bash: mail: command not found的解决方法
  4. java如何访问局域网共享文件
  5. mysql中不同事务隔离级别下数据的显示效果--转载
  6. hdu1166 敌兵布阵
  7. TFTP、RAM、NVRAM之间的关系
  8. 阻碍GIS产业发展的三大问题
  9. linux grep 基本正则表达式与扩展正则表达式使用解析
  10. Java程序员需要熟悉的库