2014-11-11 4 views
-4

각 레코드에는 온도 값이 포함되어 있다고 가정합니다. 각 기록의 첫 번째 온도 값은 기상 관측소의 고온을 나타내며 각 기록의 두 번째 온도는 기상 관측소의 저온을 나타냅니다.이 온도를 표 5의 온도 TEMP (5, 2)로 입력합니다. 표의 1 열에있는 방송국과 표 2 열의 5 방송국의 저온. 모든 온도에서 읽은 후 5 기상 관측소의 평균 고온 및 평균 저온을 찾아서 출력합니다.각각 2 개의 온도를 포함하는 5 개의 레코드가 있다고 가정하십시오.

VB.NET에서 작성했지만 실행하지 않는 코드가 있습니다. 다음 코드는, 당신은에 의해 무슨 뜻 이죠

Module Module1 
    Dim TEMP(5, 2) As Integer 
    Dim count As Integer 
    Dim AVGHIGH As Integer 
    Dim AVGLOW As Integer 
    Dim i As Integer = 5 
    Dim high As Integer 
    Dim stations As Integer = 5 
    Dim low As Integer 
    Dim Totalhigh As Integer 
    Dim Totallow As Integer 

    Sub Main() 
    Call InputArray() 
    Call ComputeandOutputAverageHightempandLowtemp() 
    Call OutputArray() 
    Console.WriteLine("Please Press Enter") 
    Console.ReadLine() 
    End Sub 
    Sub InputArray() 


    stations = 0 

    Console.WriteLine("Enter{0} temperatures, one per line ", i) 
    Console.ReadLine() 
    TEMP(i, 2) = "High Temperature" 
    TEMP(i, 1) = Console.ReadLine() 
    TEMP(i, 2) = "Low Temperature" 
    TEMP(i, 2) = Console.ReadLine() 

    Do While stations <= i 
     stations = stations + 1 

    Loop 
    End Sub 
    Sub ComputeandOutputAverageHightempandLowtemp() 
    high = TEMP(i, 1) 
    low = TEMP(i, 2) 
    stations = 1 
    Totalhigh = 0 
    Totallow = 0 
    Do While stations <= 5 
    stations = stations + 1 
     If high > low Then 
     Totalhigh = 1 + TEMP(i, 1) 
     AVGHIGH = Totalhigh/stations 
     End If 
     Totallow = 1 + TEMP(i, 2) 
     AVGLOW = Totallow/stations 
    Loop 
    Console.WriteLine("High: " & Totalhigh) 
    Console.WriteLine("Low: " & Totallow) 
    Console.WriteLine("average high temperature: " & AVGHIGH) 

    End Sub 
    Sub OutputArray() 
    stations = 0 
    Console.WriteLine() 
    Console.WriteLine("The number in the list are: ") 
    Do While (stations <= 5) 
     stations = stations + 1 
     Console.WriteLine(TEMP(i, 1) & "") 
     Console.WriteLine(TEMP(i, 2) & "") 
    Loop 

    End Sub 

End Module 
+0

'프로그램을 통과하지 않습니다.' 오류가 발생하거나 아무런 반응이 없습니까? InputArray 하위에는 한 번 위의 블록을 실행 한 후 스테이션이 5가 될 때까지 스테이션에 1을 더하는 do while 루프가 있습니다. –

+1

정확한 결과를 정확히 설명하고 정확한 결과를 설명하십시오. – jmcilhinney

답변

0

모듈 Module1의

Dim Temp(5, 2) 
Dim HTemp As String 
Dim LTemp As String 
Dim TotHTemp As Integer 
Dim TotLTemp As Integer 
Dim AvgHTemp As Integer 
Dim AvgLTemp As Integer 
Dim Record As Integer 
Dim Row As Integer 
Dim TotRow As Integer 
Dim Accum As Integer 
Dim Count As Integer 

Sub Main() 'Overall (A000) 

    Console.Write("Please Enter the total number of Stations that you want to process(High Temp and Low Temp: ") 

    Record = Console.ReadLine() 

    TotRow = Record 
    Row = TotRow - 1 

    Do While Row >= 0 

     Console.Write("Please Enter high Temperature: ") 
     HTemp = Console.ReadLine() 


     Console.Write("Please Enter Low Temperature: ") 
     LTemp = Console.ReadLine() 

     TotHTemp = TotHTemp + HTemp 
     TotLTemp = TotLTemp + LTemp 


     Call Input() 

    Loop 
    Call comput() 

    Call Output() 

    Console.ReadLine() 

End Sub 

Sub Input() '(B000) 

    Temp(Row, 0) = HTemp 
    Temp(Row, 1) = LTemp 
    Row = Row - 1 


End Sub 

Sub comput() '(B010) 
    AvgHTemp = TotHTemp/TotRow 
    AvgLTemp = TotLTemp/TotRow 

End Sub 



Sub Output() '(B020) 

    Console.WriteLine() ' for spacing 

    Dim format As String = "{0,-25}{1,-25}{2}" 
    Console.WriteLine(format, "Record", "High Temp", "Low Temp") 

    Accum = 1 
    Count = Accum 
    Row = 0 
    Do While Row < TotRow 

     Console.WriteLine(format, Count, Temp(Row, 0), Temp(Row, 1)) 
     Call Counter() 

     Row = Row + 1 

    Loop 

    Console.WriteLine() ' for Space 
    Console.WriteLine(" Avg of high Temperatues =: " & AvgHTemp) 
    Console.WriteLine(" Avg of Low temperatures =: " & AvgLTemp) 


End Sub 
Sub Counter() '(C000) 

    Accum = Accum + 1 
    Count = Accum 

End Sub 

엔드 모듈

관련 문제