игра брюс 2048
Главная / Программирование / Программирование больших вычислительных задач на современном Фортране с использованием компиляторов Intel / Тест 2

Программирование больших вычислительных задач на современном Фортране с использованием компиляторов Intel - тест 2

Упражнение 1:
Номер 1
Укажите оператор, используемый для задания производного типа

Ответ:

 (1) class 

 (2) type 

 (3) record 

 (4) extends 

 (5) select type 


Номер 2
Укажите оператор, который указывает какие процедуры привязаны к типу по имени

Ответ:

 (1) contains 

 (2) private 

 (3) type 

 (4) class 

 (5) select type 


Номер 3
Процедурные указатели объявляются при помощи оператора

Ответ:

 (1) procedure 

 (2) contains 

 (3) class 

 (4) final 

 (5) pass 


Номер 4
Наследование производных типов осуществляется при помощи атрибута

Ответ:

 (1) pass 

 (2) extends 

 (3) extend 

 (4) class 

 (5) select type 


Номер 5
Неограниченно полиморфная переменная объявляется при помощи оператора

Ответ:

 (1) class 

 (2) class(*) 

 (3) class() 

 (4) class* 

 (5) *class 


Упражнение 2:
Номер 1
Финальные процедуры объявляются при помощи атрибута

Ответ:

 (1) procedure 

 (2) final 

 (3) deferred 

 (4) non_overridable 

 (5) extends 


Номер 3
Выберите верные утверждения касающиеся конструктора

Ответ:

 (1) имя конструктора совпадает с именем типа 

 (2) конструктор может вызываться только при объявлении переменной 

 (3) все параметры конструктора являются optional-параметрами 

 (4) конструктор можно использовать в операторе allocate 

 (5) конструктор должен объявляться внутри типа при помощи атрибута deferred 


Номер 4
Определение типа полиморфной переменной происходит посредством оператора

Ответ:

 (1) class(*) 

 (2) select case 

 (3) type is 

 (4) class is 

 (5) select type 


Номер 5
Каким атрибутом следует описать процедуру, привязанную к типу по имени, чтобы получить доступ к переменной, посредством которой вызывалась данная процедура ?

Ответ:

 (1) final 

 (2) pass 

 (3) nopass 

 (4) deferred 

 (5) procedure 


Упражнение 3:
Номер 1
Перегрузка операции деления реализуется при помощи оператора

Ответ:

 (1) extends 

 (2) interface operator 

 (3) operator 

 (4) interface assignment 

 (5) procedure 


Номер 2
Перегрузка операции присваивания реализуется при помощи оператора

Ответ:

 (1) extends 

 (2) interface operator 

 (3) operator 

 (4) interface assignment 

 (5) procedure 


Номер 3
Выберите верное задание операции EXTRACT для производного типа

Ответ:

 (1) interface operator (EXTRACT) module procedure ext end interface  

 (2) interface operator (.EXTRACT.) module procedure ext end interface  

 (3) interface assignment (EXTRACT) module procedure ext end interface  

 (4) interface operator :: EXTRACT module procedure ext end interface  

 (5) interface operator => .EXTRACT. module procedure ext end interface  


Номер 4
Полиморфная переменная объявляется оператором

Ответ:

 (1) class 

 (2) type 

 (3) record 

 (4) extends 

 (5) select type 


Номер 5
Для запрещения прямого обращения к полю производного типа используется атрибут

Ответ:

 (1) public 

 (2) protected 

 (3) private 

 (4) extends 

 (5) pass 


Упражнение 4:
Номер 1
В программе объявлены типы и переменная

  type point
    complex x,y
  end type point

  type NewType
    integer a
    type (point) z(3)
    character(4) border(2)
  end type NewType
  
  type (NewType) pt(10)
        
Укажите верные варианты инициализации элемента pt(5)

Ответ:

 (1) pt(5)=NewType(50,[(1.0,1.0),(2.0,2.0)],'A101') 

 (2) pt(5)=NewType(50,[point((1.0,1.0),(2.0,2.0)), & point((0.0,1.0),(3.0,8.0)), & point((0.0,0.0),(3.0,0.0))],['A101','B120'])  

 (3) pt(5)=NewType(50,0.0,['A101','B120']) 

 (4) pt(5)=NewType(50,point(0.0),['A101','B120']) 

 (5) pt(5)=NewType(50,point(0.0,0.0),['A101','B120']) 


Номер 2
Модуль

module mod_1
  type region
    integer x1,y1,x2,y2
  end type region

  type blk
    logical st(3)
    character(5), private :: name
  end type blk

  type NewType
    type (region) reg
    type (blk)    bee
  end type NewType
end module mod_1
        

используется в головной программе.

Описан массив

type (NewType) matrix(10,10,100) Укажите верные варианты инициализации элемента matrix(1:5:2,:,20)

Ответ:

 (1) matrix(1:5:2,:,20)=NewType(region(1,2,3,4),blk(.TRUE.,'TERMO')) 

 (2) matrix(1:5:2,:,20)=NewType(region(0),blk('TERMO',.FALSE.)) 

 (3) matrix(1:5:2,:,20)=NewType((1,2,3,4),blk(.FALSE.,'TERMO')) 

 (4) matrix(1:5:2,:,20)=NewType(region(0,0,0,0),blk(.FALSE.,'TERMO')) 

 (5) matrix(1:5:2,:,20)=NewType(region(0,0,0,0),blk('TER','TER')) 


Номер 3
Модуль

module mod_1
  type region
    integer x(4)
    real R
  end type region

  type blk
    logical st(3)
    character(5), public :: name(2)
  end type blk

  type NewType
    type (region) reg(20)
    type (blk)    bee(30)
  end type NewType
end module mod_1
        

используется в головной программе.

Объявлена переменная

type(NewType) NT Укажите верные варианты доступа к полям производного типа.

Ответ:

 (1) NT.reg(10).x(2) 

 (2) NT.reg.x 

 (3) NT.reg.x(3) 

 (4) NT.bee(1::2).name(1) 

 (5) NT.bee(2:20:5).name(1)(1:3) 


Номер 4
Модуль

module mod_1
  type plot
    integer x1,y1,x2,y2
    integer color(255)
  end type plot

  type indicator
    type (plot) plt
    logical, private :: free
    character(4) date
  end type indicator

  type card
    type (indicator) indic
    integer fparam
    integer sparam
  end type card

end module mod_1
        

используется в головной программе.

Объявлена переменная

type(card) cd Укажите верные варианты доступа к полям производного типа.

Ответ:

 (1) cd.indic.plt.color(200) 

 (2) cd.indic.date(1:3) 

 (3) cd.indic 

 (4) cd.indic.free 

 (5) cd.indic.plot 


Номер 5
Модуль

module mod_1
  type plot
    integer x1,y1,x2,y2
    integer, private :: color(255)
  end type plot

  type indicator
    type (plot) plt
    logical :: free
    character(4), public :: date
  end type indicator

  type card
    type (indicator) indic
    integer fparam
    integer, private :: sparam
  end type card

end module mod_1
        

используется в головной программе.

Объявлена переменная

type(card) cd Укажите верные варианты доступа к полям производного типа.

Ответ:

 (1) cd.sparam 

 (2) cd.fparam 

 (3) cd.indicator.free 

 (4) cd.indic.plt.x1 

 (5) cd.indic.plt.color(1:100:4) 


Упражнение 5:
Номер 1
Дан модуль, который используется в головной программе

module mod_1
  type maps
    integer x,y
    integer color
    logical, private :: status
  end type maps

  type, extends (maps) :: e_maps
    integer segment
    character, private :: code
  end type e_maps

end module mod_1
        

В головной программе объявлена переменная

type (e_maps) EM Укажите верные варианты доступа к полям производного типа из головной программы.

