1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Student Test Scores help....

Discussion in 'Programming' started by IanT, Dec 11, 2013.

  1. #1
    Need some help...hitting a wall. I can get it to calculate for only the 1st student in the array, but not the other 5.


    here is the form:


    [​IMG]


    these are my instructions: (Visual basic!)

    A teacher has 6 students, and wants you to create an application that stores their grade data in a file and prints a grade report. The application should have structure that stores: Name (a string), Test Scores (an array of 5 doubles), and Average ( a double) . It should have an array of 6 structure variables to match the 6 students.It should allow the user to enter the data for each student, and calculate the average test score for each. The user needs to be able to save, read and print data to/from file etc.

    It should not accept scores below 0 or above 100.

    Here are my additional instructions:

    Do not use menu bars...Instead add buttons to read the data, save the file after the data has been updated, and exit. The button to calculate the averages should also be coded.
    The initial file containing the student scores is StudentData.txt. Code this file with a location of C:\.
    Add comments at the top of your code file for your name and the date. Include other comments as appropriate based on the examples in the textbook.
    All controls (user interface objects on your form must have meaningful names with appropriate prefixes (for example, btnExit for an exit button).

    Imports System.IO
    
    
    Public Class Form1
    
    
        Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
            ' Close(program)
            Me.Close()
        End Sub
    
    
        Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
            StudentScoreDataInput()
        End Sub
    
    End Class
    
    Module StudentTestScoresModule
    
        Const intMAX_SUBSCRIPT_STUDENT As Integer = 6
        Const intMAX_SUBSCRIPT_STUDENT_SCORES As Integer = 5
    
    
        'create structure
    
        Public Structure StudentData
            Dim strName As String
            Dim dblTestScoresArray() As Double
            Dim dblAverage As Double
        End Structure
    
        Dim dblTotalStd1 As Double
        Dim dblTotalStd2 As Double
        Dim dblTotalStd3 As Double
        Dim dblTotalStd4 As Double
        Dim dblTotalStd5 As Double
        Dim dblTotalStd6 As Double
    
        Dim dblScore As Double
    
        Dim StudentsArray(intMAX_SUBSCRIPT_STUDENT) As StudentData
    
        Sub StudentNameDataInput()
            StudentsArray(0).strName = Form1.txtName1.Text
            StudentsArray(1).strName = Form1.txtName2.Text
            StudentsArray(2).strName = Form1.txtName3.Text
            StudentsArray(3).strName = Form1.txtName4.Text
            StudentsArray(4).strName = Form1.txtName5.Text
            StudentsArray(5).strName = Form1.txtName6.Text
        End Sub
    
        Sub StudentScoreDataInput()
            Dim dblAverage As Double
            For intIndex = 0 To intMAX_SUBSCRIPT_STUDENT
                ReDim StudentsArray(intIndex).dblTestScoresArray(4)
            Next
    
            'initialize test scores for first student in the array
            StudentsArray(0).dblTestScoresArray(0) = CDbl(Form1.txtS11.Text)
            StudentsArray(1).dblTestScoresArray(1) = CDbl(Form1.txtS12.Text)
            StudentsArray(2).dblTestScoresArray(2) = CDbl(Form1.txtS13.Text)
            StudentsArray(3).dblTestScoresArray(3) = CDbl(Form1.txtS14.Text)
            StudentsArray(4).dblTestScoresArray(4) = CDbl(Form1.txtS15.Text)
    
    
    
            For Each i As StudentData In StudentsArray
                For Each S As Double In i.dblTestScoresArray
                    dblTotalStd1 += S
                Next
            Next
            dblAverage = dblTotalStd1 / intMAX_SUBSCRIPT_STUDENT_SCORES
            Form1.lblAvg1.Text = (dblAverage.ToString)
        End Sub
    
        Sub CalculateAverage()
        End Sub
    
    End Module
    Code (markup):
     
    IanT, Dec 11, 2013 IP