ZY-ReadfromFile

ZY-ReadfromFile
zhangyu 2 years ago
parent 70cbd02ddb
commit 3f5fdb39a4

@ -457,7 +457,12 @@ Step 4:输出总成绩和平均分
![输出n个学生的学号姓名以及m门课程的成绩](WritetoFile.svg)
#### ReadfromFile
Step 1:从文件中读取学生人数和课门数
Step 2:利用循环for输入学生学号和姓名
Step 3:利用二次循环输入学生成绩
Step 4:输入学生总成绩和平均分
![从文件中读取学生学号,姓名及成绩等信息写入结构体](ReadfromFile.svg)
#### exit
## 代码实现

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created by Flowgorithm 3.4.2 (http://flowgorithm.org) -->
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="2821" height="3968">
<rect x="0" y="0" width="2821" height="3968" fill="#FFFFFF"/>
<g>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="837,248 837,323"/>
<polygon fill="#404040" stroke="none" points="837,341 854,310 819,310"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="837,2201 837,3702"/>
<polygon fill="#404040" stroke="none" points="837,3720 854,3689 819,3689"/>
<g>
<path fill="#F0E0FF" stroke="#9070A0" stroke-width="4" stroke-dasharray="none" d="M 651,124 A 62 62, 0, 0 0, 651 248 L 1023,248 A 62 62, 0, 0 0, 1023 124 Z"/>
<text x="837" y="142" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="837" dy="62" unicode-bidi="embed">ReadfromFile</tspan>
</text>
</g>
<g>
<path fill="#F0E0FF" stroke="#9070A0" stroke-width="4" stroke-dasharray="none" d="M 713,3720 A 62 62, 0, 0 0, 713 3844 L 961,3844 A 62 62, 0, 0 0, 961 3720 Z"/>
<text x="837" y="3738" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="837" dy="62" unicode-bidi="embed">End</tspan>
</text>
</g>
<g>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="837,496 837,571"/>
<polygon fill="#404040" stroke="none" points="837,589 854,558 819,558"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="837,744 837,819"/>
<polygon fill="#404040" stroke="none" points="837,837 854,806 819,806"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="837,1736 837,1811"/>
<polygon fill="#404040" stroke="none" points="837,1829 854,1798 819,1798"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="837,1953 837,2059"/>
<polygon fill="#404040" stroke="none" points="837,2077 854,2046 819,2046"/>
<g>
<path fill="#FFFFD0" stroke="#A0A070" stroke-width="4" stroke-dasharray="none" d="M 651,341 L 651,496 L 1023,496 L 1023,341 Z"/>
<polyline fill="none" stroke="#A0A070" stroke-width="4" stroke-dasharray="none" points="651,372 1023,372"/>
<polyline fill="none" stroke="#A0A070" stroke-width="4" stroke-dasharray="none" points="682,341 682,496"/>
<text x="852" y="390" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="852" dy="62" unicode-bidi="embed">Integer i</tspan>
</text>
</g>
<g>
<path fill="#FFFFD0" stroke="#A0A070" stroke-width="4" stroke-dasharray="none" d="M 651,589 L 651,744 L 1023,744 L 1023,589 Z"/>
<polyline fill="none" stroke="#A0A070" stroke-width="4" stroke-dasharray="none" points="651,620 1023,620"/>
<polyline fill="none" stroke="#A0A070" stroke-width="4" stroke-dasharray="none" points="682,589 682,744"/>
<text x="852" y="638" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="852" dy="62" unicode-bidi="embed">Integer j</tspan>
</text>
</g>
<g>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="1271,1085 1488,1085 1488,1377"/>
<polygon fill="#404040" stroke="none" points="1488,1395 1505,1364 1470,1364"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="1488,1581 1488,1705 885,1705"/>
<polygon fill="#404040" stroke="none" points="868,1705 898,1722 898,1687"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="403,1085 155,1085 155,1705 788,1705"/>
<polygon fill="#404040" stroke="none" points="806,1705 775,1687 775,1722"/>
<g>
<path fill="#FFD0D0" stroke="#A07070" stroke-width="4" stroke-dasharray="none" d="M 837,837 L 372,1085 L 837,1333 L 1302,1085 Z"/>
<text x="837" y="1010" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="837" dy="62" unicode-bidi="embed">(fp = fopen(&quot;student.txt&quot;,</tspan>
<tspan x="837" dy="62" unicode-bidi="embed"> &quot;r&quot;)) == NULL</tspan>
</text>
</g>
<g>
<path fill="#D0FFD0" stroke="#70A070" stroke-width="4" stroke-dasharray="none" d="M 1178,1395 L 1085,1581 L 1798,1581 L 1891,1395 Z"/>
<text x="1488" y="1413" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1488" dy="62" unicode-bidi="embed">Output &quot;Failure to open</tspan>
<tspan x="1488" dy="62" unicode-bidi="embed"> score.txt!\n&quot;</tspan>
</text>
</g>
<g>
</g>
<ellipse cx="837" cy="1705" rx="31" ry="31" fill="#FFD0D0" stroke="#A07070" stroke-width="4"/>
<text x="1395" y="979" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1395" dy="62" unicode-bidi="embed">True</tspan>
</text>
<text x="263" y="979" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="263" dy="62" unicode-bidi="embed">False</tspan>
</text>
</g>
<g>
<path fill="#C04040" stroke="#602020" stroke-width="4" stroke-dasharray="none" d="M 434,1829 L 372,1953 L 1240,1953 L 1302,1829 Z"/>
<text x="837" y="1847" fill="#FFFFFF" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="837" dy="62" unicode-bidi="embed">Input fp, &quot;%10ld&quot;, &amp;stu[i].num</tspan>
</text>
</g>
<g>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="1085,2139 1519,2139 1519,2245"/>
<polygon fill="#404040" stroke="none" points="1519,2263 1536,2232 1501,2232"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="1519,3503 1519,3596 899,3596 899,2218"/>
<polygon fill="#404040" stroke="none" points="899,2201 881,2231 916,2231"/>
<g>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="1519,2387 1519,2462"/>
<polygon fill="#404040" stroke="none" points="1519,2480 1536,2449 1501,2449"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="1519,2604 1519,2710"/>
<polygon fill="#404040" stroke="none" points="1519,2728 1536,2697 1501,2697"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="1519,2852 1519,3299"/>
<polygon fill="#404040" stroke="none" points="1519,3317 1536,3286 1501,3286"/>
<g>
<path fill="#C04040" stroke="#602020" stroke-width="4" stroke-dasharray="none" d="M 1116,2263 L 1054,2387 L 1922,2387 L 1984,2263 Z"/>
<text x="1519" y="2281" fill="#FFFFFF" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1519" dy="62" unicode-bidi="embed">Input fp, &quot;%10ld&quot;, &amp;stu[i].num</tspan>
</text>
</g>
<g>
<path fill="#C04040" stroke="#602020" stroke-width="4" stroke-dasharray="none" d="M 1147,2480 L 1085,2604 L 1891,2604 L 1953,2480 Z"/>
<text x="1519" y="2498" fill="#FFFFFF" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1519" dy="62" unicode-bidi="embed">Input fp, &quot;%10s&quot;, stu[i].name</tspan>
</text>
</g>
<g>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="1767,2790 2201,2790 2201,2896"/>
<polygon fill="#404040" stroke="none" points="2201,2914 2218,2883 2183,2883"/>
<polyline fill="none" stroke="#404040" stroke-width="8" stroke-dasharray="none" points="2201,3100 2201,3193 1581,3193 1581,2869"/>
<polygon fill="#404040" stroke="none" points="1581,2852 1563,2882 1598,2882"/>
<g>
<path fill="#C04040" stroke="#602020" stroke-width="4" stroke-dasharray="none" d="M 1798,2914 L 1705,3100 L 2604,3100 L 2697,2914 Z"/>
<text x="2201" y="2932" fill="#FFFFFF" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="2201" dy="62" unicode-bidi="embed">Input fp, &quot;%10f&quot;, &amp;stu[i].score</tspan>
<tspan x="2201" dy="62" unicode-bidi="embed">[j]</tspan>
</text>
</g>
<g>
<path fill="#FFE0A0" stroke="#A08040" stroke-width="4" stroke-dasharray="none" d="M 1333,2728 L 1271,2790 L 1333,2852 L 1705,2852 L 1767,2790 L 1705,2728 Z"/>
<text x="1519" y="2746" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1519" dy="62" unicode-bidi="embed">j = 0 to m-1</tspan>
</text>
</g>
<text x="1860" y="2684" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1860" dy="62" unicode-bidi="embed">Next</tspan>
</text>
<text x="1410" y="2870" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1410" dy="62" unicode-bidi="embed">Done</tspan>
</text>
</g>
<g>
<path fill="#C04040" stroke="#602020" stroke-width="4" stroke-dasharray="none" d="M 1116,3317 L 1023,3503 L 1922,3503 L 2015,3317 Z"/>
<text x="1519" y="3335" fill="#FFFFFF" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1519" dy="62" unicode-bidi="embed">Input fp, &quot;%10f%10f&quot;, &amp;stu[i].</tspan>
<tspan x="1519" dy="62" unicode-bidi="embed">sum, &amp;stu[i].aver</tspan>
</text>
</g>
</g>
<g>
<path fill="#FFE0A0" stroke="#A08040" stroke-width="4" stroke-dasharray="none" d="M 651,2077 L 589,2139 L 651,2201 L 1023,2201 L 1085,2139 L 1023,2077 Z"/>
<text x="837" y="2095" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="837" dy="62" unicode-bidi="embed">i = 0 to n-1</tspan>
</text>
</g>
<text x="1178" y="2033" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="1178" dy="62" unicode-bidi="embed">Next</tspan>
</text>
<text x="728" y="2219" fill="#000000" font-family="Arial" font-size="32pt" text-anchor="middle" direction="ltr">
<tspan x="728" dy="62" unicode-bidi="embed">Done</tspan>
</text>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 10 KiB

Loading…
Cancel
Save