<stdio.h>
void
main()
{
int
i,
n,
reno
float
score[30],
avr,
a,
b,
c
char
name[30][9]
for(i
=
0
i
<
30
i++)
{
printf("%d号的成绩:",
i+1)
scanf("%f",
&score[i])
if(score[i]
<
0)
break
printf("%d号的姓名:",
i+1)
scanf("%s",
name[i])
}
n
=
i
printf("统计不及格人数:\n")
reno
=
0
avr
=
0
for(i
=
0
i
<
n
i++)
{
if(
score[i]
<
60)
{
reno++
printf("%d,
%s\n",
i+1,
name[i])
}
avr
+=
score[i]
}
printf("不及格人数为%d\n\n",
reno)
printf("统计成绩在平均分及平均分之上的学生人数:\n")
avr
/=
nreno
=
0
for(i
=
0
i
<
n
i++)
{
if(score[i]
>=
avr)
{
reno++
printf("%d,
%s\n",
i+1,
name[i])
}
}
printf("成绩在平均分及平均分之上的学生人数为%d\n\n",
reno)
printf("统计各分数段的人数及所占百分比(分数段为<60,60~79,>=80):\n")
a
=
b
=
c
=0
for(i
=
0
i
<
n
i++)
{
if(score[i]
<
60)
a++
else
if(score[i]
>=
80)
c++
else
b++
}
printf("<60:\t%.1f%%\n60~79:\t%.1f%%\n>=80:\t%.1f%%\n",100*a/n,100*b/n,100*c/n)
}
#include <stdio.h>typedef struct student
{
int id
double math
double english
double chinese
double computer
} student
int order[35]
double addsum[35]
double addaver[35]
student stu[35]
int stu_cnt = 0
void input()
{
stu_cnt = 0
while( stu_cnt < 35 )
{
printf( "输入学号(输入0退出输入):" )
scanf( "%d", &stu[stu_cnt].id )
fflush( stdin )
if ( stu[stu_cnt].id <= 0 )
break
printf( "输入4门成绩(数学 英语 语文 计算机):" )
scanf( "%lf %lf %lf %lf", &stu[stu_cnt].math, &stu[stu_cnt].english,
&stu[stu_cnt].chinese, &stu[stu_cnt].computer )
fflush( stdin )
addsum[stu_cnt] = stu[stu_cnt].math + stu[stu_cnt].english +
stu[stu_cnt].chinese, stu[stu_cnt].computer
addaver[stu_cnt] = addsum[stu_cnt] / 4.0
order[stu_cnt] = stu[stu_cnt].id
stu_cnt++
}
}
int query( int id )
{
int i = 0
for( i=0 i<stu_cnt i++ )
{
if ( stu[i].id == id )
return i
}
return -1
}
void gen_order()
{
int i,j
for( i=0 i<stu_cnt i++ )
{
for( j=i+1 j<stu_cnt j++ )
{
if ( addsum[i] - addsum[j] < 0.001 )
{
int temp_id = order[i]
order[i] = order[j]
order[j] = temp_id
}
}
}
}
void output()
{
int i
printf( "名次 学号 数学 英语 语文 计算机 总分 平均\n" )
for( i=0 i<stu_cnt i++ )
{
int j = query( order[i] )
if ( j<0 )
{
printf( "order[%d]= %d error\n", i+1, order[i] )
continue
}
printf( "%02d %5d %4.2f %4.2f %4.2f %6.2f %4.2f %4.2f\n",
i+1, stu[j].id, stu[j].math, stu[j].english, stu[j].chinese, stu[j].computer,
addsum[j], addaver[j] )
}
}
int main()
{
input()
gen_order()
output()
}
基本原理和这个通讯录数据处理程序相似,提问者稍加修改就可以使用。clear
set safe off
use txl
text
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
※ 1.输入 2.修改 3.插入 4.删除 ※
※ 5.按姓名升序显示 6.按邮政编码升序显示 ※
※ 7.按姓名查询 8.退出 ※
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
endtext
input "请按数字键选择" to aa
do case
case aa=1
go bott
accept "请输入姓名:" to xm
accept "请输入性别:" to xb
accept "请输入电话号码:" to dhhm
accept "请输入家庭住址:" to jtzz
accept "请输入工作单位:" to gzdw
accept "请输入邮政编码:" to yzbm
repl 姓名 with xm,性别 with xb, 电话号码 with dhhm,家庭住址 with jtzz,工作单位 with gzdw,邮政编码 with yzbm
case aa=2
input"请输入您要修改的记录的编号:" to c
go c
? "请修改第"+str(c,1)+"个人的数据!"
disp
accept "请输入姓名:" to xm
accept "请输入性别:" to xb
accept "请输入电话号码:" to dhhm
accept "请输入家庭住址:" to jtzz
accept "请输入工作单位:" to gzdw
accept "请输入邮政编码:" to yzbm
repl 姓名 with xm,性别 with xb, 电话号码 with dhhm,家庭住址 with jtzz,工作单位 with gzdw,邮政编码 with yzbm
case aa=3
append blank
accept "请输入姓名:" to xm
accept "请输入性别:" to xb
accept "请输入电话号码:" to dhhm
accept "请输入家庭住址:" to jtzz
accept "请输入工作单位:" to gzdw
accept "请输入邮政编码:" to yzbm
repl 姓名 with xm,性别 with xb, 电话号码 with dhhm,家庭住址 with jtzz,工作单位 with gzdw,邮政编码 with yzbm
case aa=4
input "请输入您想要删除的记录号" to d
go d
delete
accept "确认删除请按小写字母y,否则取消删除)" to e
if e="y"
pack
else
recall
endif
case aa=5
index on 姓名 to xm
list
case aa=6
index on 邮政编码 to yzbm
list
case aa=7
accept "请输入您要查询的姓名" to f
list for 姓名=f
case aa=8
wait "系统即将关闭" window timeout 3
exit
othe
messagebox("请重新选择",0+64,"出错了")
endc
set safe on
*这个程序能完成任务,不过界面不好。可以这样修改:
*新建一个表单(主表单,表单1),增加8个按钮,每个按钮的名称caption同上面程序中的菜单;再增加一个按钮,caption为“退出”,保存表单1。
*新建一个数据处理表单(表单2),向表单添加标签,caption为“姓名”,再增加一个文本控件text1,用来处理“姓名”数据;继续向表单添加标签,caption为“性别”,增加一个文本控件text2,用来处理“性别”数据;.........向表单添加标签,caption为“邮政编码”,再增加一个文本控件text6,用来处理“邮政编码”数据。把标签和文本控件适当整理齐整。增加一个按钮,caption 为“保存”,再增加一个按钮,caption为“退出”,
双击表单空白处,出现load事件,输入
thisform.text1.value=xm
thisform.text2.value=xb
thisform.text3.value=dhhm
thisform.text4.value=jtzz
thisform.text5.value=gzdw
thisform.text6.value=yzbm
输入完毕,关闭load事件,这是给表单2的几个控件赋初值。
双击“退出”按钮,输入
thisform.release
关闭事件,双击“保存”按钮,输入
repl 姓名 with thisform.text1.value,
性别 with thisform.text2.value,
电话号码 with thisform.text2.value,
家庭住址 with thisform.text2.value,
工作单位 with thisform.text2.value,
邮政编码 with thisform.text2.value
保存表单2。
打开表单1,双击表单的空白处,出现load事件,输入:
set safe off
use txl
public xm,xb,dhhm,jtzz,gzdw,yzbm
双击“输入”按钮,输入
go bott
*下面给表单2赋初值
xm=姓名
xb=性别
dhhm=电话号码
jtzz=家庭住址
gzdw=工作单位
yzdm=邮政编码
do form 表单2
双击“修改”按钮,输入
input"请输入您要修改的记录的编号:" to c
go c
*下面给表单2赋初值
xm=姓名
xb=性别
dhhm=电话号码
jtzz=家庭住址
gzdw=工作单位
yzdm=邮政编码
do form 表单2
双击“插入”按钮,输入
appe blank
*下面给表单2赋初值
xm=姓名
xb=性别
dhhm=电话号码
jtzz=家庭住址
gzdw=工作单位
yzdm=邮政编码
do form 表单2
双击“删除”按钮,输入
input "请输入您想要删除的记录号" to d
go d
delete
accept "确认删除请按小写字母y,否则取消删除)" to e
if e="y"
pack
else
recall
endif
双击“按姓名升序显示”按钮,输入
index on 姓名 to xm
brow
双击“按邮政编码升序显示”按钮,输入
index on 邮政编码 to yzbm
brow
双击“按姓名查询”按钮,输入
accept "请输入您要查询的姓名" to f
brow for 姓名=f
双击“退出”按钮,输入
close data
set safe on
thisform.release
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)