0% found this document useful (0 votes)
47 views

Cs 0411 Midterm Examination: March 3, 2010 Duration: One and Half Hours

This document contains an 8 problem midterm exam for a CS 0411 course. The exam is 1.5 hours long and allows students to bring one information sheet. Problems include filling in missing lines of UNIX commands, identifying valid Fortran constants and assignment statements, evaluating Fortran expressions, determining output of Fortran code segments, completing a Fortran function, and writing a Fortran program to calculate teacher salaries with inflation.

Uploaded by

Ahmad Abba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Cs 0411 Midterm Examination: March 3, 2010 Duration: One and Half Hours

This document contains an 8 problem midterm exam for a CS 0411 course. The exam is 1.5 hours long and allows students to bring one information sheet. Problems include filling in missing lines of UNIX commands, identifying valid Fortran constants and assignment statements, evaluating Fortran expressions, determining output of Fortran code segments, completing a Fortran function, and writing a Fortran program to calculate teacher salaries with inflation.

Uploaded by

Ahmad Abba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CS 0411 MIDTERM EXAMINATION

March 3, 2010

Duration: one and half hours

Student Name: Answer

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

The valid Fortran constants are: (b) (c) (d) (e)

2
Problem 3. 8 marks
Indicate which of the followings are valid Fortran assignment statements:

(1) Gama = 6.278


(2) N = N * N + N
(3) A + B = C
(4) ch = 23.4 + "3.14"
(5) B = 45.0E-6
(6) Al = "plus"(3:)//"5.8"
(7) - C = 6.283
(8) ID = REAL(123)/0.89**2

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:

(1) 10/4 + 2*2/3


(2) 3.0+4.0/2.0**2
(3) 64.0**1/2
(4) Name(3:9) !where Name="cs0411"//"midterm"

The values are:

(1) 3 (2) 4.0 (3) 32.0 (4) 0411mid

3
Problem 5. 16 marks
Convert the following mathematical formulas to Fortran expression:

(1) √cos α−24t


10t
+ 3.5t.
αt+100

(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:

integer :: a=4, b=3, c=1


If (.not.(a > b).or.(a<=c)) then
print*,a+b+1
else if(.not.(a > b+c)) then
print*,a
else
print*,a+c
end if

The output is: 4

Character(10) :: Name="John Q. Doe", Cours="Fortran 90"


real :: mid=19.5, assin=25.5, fin=43.5
print 10, Name, Cours,"Assignments:",assin,"Midterm",mid,"Final exam:",fin,&
mid+assin+fin
10 Format(1x,"Name:",A,"Course:",A / 3(1x,A,f4.1) / T20, "Grade:",f4.2)

The output is: (Using ∅ to indicate a blank)

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

Complete the program.

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

Assume the input is −3.2, write down the output below:

The value of f( -3.20)= 10.00

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:

John Q. Doe has been teaching 25 years. Salary: $ 80000 /year.

The sourse codes are as follows.

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

You might also like