Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program CourceWork_Mozer
- implicit none
- type student_data
- character(len = 15) :: surname, name, patronymic
- integer :: day, month, year
- character(len = 11) :: telephone_number
- character(len = 18) :: flowers
- end type student_data
- !--
- logical :: search_result
- type(student_data) :: current_student
- !--
- write(*, *) '= Enter surname...'
- read(*, '(A15)') current_student%surname
- call student_searh(current_student, search_result)
- if (search_result) then
- call student_output(current_student)
- end if
- write(*, *) '= End program...'
- pause
- contains
- subroutine student_searh(student, search_result)
- implicit none
- type(student_data), intent(inout) :: student
- logical, intent(out) :: search_result
- type(student_data) :: student_database
- !--
- if (student%surname == '') then
- write(*, *) '= Incorrect input!'
- search_result = .false.
- return
- end if
- write(*, *) '= Search in database...'
- open(unit = 1, file = 'GR_M1O_101B_18.TXT', status = 'old')
- do
- read(1, 201, end = 199) student_database%surname, student_database%name, student_database%patronymic, student_database%day, student_database%month, student_database%year, student_database%telephone_number, student_database%flowers
- if (student%surname == student_database%surname) then
- write(*, *) '= Student was found.'
- student = student_database
- search_result = .true.
- exit
- end if
- end do
- go to 200
- 199 write(*, *) "= Student wasn't found."
- search_result = .false.
- 200 close(1)
- 201 format(A15, A15, A15, I2, I2, I2, A11, A18)
- end subroutine student_searh
- subroutine student_output(student)
- implicit none
- character(len = 87) :: output(2)
- character(len = 23) :: format_integer
- character(len = 9), dimension(12) :: months = (/'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'/)
- type(student_data), intent(in) :: student
- !-- Full name
- output(1) = trim(student%surname)//' '//trim(student%name)//' '//trim(student%patronymic)
- !-- Birthday
- if (student%flowers == '') then
- output(1) = trim(output(1))//' (male) was born on '//months(student%month)
- else
- output(1) = trim(output(1))//' (female) was born on '//months(student%month)
- endif
- if (student%year < 90) then
- output(2) = ', 200'
- format_integer = '(A, A, A, I2, A, I1, A)'
- else
- output(2) = ', 19'
- format_integer = '(A, A, A, I2, A, I2, A)'
- end if
- write(*, format_integer) ' ---> ', trim(output(1)), ' ', student%day, trim(output(2)), student%year, '.'
- !-- Telephone
- if (student%flowers == '') then
- output(1) = '---> Contact him'
- else
- output(1) = '---> Contact her'
- end if
- if (student%telephone_number /= '') then
- output(1) = trim(output(1))//' by phone '//student%telephone_number(1:1)//' ('//student%telephone_number(2:4)//') '//student%telephone_number(5:7)//'-'//student%telephone_number(8:9)//'-'//student%telephone_number(10:11)//'.'
- else
- output(1) = trim(output(1))//' personally.'
- endif
- write(*, *) trim(output(1))
- !-- Flowers
- if (student%flowers /= '') then
- output(1) = '---> P.S. '//trim(student%flowers)//' are favorite flowers.'
- write(*, *) trim(output(1))
- end if
- end subroutine student_output
- end program CourceWork_Mozer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement