PROGRAM Production_Costs !----------------------------------------------------------------------- ! This program reads the a two-dimensional array Hours whose elements ! are the number of hours required by various departments to produce ! various items. It also reads an array containing the cost per hour ! of operation in each department. It uses the intrinsic function ! MATMUL to compute an array whose elements the total costs of ! producing each of the items. Variables used are: ! NumItems : the number of rows (items) ! NumDepartments : the number of columns (departments) ! Hours : a NumItems X NumDepartments allocatable array: ! Hours(I,J) is the number required for item I ! by department J ! HourlyCost : a NumDepartments X 1 allocatable array in which the ! I-th entry is the hourly cost of operation by ! department I ! TotalCost : Hours * HourlyCost. Its I-th element is the ! total cost of producing item I ! Item, Dept : row, column subscripts ! ! Input: NumItems, NumDepartments, Hours, and HourlyCost ! Output: TotalCost !----------------------------------------------------------------------- IMPLICIT NONE INTEGER, DIMENSION(:, :), ALLOCATABLE :: Hours, HourlyCost, TotalCost INTEGER :: NumItems, NumDepartments, Item, Dept ! Read values for NumItems and NumDepartments and allocate arrays ! Hours, HourlyCost, and TotalCost PRINT *, "Enter the number of items produced and the number of & &departments:" READ *, NumItems, NumDepartments ALLOCATE(Hours(NumItems, NumDepartments)) ALLOCATE(HourlyCost(NumDepartments, 1)) ALLOCATE(TotalCost(NumItems, 1)) ! Read the arrays Hours and HourlyCost PRINT *, "Enter the hours table in rowwise order:" READ *, ((Hours(Item, Dept), Dept = 1, NumDepartments), & Item = 1, NumItems) PRINT *, "Enter the ", NumDepartments, " hourly costs:" READ *, (HourlyCost(Item, 1), Item = 1, NumDepartments) ! Calculate and display the array TotalCost PRINT * TotalCost = MATMUL(Hours, HourlyCost) DO Item = 1, NumItems PRINT '(1X, "Cost of item", I2, " is $", I6)', Item, & TotalCost(Item,1) END DO STOP END PROGRAM Production_Costs