We know the secret of your success
1. Review the following code sample and the three error messages generated by the compiler, as well as a question on the purpose of the code. Identify the cause of errors by line number and description, explaining what is required to fix them; and describe the purpose of the code with a short description.
(a) Error message one: [3 marks]
(b) Error message two: [3 marks]
(c) Error message three: [3 marks]
(d) What overall action does the code for this question perform? Answers should be a brief description only (one or two sentences). [3 marks]
Answer (Purchase past paper to get the full solution)
(a) Declared dimension of array myseeds (line 9) is not equal to length of initializing list of numbers (line 12)Possible correction is to replace line 9 on:
INTEGER, DIMENSION(1:4) :: myseeds
(b) Warnings: variable i of type real is used as index of array xs on line 24 and on line 21 as loop variable.Possible correction is to replace line 10 on:
INTEGER :: i
(c) CALL word is missed in line 22. Should be
CALL RANDOM_NUMBER(temp_real)
(d) The code reads 50 numbers from input file “data.in” in array xs, makes random shuffle of array elements (using the a random j index in the range 1..n) and writes resulting array in output file “processed.out”.
2. Write a program to read in a data set of 25 values from a file, all of type REAL. Determine the minimum, mean and maximum values. These statistics should then be output to the screen. [25 marks]
You should attempt to use actual Fortran syntax. No marks are lost for incorrect spelling and, should you be stuck for the exact Fortran syntax, make use of whatever you can best recall to represent what you intend.
The code should include the following:
Define any and all variables to be used.
Open and read in data from a file named `input.dat', the data set is of type REAL and contains 25 values. It is recommended that you use an array for this step.
Determine the minimum, mean and maximum values from the data using appropriate Fortran 90 syntax. You should not assume any particular values for the input data set, for which the range is not known.
Output the minimum, mean and maximum to the screen.
3. Write a program, which prompts the user to enter an integer value, and then makes use of a random number generator to pick that number of random alpha-numeric ASCII characters to generate a random `password'. The program should use a function or subroutine to produce each individual random character. [25 marks]
You should attempt to use Fortran syntax if possible. No marks are lost for incorrect spelling and, should you not recall the Fortran syntax exactly, make use of whatever phrasing most unambiguously conveys the purpose of the operation intended.
The program should include the following:
Use a suitable message to request from the user an integer value indicating how many random characters to generate, up to a maximum of 256.
The program should then build up a string of random characters obtained making use of the random number generator facilitated by the `RANDOM_NUMBER' subroutine.
You do not need to initialise the random number generator using the `RANDOM_SEED' subroutine.
A function or subroutine of your own should generate and return a single random character anywhere within the ASCII ranges 48 to 57 (the numerals), 65 to 90 (the upper case letters) and 97 to 122 (the lower case letters), but not outside of those ranges. You must decide how to extract suitable numbers! (the probability of picking any particular character does not have to be uniform)
If you have difficulty with the previous point (anywhere within several separate ranges), aim only to extract from the range 48 to 57 (the numerals), though this will be at a loss of some marks!
This subroutine or function should then be used by the code, an appropriate number of times, to create a string of the length desired by the user.
The resulting string of random characters should then be displayed to the screen. - Hint 1: The ACHAR function takes an integer value and returns the ASCII character associated with that INTEGER, e.g. ACHAR(97) returns lowercase `a'.
Hint 2: The following code fragment will produce a random integer `c' between the values of `a' and `b'. Where a, b and c are INTEGERs and rand is a REAL: CALL RANDOM_NUMBER(rand) c =INT(rand*(b-a) + a) e.g. for a=11 and b=14; c would come out as a random INTEGER between 11 and 14 inclusive.
4. Read the following code, then determine what the output would be if the input value for n is 2, and for a are 6.1, 2.8 and 4.3 in that order. [18 marks]
Hint 1: There should be three separate lines of output; up to 6 marks are available for each of these, for a total of 18 marks; marks will be awarded for clear working even if correct values are not reached.
Hint 2: It may be helpful to tabulate the values for each of the variables as you deduce the outcome of the code.
5. Answer ALL of the following questions.
(a) Is the following array allowed, and if so how many elements would it possess? Show your working. INTEGER, DIMENSION(-1:6,-5:20,-2:2,1:40) :: myarray [2 marks]
(b) What content would be present in the file `partb.txt' after execution of the following code fragment? [2 marks]
OPEN(10,FILE='partb.txt')
WRITE(10,*) 'Not'
CLOSE(10)
OPEN(11,FILE='partb.txt')
WRITE(11,*) 'So bad'
CLOSE(11)
(c) What would be the terminal (bash) command to create a copy of a file `old_class_test.txt', calling the new one `new_class_test.txt'? [2 marks]
(d) What would be the terminal (bash) command, which would delete any file with the filename extension `.temp'? [2 marks]
(e) State one difference between FUNCTIONs and SUBROUTINEs (no more than a sentence). [2 marks]
(f) For the TYPE shown below, write a FUNCTION, which would take one variable of that type, and return the larger of tema and temb. [6 marks]
TYPE monitoring
DOUBLE PRECISION :: tema, temb
DOUBLE PRECISION :: ratea, rateb
END TYPE
(g) In a statement `DO i = a, b, c' what property of the loop do each of i, a, b and c correspond to? [4 marks]
NB: Computing Skills, 2019 past coursework answer and solution by adding to cart
Last updated: Oct 03, 2019 04:42 PM
Your one-stop website for academic resources, tutoring, writing, editing, study abroad application, cv writing & proofreading needs.