上机实验报告
发布时间:2022-09-17 15:15:30
一. 题目1. 建立一个学生档案,内容包括学号,姓名,年龄,性别,数学,物理和英语3门功课成绩。要求实现以下功能:1) 数据输入;2) 查询某个学生的成绩;3) 按平均排列输出;4) 统计某门课各分数段人数;5) 删除某个学生记录;2. 编程实现对二位数进行加,减,乘运算,每运行一次程序做10道题,完成后给出成绩(每题10分)。二. 设计思想和模块划分.先定义所需要的条件,例如,姓名,学号,性别,三门功课的成绩,平均分等。2.输入姓名,学号,性别,年龄,三门功课的成绩后,就输出相应的姓名,学号,性别,年龄,三门功课的成绩。3.打印表头;4.在求出平均分,并打印出平均分。5.在查找学生,并打印出学生的相关资料;并按照平均分的高低排列;6.在统计学生各科成绩是否》=60分,如果是就是通过,否就是没通过,最后打印出最后的结果。7.删除学生,选中删除的学生,如果确定要,那么该学生的一切记录就变为0;2.1.随机调用函数,产生两个其值为10到99的随机整数分别放在c,d中用作运算时的运算数。2.随机调用函数,产生一个值为1到3的随机整数放入b中,用来选择不同的运算。根据b的值选择不同的运算。当b=1时,去进行c d的运算练习;当b=2时,去进行c-d的运算练习;当b=3时,去进行c×d的运算练习。每完成一个算题就给出是否正确的信息。3.根据答案正确与否统计。正确时,显示’right’; 错误时,显示’wrong’。4.步骤. 重复10次。5.输出学生成绩。 三. 运行结果1. Input the1student :num:03name:wfage:18sex:fmath:98phy:75eng:65Input the2student :num:06name:scage:17sex:fmath:78phy:45eng:65Input the3student :num:09name:ytage:17sex:mmath:69phy:75eng:50 ----------------------------- table----------------------------- --------------------------------------------------------------------------------------------------- num name age sex math phy eng ave --------------------------------------------------------------------------------------------------- wf 18 f --------------------------------------------------------------------------------------------------- yt 17 m ---------------------------------------------------------------------------------------------------- sc 17 f number:3 ------------------------------------------------------------------------------------------------ num name age sex math phy eng ave ------------------------------------------------------------------------------------------------ wf 18 f number:6 ------------------------------------------------------------------------------------------------ num name age sex math phy eng ave ------------------------------------------------------------------------------------------------ sc 17 f ------------------------------------------------------------------------------------------------true? Y/Ny1 ---------------- table-------------- ------------------------------------------------------------------------------------------------- num name age sex math phy eng ave ------------------------------------------------------------------------------------------------- wf 18 f -------------------------------------------------------------------------------------------------- yt 17 m -------------------------------------------------------------------------------------------------- 0 0 0 f the math the phy the eng 1math: pass num is :3 no pass num is : 82=114right!97*15=1455right!99-58=41right!76-66=10right!58 13=71right!37 49=86right!99 52=151right!49*69=5462wrong!73-38=31wrong!86 34=120right!mark is80 四. 主要错误改正方法1.在本题的编写过程中常出现begin 和end 不配对,只要始它们的个数相同就可以了,就可以了。在程序中常出现的’unknown identifier’没有定义的错误,只要在程序前加上定义,就可以了。还有就是type mismatch’的类型不匹配,只要根据前后内容,重新定义,就可以了。2.在本题编写中,题目要求是两个两位数运算,如果写成c:=random(100)在运行过程中,就会出现一位数运算,只要把它写成c:=random(90) 10,就可以了。五. 实习小结1.第一题的程序编写比较复杂,需要较多的定义,因而在后面的程序部分,就常出现标识符重复,而导致的类型不匹配。还有就是每个部分编好后,上下不能连接,而无法调用。2.第二题较第一题简单,和书上的例题类似,所以,比较简单,但从中也出现一些不问题。以上两大题中出现的问题,要在同学的帮助下,才能完成。总的来说两题程序比较困难 六. 程序清单 twins;const m=3; n=3;typestudent=recordnum:integer;name:string;age:integer;sex:char;s:array[] of real;math,eng,phy:real;ave:real;end;sarr=array[] of student;ta=array [] of student;f=string;varstu:sarr; ct:ta; k,d:integer;procedure readin (var stu:sarr);const wrong="0<=data<=100 ,again!";var j,i:integer; a:student;beginwriteln;writeln("Input ",m," num name sex math phy eng"," of student.");for j:=1to m dobeginwriteln;writeln("Input the ",j," student :");with a dobeginwrite("num:"); readln(num);write("name:"); readln(name);write("age:"); readln(age);write("sex:"); readln(sex);while (sex<>"m")and(sex<>"f") dobeginwrite("sex:"); readln(sex)end;for i:=1to n do begincase i of1:begin write("math:"); readln(s[i]);while(s[i]<0)or(s[i]>100)dobeginwriteln(wrong);write("math:"); readln(s[i]);end;end;2:begin write("phy:"); readln(s[i]);while(s[i]<0)or(s[i]>100)dobeginwriteln(wrong);write("phy:"); readln(s[i]);end;end;3:begin write("eng:"); readln(s[i]);while(s[i]<0)or(s[i]>100)dobeginwriteln(wrong);write("eng:"); readln(s[i]);end;end;end;end;stu[j]:=a;end;writeln;end;end;procedure ave (var stu:sarr);var j,i:integer; k:real;beginfor j:=1to m dobegink:=0;with stu[j] dobeginfor i:=1to n do k:=k s[i];ave:=k/nend;end;end;procedure px (var stu:sarr);var tm:ta; j,i,p:integer;beginfor j:=1to m dobeginp:=j;for i:=j 1to m doif stu[i].ave>stu[p].ave then p:=i;tm:=stu[p]; stu[p]:=stu[j]; stu[j]:=tm;end;end;procedure head (ct:ta);var i:integer;beginwrite(" "); for i:=1to72do write("-");writeln;write(""," num":4," ","name":9," ","age":8," ","sex":5," ","math":6," ","phy":9," ","eng":8," ");writeln("ave":6," ");write(" "); for i:=1to72do write("-");writeln;with ct dobeginwrite("",num:7," ",name:8," ",age:8," ",sex:5," ");for i:=1to n do write(s[i]:7," ");write(ave:10," ");writeln;end;write(" "); for i:=1to72do write("-");writeln;end;procedure find (var stu:sarr);var n,i:integer; u:boolean;beginu:=true;while u dobeginwrite("Into number:");readln(n);for i:=1to m dobeginif stu[i].num=n then beginct:=stu[i];u:=false;d:=iend;end;end;end;procedure del (var stu:sarr);var i:integer; b:char;beginhead(ct);write("true? Y/N"); readln(b);if b="y" then begin write("1");with stu[d] dobeginnum:=0; name:="0"; age:=0; sex:="f";for i:=1to n do s[i]:=0;ave:=0end;endelseend;procedure tj (var stu:sarr);var w1,q1,q2,num,j:integer;h1,h2,h3:boolean;beginh1:=false;h2:=false;h3:=false;q1:=0;q2:=0;writeln(" ":30," the math the phy the eng ");readln(w1);case w1of1:h1:=true;2:h2:=true;3:h3:=true;end;if h1thenbeginbeginfor j:=1to m dowith stu[j] doif stu[j].math>=60 thenq1:=q1 1elseq2:=q2 1;writeln("math:");end;if h2thenbeginbeginfor j:=1to m dowith stu[j] doif stu[j].phy>=60 thenq1:=q1 1elseq2:=q2 1;writeln("phy:");end;if h3thenbeginbeginfor j:=1to m dowith stu[j] doif stu[j].eng>=60 thenq1:=q1 1elseq2:=q2 1;writeln("eng:");end;end;end;end;writeln(" ":5,"pass num is :",q1);writeln(" ":5,"no pass num is :",q2);end;procedure head1(var stu:sarr);var j,i:integer;beginwriteln("---------------- table--------------":60);writeln;write(" "); for i:=1to72do write("-");writeln;write(""," num":4," ","name":9," ","age":8," ","sex":5," ","math":6," ","phy":9," ","eng":8," ");writeln("ave":6," ");write(" "); for i:=1to72do write("-");writeln;for j:=1to m do beginwith stu[j] dobeginwrite("",num:7," ",name:8," ",age:8," ",sex:5," ");for i:=1to n do write(s[i]:7:1," ");write(ave:10:1," ");writeln;end;write(" "); for i:=1to72do write("-");writeln;end;end;beginreadin(stu);ave(stu);k:=0;while k<>5dobeginwriteln(" ");read(k); readln;while (k<>1)and(k<>2)and(k<>3)and(k<>4)and(k<>5) dobeginwriteln(" mistake,Please again");read(k)end;case k of1: begin px(stu); head1(stu) end;2: begin find(stu); head(ct) end;3: begin find(stu); del(stu); px(stu); head1(stu) end;4: begin tj(stu); end;5: writeln("exit!");end;end; shadow;var a,b,c,d,e:integer;right:boolean;procedure s1;beginwriteln("right!");right:=trueend;procedure s2;beginwriteln("wrong!");right:=falseend;procedure s3(x,y:integer);var h:integer;beginwrite(x," ",y,"=");readln(h);if h=x y then s1else s2 end;procedure s4(x,y:integer);var h,w:integer;beginif x