MST

星途 面试题库

面试题:Fortran自定义数据类型的应用

假设要开发一个管理员工信息的程序,员工信息包括姓名(字符串)、年龄(整数)、工资(实数)。请使用Fortran自定义数据类型来设计数据结构,并编写一段程序示例,实现至少一个员工信息的录入和显示功能。
13.3万 热度难度
编程语言Fortran

知识考点

AI 面试

面试题答案

一键面试
! 定义员工信息的数据类型
type :: employee
    character(len=50) :: name
    integer :: age
    real :: salary
end type employee

program manage_employee
    type(employee) :: emp
    ! 录入员工信息
    write(*,*) '请输入员工姓名:'
    read(*,*) emp%name
    write(*,*) '请输入员工年龄:'
    read(*,*) emp%age
    write(*,*) '请输入员工工资:'
    read(*,*) emp%salary
    ! 显示员工信息
    write(*,*) '员工姓名:', emp%name
    write(*,*) '员工年龄:', emp%age
    write(*,*) '员工工资:', emp%salary
end program manage_employee