Question Largest Score Actual Score Q1 7 Q2 8 Q3 7 Q4 10 Q5 8

King Abdulaziz University
Faculty of Engineering
Structured Computer Programming
EE 201
Final Exam
(Monday, 5 Rabii І 1435, 6 January, 2013)
NAME :……………………………………………………………………..……… ID : ……………………………
INSTRUCTIONS:





Do not write anything on the cover page except your name and the University ID number
You can use any type of pens or pencils except the red ones.
Do not remove any paper from the answer sheets.
Do not use calculators, mobiles, books, notes, or external blank papers.
Maximum time allowed is 2 hour.
Good Luck…
Question
Q1
Largest Score
7
Q2
Q3
Q4
Q5
8
7
10
8
Total
40
1
Actual Score
Q1: Write a MATLAB program that inputs a positive number of seconds and return the number
of hours, the number of minutes and the number of seconds.
An example of running the program is:
x=input ('Enter a positive number of seconds: ');
xm=mod(x,3600);
h=(x-xm)/3600;
m=(xm-mod(xm,60))/60;
s=mod(xm,60);
1 Mark
1 Mark
1 Mark
1 Mark
disp(['the number of Hours is: ' num2str(h)])
disp(['the number of Minutes is: ' num2str(m)])
disp(['the number of Seconds is: ' num2str(s)])
2
1 Mark
1 Mark
1 Mark
Q2: Write a MATLAB program that prompts the user to enter a matrix (A) and generates and
displays the B matrix which is the transpose of the „A‟ matrix without using the transpose
operator (‘)
Hint: use loops
An example of running the program is:
.
A=input('Enter a Matrix: ');
[m,n]=size(A);
1 Mark
1 Mark
for i=1:m
for j=1:n
B(j,i)=A(i,j);
end
end
1 Mark
1 Mark
disp('the transpose of the entered matrix is: ')
disp(B)
1 Mark
2 Marks
3
1 Mark
Q3: In statistics, the number of combinations of a group of n objects taken r at a time is:
a) Write a Matlab user defined function named “FACT” that takes one number and returns the
factorial of this number
b) Write a Matlab program that inputs 2 positive numbers n and r and computes the number of
combinations
using the user defined function of the part „a‟
a)
function f=FACT(n)
f=1;
for i=1:n
f=f*i;
end
end
3 Marks
b)
n=input('Enter the first number: ')
r=input('Enter the second number: ')
1 Mark
C=FACT(n)/(FACT(r)*FACT(n-r));
2 Marks
disp('the number of combinations of n taken r is: ')
disp(C);
1 Mark
4
Q4:
a) Complete the flowchart of the following MATLAB code
b) Identify the correct screen display, for the following MATLAB code:
x=2
y=6
i=1 ;
while i<=y
z1=2*i+x
i=i+1;
if i==4
continue
end
if i==6
break
else
x=2*x
end
A(i)=z1;
end
disp(A)
Start
x=2
y=6
i=1 ;
A(i)=z1 ;
z1=2*i+x
i<y
i=i+1;
b)
i=4
Disp #
Screen Display
1
x=2
2
y=6
0.5
3
z1=4
0.5
4
x=4
0.5
5
z1=8
0.5
6
x=8
0.5
7
z1=14
0.5
8
z1=16
0.5
9
x=16
0.5
10
z1=26
0.5
11
A=[0 4 8 0 16]
0.5
i=6
x = x*2
Disp (A)
END
5
5 Marks
Q5. The Amplitude modulation (AM) is a technique used in electronic communication for
transmitting information via a radio carrier wave. AM works by varying the amplitude of the
transmitted signal in relation to the information being sent.
The equations of the carrier signal, the original signal to send, and the modulated signal
combining the two signals are respectively:
V1=Vc.sin(2.π.fc.t)
V2=Vm.sin(2.π.fm.t)
V3= Vc.sin(2.π.fc.t)+Vm.sin(2.π.fm.t)*sin(2.π.fc.t)
Supposing that Vc=1, Vm=1, fc=20, fm=1. Write a MATLAB program that plots the three
signals with the following form. Use the step 0.0025 for the time.
Hint: use subplot
6
t=0:0.0025:3;
0.5 mark
y1=sin(2*pi*20*t);
0.5 mark
y2=sin(2*pi*t);
y3=sin(2*pi*20*t)+sin(2*pi*t).*sin(2*pi*20*t);
subplot(3,1,1)
plot(t,y1)
title('The carrier Signal')
0.5 mark
0.5 mark
0.5 mark
0.5 mark
subplot(3,1,2)
plot(t,y2)
title('The Original Signal to Send')
subplot(3,1,3)
plot(t,y3)
title('The AM modulated Signal')
legend('Vc sin(2 pi fc t)+Vm sin(2
ylabel('Amplitude ')
xlabel('time (ms)')
gtext('AM Modulation')
0.5 mark
0.5 mark
0.5 mark
0.5 mark
0.5 mark
0.5 mark
pi fm t)*sin(2 pi fc t)')
0.5 mark
0.5 mark
0.5 mark
7
0.5 mark
Some Commonly Used Mathematical Functions
x
x
Some Commonly Used Built-in Functions
ceil(x)
length(A)
fix(x)
max(A)
floor(x)
min(A)
round(x)
size(A)
sign(x)
sort(A)
mod(a,b)
sum(A)
linspace (x1,x2,n)
zeros(m,n)
logspace(a,b,n)
ones(m,n)
find(A)
eye(n)
8
9