Ответ:

 (1) EM.code 

 (2) EM.segment 

 (3) EM.color 

 (4) EM.status 

 (5) EM.maps 


Номер 2
Дан модуль, который используется в головной программе

module mod_1
  type rectangle
    integer x1,y1,x2,y2
    integer color
    character, private :: name
  end type rectangle

  type, extends (rectangle) :: roundrect
    integer radius
    real, public :: center
  end type roundrect

end module mod_1
        

В головной программе объявлена переменная

type (rectangle) rct Укажите верные варианты доступа к полям производного типа из головной программы.

Ответ:

 (1) rct.roundrect 

 (2) rct.name 

 (3) rct.center 

 (4) rct.rectangle 

 (5) rct.x1 


Номер 3
Дан модуль, который используется в головной программе

module mod_1
  type person
    integer year
    character(64), private ::  name="ABC"
    character(64), private :: sname="DEF"
  end type person

  type, extends (person) :: student
    logical, private :: status
    character, public :: group
  end type student

end module mod_1
        

В головной программе объявлена переменная

type (person) ps type (student) st Укажите верные варианты доступа к полям производного типа из головной программы.

Ответ:

 (1) ps.year 

 (2) st.person 

 (3) st.group 

 (4) st.status 

 (5) ps.status 


Номер 4
Дан модуль, который используется в головной программе

module mod_1
  type person
    integer, public :: year
    character(64), private ::  name="ABC"
    character(64), public :: sname="DEF"
  end type person

  private person

  type, extends (person) :: student
    logical,  public :: status
    character, private :: group
  end type student

end module mod_1
        

В головной программе объявлена переменная

type (student) st Укажите верные варианты доступа к полям производного типа из головной программы.

Ответ:

 (1) st.person 

 (2) st.person.name 

 (3) st.year 

 (4) st.status 

 (5) st.person.year 


Номер 5
Дан модуль, который используется в головной программе

module mod_1
  type rectangle
    integer x1,y1,x2,y2
    integer, private :: color
    character(16), private :: name = "REC_0001"
  end type rectangle

  type, extends (rectangle) :: roundrect
    integer r1, r2
    real    center
  end type roundrect

end module mod_1
        

В головной программе объявлена переменная

type (roundrect) rc Укажите верные варианты доступа к полям производного типа из головной программы.

Ответ:

 (1) rc.x1 

 (2) rc.name 

 (3) rc.rectangle 

 (4) rc.color 

 (5) rc.center 


Упражнение 6:
Номер 1
Объявлены следующие типы и переменные.

  type sma
    real p(100)
    real mid(100)
    logical res
  end type sma

  type, extends (sma) :: ssma
    real middle
  end type ssma

  type uma
    type (sma) sm(100)
    complex p(100)
    logical ret
    character bis
  end type uma

  class (sma), pointer :: polym
  type (uma),  target  :: um1
  type (ssma), target  :: ssm1
        
        Какие справедливы прикрепления ссылки polym?
        

Ответ:

 (1) polym=>um1.sm(50) 

 (2) polym=>um1 

 (3) polym=>ssm1 

 (4) polym=>um1.sm(1:100:4) 

 (5) polym=>null() 


Номер 2
Объявлены следующие типы и переменные.

  type cell
    real next
    real prev
    logical stat
  end type cell

  type, extends (cell) :: object
    integer code
    real    dist
    real    radius
  end type object

  type grid
    type (object) object
    integer n
    integer xa,xb,ya,yb
  end type grid

  class (*), pointer :: polym
  class (cell),  pointer  :: ptc
  type  (grid),  target   :: ptg
        
Какие справедливы прикрепления ссылок ?
        

Ответ:

 (1) polym => ptc 

 (2) ptc => ptg.object 

 (3) polym => ptg.object 

 (4) polym=>um1.sm(1:100:4) 

 (5) polym => ptg 


