为了账号安全,请及时绑定邮箱和手机立即绑定

题目哈: [(单科成绩-60)/10+1]*单科学分 求和后再除以总学分

题目哈: [(单科成绩-60)/10+1]*单科学分 求和后再除以总学分

手掌心 2023-01-12 21:17:30

Option Base 1
Const num = 10
Dim a(num) As Single, b(num) As Single, c(num) As Single
Dim x As Single, m As Single
Dim sum As Single, i As Integer

Private Sub Command1_Click()

sum = 0
For i = 1 To num
c(i) = ((a(i) - 60) / 10 + 1) * b(i)
sum = sum + c(i)
Next i

x = sum / m
Print "Text00.Text"; x
End Sub

Private Sub Form_Load()

a(1) = Val("Text1.Text") '各科成绩
a(2) = Val("Text2.Text")
a(3) = Val("Text3.Text")
a(4) = Val("Text4.Text")
a(5) = Val("Text5.Text")
a(6) = Val("Text6.Text")
a(7) = Val("Text7.Text")
a(8) = Val("Text8.Text")
a(9) = Val("Text9.Text")
a(10) = Val("Text10.Text")
b(1) = Val("Text11.Text") '各科学分
b(2) = Val("Text12.Text")
b(3) = Val("Text13.Text")
b(4) = Val("Text14.Text")
b(5) = Val("Text15.Text")
b(6) = Val("Text16.Text")
b(7) = Val("Text17.Text")
b(8) = Val("Text18.Text")
b(9) = Val("Text19.Text")
b(10) = Val("Text20.Text")
m = Val(Text0.Text) '总学分
End Sub

查看完整描述

3 回答

?
小唯快跑啊

TA贡献1619条经验 获得超2个赞

下面是根据你的程序改起来的,改动的地方就是把Form_load函数中的40个双引号去掉
Option Explicit

Option Base 1
Const num = 10
Dim a(num) As Single, b(num) As Single, c(num) As Single
Dim x As Single, m As Single
Dim sum As Single, i As Integer

Private Sub Command1_Click()
sum = 0
For i = 1 To num
c(i) = ((a(i) - 60) / 10 + 1) * b(i)
sum = sum + c(i)
Next i

x = sum / m
Print "Text00.Text"; x
End Sub

Private Sub Form_Load()
a(1) = Val(Text1.Text) '各科成绩
a(2) = Val(Text2.Text)
a(3) = Val(Text3.Text)
a(4) = Val(Text4.Text)
a(5) = Val(Text5.Text)
a(6) = Val(Text6.Text)
a(7) = Val(Text7.Text)
a(8) = Val(Text8.Text)
a(9) = Val(Text9.Text)
a(10) = Val(Text10.Text)
b(1) = Val(Text11.Text) '各科学分
b(2) = Val(Text12.Text)
b(3) = Val(Text13.Text)
b(4) = Val(Text14.Text)
b(5) = Val(Text15.Text)
b(6) = Val(Text16.Text)
b(7) = Val(Text17.Text)
b(8) = Val(Text18.Text)
b(9) = Val(Text19.Text)
b(10) = Val(Text20.Text)
m = Val(Text0.Text) '总学分
End Sub

============================================
下面是我给你写的程序,你可以和你的程序比较一下孰优孰劣
窗体上左上角放一个TextBox和右边放一个按钮就可以了,不需要象你那样放21个TextBox
Option Explicit

Option Base 1
Const Total = 10

Private Sub Command1_Click()
Dim Sum As Single, Score(Total) As Single, Credit(Total) As Single
Dim i As Integer, SumCredit As Integer
For i = 1 To Total
Score(i) = (Val(Text1(i - 1).Text) - 60) / 10 + 1
Credit(i) = Val(Text1(i + Total - 1).Text)
Sum = Sum + Score(i) * Credit(i)
SumCredit = SumCredit + Credit(i)
Next i

MsgBox "平均学分:" & Format(Sum / SumCredit, "0.00")
End Sub

Private Sub Form_Load()
Dim i As Integer
Text1(0).Text = 90
For i = 0 To Total - 1
If i <> 0 Then
Load Text1(i)
Text1(i).Left = Text1(0).Left
Text1(i).Top = Text1(i - 1).Top + Text1(0).Height + 100
Text1(i).Visible = True
Text1(i).Text = Int(Rnd * 60) + 35
End If
Load Text1(i + Total)
Text1(i + Total).Left = Text1(0).Left + Text1(0).Width + 400
Text1(i + Total).Top = Text1(i).Top
Text1(i + Total).Visible = True
Text1(i + Total).Text = Int(Rnd * 5) + 1
Next
End Sub
=========================================
我觉得,你的程序的一个闪光点就是
c(i) = ((a(i) - 60) / 10 + 1) * b(i)
这一句.如果这句是你自己写的,那证明你还是很有想法的

 


查看完整回答
反对 回复 2023-01-15
?
ITMISS

TA贡献1577条经验 获得超8个赞

我给你改一下吧:
Option Base 1 
Const num = 10 
Dim a(num) As Single, b(num) As Single, c(num) As Single 
Dim x As Single, m As Single 
Dim sum As Single, i As Integer 

Private Sub Command1_Click() 
sum = 0 
m=0
For i = 1 To num 
c(i) = ((a(i) - 60) / 10 + 1) * b(i) 
sum = sum + c(i)
m=m+b(i) 
Next i 

if m>0
x = sum / m 
Print "Text00.Text"; x 
end if
End Sub 

Private Sub Form_Load() 

a(1) = Val(Text1.Text) '各科成绩 
a(2) = Val(Text2.Text) 
a(3) = Val(Text3.Text) 
a(4) = Val(Text4.Text) 
a(5) = Val(Text5.Text) 
a(6) = Val(Text6.Text) 
a(7) = Val(Text7.Text) 
a(8) = Val(Text8.Text) 
a(9) = Val(Text9.Text) 
a(10) = Val(Text10.Text) 
b(1) = Val(Text11.Text) '各科学分 
b(2) = Val(Text12.Text) 
b(3) = Val(Text13.Text) 
b(4) = Val(Text14.Text) 
b(5) = Val(Text15.Text) 
b(6) = Val(Text16.Text) 
b(7) = Val(Text17.Text) 
b(8) = Val(Text18.Text) 
b(9) = Val(Text19.Text) 
b(10) = Val(Text20.Text) 
End Sub

语法不规范,思维不严谨

 


查看完整回答
反对 回复 2023-01-15
?
qq_笑_17

TA贡献1568条经验 获得超7个赞

因为你的a(1)-a(10),b(1)-b(10)中赋值中多了双引号,所以最终赋值结果都是0,最终造成m=0,并且sum也=0
所以当sum=sum/m时会溢出。解决办法,把刚才说的那些双引号去掉。

查看完整回答
反对 回复 2023-01-15
  • 3 回答
  • 0 关注
  • 7 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信