Cs 0411 Midterm Examination: March 3, 2010 Duration: One and Half Hours
Cs 0411 Midterm Examination: March 3, 2010 Duration: One and Half Hours
March 3, 2010
Student Number:
Note. There are total 8 problems in this exam set (7 pages). This exam allows a
student to bring one information sheet prepared by herself/himself.
Problem 1. 5 marks
The following is displayed in a computer screen, which is using a UNIX operation
system. Two lines are missing. Fill these lines correctly according to the UNIX
command ls and the information provided on the screen.
——————————————————————————–
$ ls
fortran mail public_html file.f90
$ mkdir cs0411
$ mv file.f90 ./cs0411
$ cd cs0411
$ f90 file.f90 -o try.out
$ ls
file.f90 try.out
$ cp file.f90 ../file1.f90
$ cd ..
$ ls
cs0411 fortran mail public_html file1.f90
——————————————————————————–
Problem 2. 5 marks
Indicate which of the followings are valid Fortran constants:
(a) 9,999 (b) 123456789 (c) +234 (d) -23. (e) 3.00E3 (f) -+90
2
Problem 3. 8 marks
Indicate which of the followings are valid Fortran assignment statements:
The valid Fortran statements are: (1) (2) (5) (6) (8)
Problem 4. 12 marks
Find and write down the value of each of the expressions:
3
Problem 5. 16 marks
Convert the following mathematical formulas to Fortran expression:
(10.0*t*cos(a)-24.0*t)/(sqrt(a*t)+100.0)+3.5*t
q
4π 2 lh 2πt
+ sin2 2πt
(2) τ2
h2 cos4 τ τ
.
4*pi*pi*l*h/(tau*tau)*sqrt(h*h*(cos(2*pi*t/tau))**4&
+(sin(2*pi*t/tau))**2)
4
Problem 6. 18 marks
Indicate the output of the following segments of Fortran program:
Name:John Q. DoeCourse:Fortran 90
Assignments:25.5 Midterm19.5 Final exam:43.5
Grade:****
5
Problem 7. 16 marks
The following is part of a Fortran program calculating the value of f (x), where
sin(x−1)
x−1 x > 0, x 6= 1
f (x) = x x = 0 or 1
10 x<0
Program function
implicit none
real::x, fun !fun is the value of f(x)
print*,"Please input a real number x (|x|<1000):"
read*,x
!------------------------------------------------
if(x<0) then
fun=10.0
else if(x==0.0 .or. x==1.0) then
fun=x
else
fun=sin(x-1)/(x-1)
end if
!--------------------------------------------------
print’(1x,"The value of f(",f7.2,")=",f7.2)’,x,fun
!--------don’t forget the following
END PROGRAM function
6
Problem 8. 20 marks
Suppose the starting salary for a beginning teacher is $ 45,000 per year. Assume
that the continuously compounded average annual inflation rate is 5 %, but the ceiling
of the salary is $ 80,000. Write a Fortran program which reads a name of a teacher
and the number of years he/she has worked, output the current salary. The output
looks like:
Program SalaryCount
implicit none
integer::salary,years
character(20)::name
character(1)::response
implicit none
do
print*,"Name of the teacher?"
read*,name
print*,"How many years has he/she tought?"
read*,years
salary=int(real(45000)*(1+0.05)**years)
if(salary>80000) salary=80000
print 10,name,years,salary
print*,"Calculate more salary?"
read*,response
if(response/="Y") exit
end do
10 format(1x,A," has been teaching",1x,I3,1x,"years.",&
"Salary:$",I5,"/year")
end program SalaryCount