Номер 3
Объявлены следующие типы и переменные.

  type grid
    integer adr
    real alfa
    real beta
  end type grid

  type, extends (grid) :: flow
    integer coord
    real    dist
    real    param
  end type flow

  type regime
    type (flow) flw
    real, allocatable :: ux(:,:,:), uy(:,:,:), uz(:,:,:)
    real  R1, R2, R3
  end type regime

  class(*), pointer :: polym
  class(regime), pointer :: pol_reg
  type(flow), target   :: pol_flw
        
Какие справедливы прикрепления ссылок ?
        

Ответ:

 (1) polym => pol_flw.grid 

 (2) pol_reg => pol_flw.flw 

 (3) polym => pol_reg 

 (4) pol_reg => pol_flw 

 (5) polym => pol_flw 


Номер 4
Объявлены следующие типы и переменные.

  type cell
    real next
    real prev
    logical stat
  end type cell

  type object
    integer code
    real    dist
    real    radius
  end type object

  type grid
    type (object) object
    type (cell)   cell
    integer xa,xb,ya,yb
  end type grid

  class (*), pointer :: polym
  class (cell),  pointer  :: ptc
  type  (grid),  target   :: ptg
        
Какие справедливы прикрепления ссылок ?
        

Ответ:

 (1) polym => ptg.cell 

 (2) ptc => ptg.cell 

 (3) ptc => ptg.object 

 (4) ptc => ptg.cell.next 

 (5) polym => ptg.cell.next 


Номер 5
Объявлены следующие типы и переменные.

  type grid
    integer adr
    real alfa
    real beta
  end type grid

  type, extends (grid) :: flow
    integer coord
    real    dist
    real    param
  end type flow

  type, extends (flow) :: regime
    real, allocatable :: ux(:,:,:), uy(:,:,:), uz(:,:,:)
    real  R1, R2, R3
  end type regime

  class(*), pointer :: polym
  class(grid), pointer :: pol_grd
  type(flow), target   :: flw
        
Какие справедливы прикрепления ссылок ?
        

Ответ:

 (1) pol_grd=>flw 

 (2) polym => flw.dist 

 (3) pol_grd => flw.param 

 (4) pol_grd => flw.grid 

 (5) polym => flw.grid.beta 


Упражнение 7:
Номер 1

В головной программе используется модуль geom, который содержит только тип triangle и модульную процедуру Square. Головная программа использует модуль geom. В головной программе объявлена переменная type (triangle) TR.

Укажите верное описание типа triangle и процедуры Square, для организации вызова write(*,*) TR.Square() из головной программы


Ответ:

 (1) type triangle real x1,y1,x2,y2,x3,y3 contains procedure, pass :: Square end type triangle  

 (2) real function Square(tr) type(triangle) tr Square=abs((tr.x1-tr.x2)*(tr.y3-tr.y2)-(tr.y1-tr.y2)*(tr.x3-tr.x2))/2 end function Square  

 (3) type triangle real x1,y1,x2,y2,x3,y3 contains procedure, nopass :: Square end type triangle  

 (4) subroutine Square type(triangle) tr write(*,*) abs((tr.x1-tr.x2)*(tr.y3-tr.y2)-(tr.y1-tr.y2)*(tr.x3-tr.x2))/2 end subroutine Square  

 (5) real function Square(tr) class(triangle) tr Square=abs((tr.x1-tr.x2)*(tr.y3-tr.y2)-(tr.y1-tr.y2)*(tr.x3-tr.x2))/2 end function Square  


Номер 2

В головной программе используется модуль geom, который содержит только тип circle и модульную процедуру IncRadius. Головная программа использует модуль geom. В головной программе объявлена переменная type (circle) CR.

Укажите верное описание типа circle и процедуры IncRadius, чтобы при вызове call CR.IncRadius(10.0) из головной программы, поле R переменной CR было изменено.


