! include 'class_Date.f90'
! include 'class_Person.f90'
include 'class_Student.f90' ! see previous figure
program main ! create or correct a student
use class_Student ! inherits class_Person, class_Date also
implicit none
type (Person) :: p ; type (Student) :: x
! Method 1
p = make_Person ("Ann Jones","",0) ! optional person constructor
call set_DOB (p, 5, 13, 1977) ! add birth to person data
x = Student_(p, "219360061", Date_(8,29,1955), 9, 3.1) ! public
call print_Name (p) ! list name
print *, "Born :"; call print_DOB (p) ! list dob
print *, "Sex :"; call print_Sex (p) ! list sex
print *, "Matriculated:"; call print_DOM (x) ! list dom
call print_GPA (x) ! list gpa
! Method 2
x = make_Student (p, "219360061") ! optional student constructor
call set_DOM (x, 8, 29, 1995) ! correct matriculation
call print_Name (p) ! list name
print *, "was born on :"; call print_DOB (p) ! list dob
print *, "Matriculated:"; call print_DOM (x) ! list dom
! Method 3
x = make_Student (make_Person("Ann Jones"), "219360061") ! optional
p = get_Person (x) ! get defaulted person data
call set_DOM (x, 8, 29, 1995) ! add matriculation
call set_DOB (p, 5, 13, 1977) ! add birth
call print_Name (p) ! list name
print *, "Matriculated:"; call print_DOM (x) ! list dom
print *, "was born on :"; call print_DOB (p) ! list dob
end program main ! Running gives:
! Ann Jones
! Born : May 13, 1977
! Sex : female
! Matriculated: August 29, 1955
! My name is Ann Jones, and my G.P.A. is 3.0999999.
! Ann Jones was born on: May 13, 1977 , Matriculated: August 29, 1995
! Ann Jones Matriculated: August 29, 1995 , was born on: May 13, 1977
fortran OOP(7) Test_Student.f90
最新推荐文章于 2022-04-27 16:55:47 发布