vb.net structure结构类型

编写一个记录学生信息和学习成绩的程序

学号(num)、姓名(name)、性别(sex)、年龄(age)、住址(address)、学习成绩(mark)

学习成绩分为5们 分数分别为95,90,112,94,90

 

Module Module1

    Public Structure student
        Dim num As Integer
        Dim name As String
        Dim sex As String
        Dim age As Integer
        Dim address As String
        Dim lessons As Mark
    End Structure
    Public Structure Mark
        Dim mark1 As Integer
        Dim mark2 As Integer
        Dim mark3 As Integer
        Dim mark4 As Integer
        Dim mark5 As Integer
    End Structure
    Sub Main()
        Dim average, sum As Single
        Dim person As student

        person.num = 12345
        person.name = "zhang"
        person.sex = "nan"
        person.age = 21
        person.address = "yantai"

        person.lessons.mark1 = 95
        person.lessons.mark2 = 90
        person.lessons.mark3 = 112
        person.lessons.mark4 = 94
        person.lessons.mark5 = 90
        average = 0
        sum = 0
        '结构变量的引用
        With person.lessons
            sum = .mark1 + .mark2 + .mark3 + .mark4 + .mark5
        End With
        average = sum / 5

        Console.WriteLine("学号:{0}", person.num)
        Console.WriteLine("姓名:{0}", person.name)
        Console.WriteLine("性别:{0}", person.sex)
        Console.WriteLine("地址:{0}", person.address)
        Console.WriteLine("五门成绩:")
        With person.lessons
            Console.WriteLine("{0}", .mark1)
            Console.WriteLine("{0}", .mark2)
            Console.WriteLine("{0}", .mark3)
            Console.WriteLine("{0}", .mark4)
            Console.WriteLine("{0}", .mark5)
        End With
        Console.WriteLine("总成绩:{0}", sum)
        Console.WriteLine("平均成绩:{0}", average)

        Console.ReadLine()
    End Sub

End Module


运行效果:

 

 

 

 

你可能感兴趣的:(vb.net)