Ответ:

 (1) subroutine IncRadius(dR) type(circle) cr real dR cr.R=cr.R + dR end subroutine IncRadius  

 (2) subroutine IncRadius(cr, dR) class(circle) cr real dR cr.R=cr.R + dR end subroutine IncRadius  

 (3) type circle real, public :: x,y real, private :: R contains procedure, nopass :: IncRadius end type circle  

 (4) type circle real, public :: x,y real, private :: R contains procedure :: IncRadius end type circle  

 (5) subroutine IncRadius(cr,dR) type(circle) cr real dR cr.R=cr.R + dR end subroutine IncRadius  


Номер 3

В головной программе используется модуль peoples, который содержит только тип person и модульную процедуру PrintInfo. Головная программа использует модуль peoples. В головной программе объявлена переменная type (person) PS.

Укажите верное описание типа person и процедуры PrintInfo, чтобы при вызове call PS.PrintInfo() из головной программы, отображалась информация, содержащаяся в полях переменной PS.


Ответ:

 (1) subroutine PrintInfo(PS) class(person) PS write(*,*) "FIO = ", PS.fio write(*,*) "flag = ", PS.flag write(*,*) "year = ", PS.year end subroutine PrintInfo  

 (2) subroutine PrintInfo(PS) type(person) PS write(*,*) "FIO = ", PS.fio write(*,*) "flag = ", PS.flag write(*,*) "year = ", PS.year end subroutine PrintInfo  

 (3) type person character(128) fio logical, private :: flag integer, private :: year contains procedure, pass :: PrintInfo end type person  

 (4) type person character(128) fio logical, private :: flag integer, private :: year contains procedure, nopass :: PrintInfo end type person  

 (5) type person character(128) fio logical :: flag integer :: year contains procedure, nopass :: PrintInfo end type person  


Номер 4

В головной программе используется модуль farm, который содержит только тип animal и модульную процедуру PrintTitle. Головная программа использует модуль farm. В головной программе объявлена переменная type (animal) AN.

Укажите верное описание типа animal и процедуры PrintTitle, для организации вызова call AN.PrintTitle() из головной программы.


Ответ:

 (1) type animal character(64) name logical, private :: status integer, private :: age contains procedure, nopass :: PrintTitle end type animal  

 (2) type animal character(64) name logical, private :: status integer, private :: age contains procedure, pass :: PrintTitle end type animal  

 (3) subroutine PrintTitle() type (animal) an write(*,*) "****************" write(*,*) "* ANIMAL *" write(*,*) "****************" end subroutine PrintTitle  

 (4) subroutine PrintTitle() write(*,*) "****************" write(*,*) "* ANIMAL *" write(*,*) "****************" end subroutine PrintTitle  

 (5) type animal character(64) name logical :: status integer :: age contains procedure :: PrintTitle end type animal  


Номер 5

В головной программе используется модуль geom, который содержит только тип figure и модульную процедуру Modify. Головная программа использует модуль geom. В головной программе объявлена переменная class (figure), allocatable :: FG.

Укажите верное описание типа figure и процедуры Modify, чтобы при вызове call FG.Modify(10) из головной программы, происходило изменение поля points в переменной FG.


Ответ:

 (1) type figure integer, private :: points(5) integer, private :: color contains procedure :: Modify end type figure  

 (2) subroutine Modify(fg, scale) class(figure) fg integer scale fg.points=fg.points*scale end subroutine Modify  

 (3) subroutine Modify(fg, scale) type(figure) fg integer scale fg.points=fg.points*scale end subroutine Modify  

 (4) type figure integer, private :: points(5) integer, private :: color contains procedure, nopass :: Modify end type figure  

 (5) type figure integer :: points(5) integer, private :: color contains procedure, nopass :: Modify end type figure  


Упражнение 8:
Номер 1
Какие имена являются процедуры привязанными к типу по имени в следующем фрагменте программы ?

  use graph
  type(plot) PLT, PLTA, PLTB
  ...
  call PLT.Create(10,10,200,200)
  PLT=.INVERSE.PLT
  write(*,*) PLTA.xcenter
  write(*,*) PLT.Radius()
  call VerifyPlot(PLTB.coords)
  write(*,*) finish(PLTA.start())
  PLT=PLTA.UNION.PLTB
  ...
  

Ответ:

 (1) Create 

 (2) NVERSE 

 (3) xcenter 

 (4) Radius 

 (5) VerifyPlot 

 (6) coords 

 (7) finish 

 (8) start 

 (9) UNION 


Номер 2
В следующем фрагменте программы, какие имена являются процедурами привязанными к типу по имени ?
  use algebra
  type (matrix) MTR, MTR1, MTR2
  real det
  ...
  call MTR.Create(10,10)
  call MTR.Random()

  call MTR1.Transpose()
  det=MTR1.determinant
  ...
  MTR=MTR1.CONVERT.MTR2

  write(*,*) MTR.value(10,2:10,10)
  ...
        

Ответ:

 (1) Create 

 (2) Random 

 (3) Transpose 

 (4) determinant 

 (5) CONVERT 

 (6) value 


Номер 3
В приведенном фрагменте программы перечислите имена пользовательских операций.
  use math
  type (matrix) MTR, MTR1, MTR2
  type (set) S1, S2, S3
  ...
  call MTR.Create(Mi,Mj)
  MTR = MTR1 + MTR2 * (MTR.Inverse())
  S2 = S1.CROSS.S3

  call MTR1.Transpose()
  det = MTR1.determinant
  ...
  S1 = S2.UNION.S3
  write(*,*) S1.value(1:100:2)
  ...
        

Ответ:

 (1) Create 

 (2) Inverse 

 (3) Transpose 

 (4) determinant 

 (5) INDEX 

 (6) UNION 

 (7) CROSS 

 (8) value 


Номер 4
В следующем фрагменте программы, какие имена не являются и могут не являться процедурами, привязанными к типу по имени?
  use grids

  type (grid_MKE) GR
  type (point) pt

  call GR.Init()
  call GR.PrintInfo()

  write(*,*) GR.coordinates(10,20)
  write(*,*) GR.next()
  write(*,*) GR.values(2,2)

  if (.NOT.GR.err) then
  ...

  pt = GR.points + pt
  ...
        

Ответ:

 (1) Init 

 (2) PrintInfo 

 (3) coordinates 

 (4) next 

 (5) values 

 (6) err 

 (7) points 


Номер 5
В следующем фрагменте программы, укажите имена перегруженных процедур и операций.
  use flow
  type (grid) GRD
  type (velocity) VX, VY, VZ
  ...
  GRID.Init()
  call GRD.Add(VX)
  call GRD.Add(VY,VZ)
  call GRD.Build(X1=0.0,Y1=0.0,X2=2.0,Y2=1.0)
  write(1,*) VX + VY, VX - VZ
  ...
  call GRD.Draw()
  ...
  call VX.VectorField(GRD)
        

Ответ:

 (1) Init 

 (2) Add 

 (3) Draw 

 (4) операция " + " 

 (5) операция " - " 

 (6) VectorField 

 (7) Build 


Упражнение 9:
Номер 1
Даны два типа

  type person
    character(64) name
    character(64) lastname
  end type person

  type robot
    character(32) mech
    integer(8)    period
  end type robot

Создайте тип office, который
  • наследует тип person
  • содержит поле типа robot, в виде одномерного динамического массива
  • содержит поле типа character(64), являющееся ссылкой
  • В ответ введите размер в байтах переменной типа office

    Ответ:

     168 


    Номер 2
    Даны два типа
    
      type grid
        real(8) x1,y1,x2,y2
        integer(8) adr
      end type grid
    
      type point
        real(8) x
        real(8) y
      end type point
    
    Создайте тип region, который содержит поля:
    
  • типа point, в виде одномерного динамического массива
  • типа real(8), в виде трехмерного динамического массива
  • В ответ введите размер в байтах переменной типа region

    Ответ:

     98 


    Номер 3
    Даны два типа описанных в модуле hydro
    
    module hydro
      type point
        real(8) x
        real(8) y
      end type point
    
      type, extends (point) :: expoint
        real(16), allocatable :: x1,y1,x2,y2
        character(8) code
      end type expoint
    ...
    end module hydro
    
    В тип expoint добавляются две модульные процедуры procA и procB. Процедуры не имеют формальных параметров. На сколько изменится размер в байтах переменной типа expoint после добавления процедур ?
    

    Ответ:

     0 


    Номер 4
    Даны два типа описанных в модуле gas_dynamics
    
    module gas_dynamics
      type grid
        real(8), allocatable :: dat(:,:,:)
        real(8), allocatable :: xcoord(:)
        real(8), allocatable :: ycoord(:)
        real(8), allocatable :: zcoord(:)
      end type grid
    
      type particle
        real(8), allocatable, private :: ux(:,:,:)
        real(8), allocatable, private :: uy(:,:,:)
        real(8), allocatable, private :: uz(:,:,:)
        real(8), allocatable, private :: tm(:,:,:)
      end type particle
    ...
    end module gas_dynamics
    
    Создайте тип plot, который:
    
  • наследует поля типа grid
  • содержит поле типа particle, в виде одномерного динамического массива
  • содержит два поля типа complex(8), в виде одномерных динамических массивов
  • В ответ введите размер в байтах переменной типа plot

    Ответ:

     276 


    Номер 5
    Даны два типа описанных в модуле gas_dynamics
    
      type base
        complex(8), allocatable :: points(:)
        logical,    allocatable :: errors(:)
        integer, private :: size
      end type base
    
      type, extends(base) :: baseX
        character(32) file
        character(32) name
        logical       stat
      end type baseX
    
    Создайте тип composite, который:
    
  • содержит поле типа baseX, в виде динамической переменной
  • содержит поле типа integer(2), в виде ссылки
  • содержит поле типа integer(8)
  • В ответ введите размер в байтах переменной типа composite

    Ответ:

     16 


    Упражнение 10:
    Номер 1
    Для типа point выберите правильный код финальной процедуры DeletePoint
    
    module flow
    integer, private :: INDEX
    
      type point
        integer x,y,z
        integer color
        logical stat    
        contains
          final :: DeletePoint    
      end type point
    
      CONTAINS
      ...
        subroutine InitFlow()
          INDEX=0
        end subroutine InitFlow
    end module flow
      
    

    Ответ:

     (1) subroutine DeletePoint(pt) type(point) pt write(*,*) pt write(*,*) "Point is deleted...." INDEX=INDEX+1 end subroutine  

     (2) subroutine DeletePoint(pt) class(point) pt write(*,*) pt write(*,*) "Point is deleted...." INDEX=INDEX+1 end subroutine  

     (3) subroutine DeletePoint() class(point) pt write(*,*) pt write(*,*) "Point is deleted...." INDEX=INDEX+1 end subroutine  

     (4) subroutine DeletePoint() type(point) pt write(*,*) pt write(*,*) "Point is deleted...." INDEX=INDEX+1 end subroutine  

     (5) subroutine DeletePoint() write(*,*) pt write(*,*) "Point is deleted...." INDEX=INDEX+1 end subroutine  


    Номер 2
    В головной программе используется модуль flow. Объявлена переменная PT типа point. Какие из процедур в типе point могут изменить приватную часть переменной PT ?
    
    module flow
    
      type point
        integer x
        integer y
        real, private :: cp
      contains
        procedure, nopass :: proc1
        procedure proc2
        procedure, pass :: proc3
        procedure, nopass :: proc4
        procedure proc5
    
        procedure show
      end type point
    
      contains
        subroutine proc1(pt,val)
          type(point) pt
          real val
          pt.cp = val
        end subroutine proc1
    
        subroutine proc2(pt)
          class(point) pt
          pt.cp=real(pt.x+pt.y)
        end subroutine proc2
    
        subroutine proc3(pt)
          class(point) pt
          integer tmp
          tmp=pt.x; pt.x=pt.y; pt.y=tmp
        end subroutine proc3
    
        subroutine proc4(pt)
          type(point) pt
          if (pt.cp<=0) write(*,*) "ERROR"
        end subroutine proc4
    
        subroutine proc5(pt,M,N,S)
          class(point) pt
          integer M,N
          real, optional :: S
          pt.x=pt.x+N
          pt.y=pt.y+M
          if (present(S)) call random_number(pt.cp)
        end subroutine proc5
    
    end module flow
            
    

    Ответ:

     (1) proc1 

     (2) proc2 

     (3) proc3 

     (4) proc4 

     (5) proc5 


    Номер 3
    Какое значение будет присвоено переменной k в результате выполнения оператора select type в следующем фрагменте программы ?
    
    type point
      integer x, y
    end type point
    
    type, extends(point) :: point_ex
      integer z
      integer color
      logical error
    end type point_ex
    
    type, extends(point_ex) :: point_phys
      real vx
      real vy
      real vz
      real tm
    end type point_phys
    
    type, extends(point_phys) :: point_mech
      character(32) name
      character(8)  code
    end type point_mech
    
    integer k
    class (*), pointer :: ptr
    type  (point_ex), target :: pt_ex
    class (point_phys), allocatable, target :: pt_ph
    class (point_mech), allocatable, target :: pt_mh
    
    allocate(pt_ph,source=point_phys(1,2,3,4,.true.,0.0,0.0,0.0,0.0))
    allocate(pt_mh,source=point_mech(5,6,7,8,.true.,0.0,0.0,0.0,0.0,"A","B"))
    
    ptr=>pt_ph
    
      select type (ptr)
        type is (point_ex);    k=ptr.x
        class is (point);      k=ptr.y
        class is (point_mech); k=ptr.color
        class default;         k=0
      end select 
    ...
    
    
    

    Ответ:

     2 


    Номер 4
    Какое значение будет присвоено переменной k в результате выполнения оператора select type в следующем фрагменте программы ?
    
    type point
      integer x, y
    end type point
    
    type, extends(point) :: point_ex
      integer z
    end type point_ex
    
    type, extends(point_ex) :: point_phys
      real vx
      real tm
    end type point_phys
    
    type, extends(point_phys) :: point_mech
      character(32) name
    end type point_mech
    
    class (point_ex), pointer :: poly
    class (point), target, allocatable :: pt
    class (point_ex), target, allocatable  :: pt_ex
    class (point_phys), target, allocatable  :: pt_ph
    class (point_mech), target, allocatable  :: pt_mh
    integer k
    
    allocate (pt, source=point(1,2))
    allocate (pt_ex, source=point_ex(3,4,5))
    allocate (pt_ph, source=point_phys(6,7,8,0.0,9.0))
    allocate (pt_mh, source=point_mech(9,10,11,0.0,0.0,"ABC"))
    
    poly=>pt_mh
    
      select type (poly)
        class is (point_ex);   k=poly.x
        class is (point_phys); k=poly.z
        class default;         k=0
      end select 
    ...
    
    

    Ответ:

     11 


    Номер 5
    Какое значение будет находиться в поле a переменной ex1 после вызова 
    call ex1.solve() в следующей программе ?
    
    module mod_1
      abstract interface
        integer function func(x)
          integer x
        end function func
      end interface
        
      type region
        integer, private :: a
        integer, private :: b
        procedure (func), pointer, nopass :: funct
        
        contains
          procedure solve
      end type region
    
    contains
      subroutine solve(rg)
        class(region) rg
        rg.a=rg.funct(rg.a)
      end subroutine solve
    end module mod_1
    
    program prog
    use mod_1
    type (region) ex1
    
    ex1.a=2; ex1.b=3; ex1.funct=>F
    call ex1.solve()
    
    contains
    
    integer function F(x)
      integer x
      F=x*x+x
    end function F
    
    END
    
    

    Ответ:

     6 




    Главная / Программирование / Программирование больших вычислительных задач на современном Фортране с использованием компиляторов Intel / Тест 2