TFG - oa.upm.esoa.upm.es/50279/1/TFG_Cuervo_Cuervo_Sonia.pdf · 1 1. 1 1 1 1 1 à 1 1 ¤ 1 1 1 1 1 1 ,
GENN004_Fall2011_V1(1)
-
Upload
bishoy-emile -
Category
Documents
-
view
214 -
download
0
Transcript of GENN004_Fall2011_V1(1)
7/29/2019 GENN004_Fall2011_V1(1)
http://slidepdf.com/reader/full/genn004fall2011v11 1/8
Fall 20118 /1GENN004 – Final Exam
Computer Engineering Department.Faculty of Engineering
Cairo University
Introduction to Computers and Engineering (GENN004)Final Exam – CHS – Fall 2011
(2 hours)
Total Marks: 40
Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Total (40)
Question 1: [10 pt] Choose the correct answer. Clearly circle only one answer.
1) If a1 is true and a2 is false, then which of the following expressions is false?o ~a1 || a2o ~(a1 && a2)o a1 || a2o a1 && ~a2
2) Which of the following statement is false?o Developers are allowed to define their own functions in MATLAB.o The statement x1 == x2 makes the value of variable x2 equal to the value of
variable x1o MATLAB considers capital X and small x as two different variables.o Developers are allowed to use nested if statements in MATLAB
3) Which of the following statements will print the following output without the outer boxto the screen.
***********Total= 35 LE
o total = 34.792 ; f printf(‘***********\nTotal=%7f LE\n’,ceil(total)) ;o total = 34.792 ; f printf(‘***********\nTotal=%7.0f LE\n’,total) ;o total = 34.792 ; f printf(‘***********\nTotal=%-7.0f LE\n’,total) ;o total = 34.792 ; f printf(‘***********\nTotal=%.0f LE\n’,total) ;
4) Consider the following matrix:X = [ 1, 7, 4 ; 8, 5, 6 ; 3, 2, 9 ] ;
What will be the value of X(2,3) after executing the following statement:
X(2,3) = X(2,3) * X(1,2) + X(2,3) / X(1,3) * X(3,2) ;o 6
o 45o 20o None of the above
7/29/2019 GENN004_Fall2011_V1(1)
http://slidepdf.com/reader/full/genn004fall2011v11 2/8
Fall 20118 /2GENN004 – Final Exam
5) Which of the following is not a valid variable name?
o floorYo forloopo Pseudo_Code
o x#0
6) What would appear on the screen after the execution of the following statements:p = 1 ; for count = 1:5
p = p * count ; endfprintf("p = %d\n", p) ;
o p = 720o p = 5
o p = 120o None of the above
7) The expression (~ ( 3 – rem(4,3) < 5 && 6 / 4 < 3 ) ) iso Invalido Trueo Falseo None of the above
8) The following is a correct for statement.o for 0:1:10o for i=10:-1o for i=0:-1:10o for i=10:0
9) The math equation
can be written in matlab as follows:
o Z=(3*x+5*y)/2*x+2*x*yo Z=(3*x+5*y)/(2*x)+2*x*yo Z=3*x+5*y/2*x+2*x*yo None of the above
10) Consider the following array:int X = [ 11, 12, 13 ; 21, 22, 23; 31, 32, 33; 41, 42, 43 ] ;
What will be the value of X(1:2:4, end)
o [11, 12, 13; 21, 22, 23; 41, 42, 43]o [13 ; 23; 43]o [13 ; 33]o None of the above
7/29/2019 GENN004_Fall2011_V1(1)
http://slidepdf.com/reader/full/genn004fall2011v11 3/8
Fall 20118 /3GENN004 – Final Exam
Question 2: [10 pt]2.a) [3 pt] What is the output of the shown program:
X=[1 2 3 4 5 6]; L=length(X);
for i = 1 : L/2 tmp=X(i); X(i)=X(L-i+1); X(L-i+1)=tmp;
end
disp(X)
Solution:
2.b) [3 pt] The following program reads 10 numbers from the user, inserts them in anarray, and computes and displays the average of these 10 numbers. The program haserrors. Correct the program so that it compiles and functions correctly. Hint: You need to make at least 6 changes.
N=10
for i = 0 : N
arr[i]=(‘Enter value :’, ‘s’) ;
sum = sum + arr[i] ;
endfor average = sum \ N ;
fprintf(‘average = %d\n’, avg) ;
end
7/29/2019 GENN004_Fall2011_V1(1)
http://slidepdf.com/reader/full/genn004fall2011v11 4/8
Fall 20118 /4GENN004 – Final Exam
2.c) [4 pts] Write a function that takes as an input an array A and returns the number of positive, negative and zero elements in three variables p, n, and z respectively.
7/29/2019 GENN004_Fall2011_V1(1)
http://slidepdf.com/reader/full/genn004fall2011v11 5/8
Fall 20118 /5GENN004 – Final Exam
Question 3: [10 pt]Study carefully the following program:
x=input('Enter first number:'); op=input('Enter an operation + or -:','s');
y=input('Enter second number:'); z=input('Enter your answer:'); if op=='+'
answer=x+y; else
answer=x-y; end if answer==z
fprintf('correct answer\n'); else
fprintf('try again\n'); end
1) [2 pts] What is the purpose of this program?
2) [2 pts] Modify the previous program to print to the user the correct answer if hisanswer is wrong. [Rewrite the modified statements only]
7/29/2019 GENN004_Fall2011_V1(1)
http://slidepdf.com/reader/full/genn004fall2011v11 6/8
Fall 20118 /6GENN004 – Final Exam
3) [2 pts] Extend the previous program to support the multiplication and the divisionoperation. [Rewrite the modified statements only]
4) [4 pts] Modify the previous program to give the user 8 chances to try again. If theuser is not able to get the correct answer after the 8 trials, then the program printsthe correct answer. [Rewrite the entire program]
7/29/2019 GENN004_Fall2011_V1(1)
http://slidepdf.com/reader/full/genn004fall2011v11 7/8
Fall 20118 /7GENN004 – Final Exam
Question 4: [10 pt]Write a program to solve the following problem:
The program reads from the user two arrays, the first array contains unknown number of elements while the second array (pattern) contains exactly two elements. The
program searches the first array to count and record all occurrences of the secondarray. Then it prints how many times the second array (pattern) is found and where.The program should also ask the user to continue or not and according to the user decision the program re-ask the user to enter the arrays or to stop and say Good Bye!.
The input and output of the program should look like the shown example.
Example:
Enter array: [1 2 3 4 5 6 7 8 1 2 3 1 2 3 ]Enter pattern: [1 2]
The pattern is found 3 time(s) at the following positions1 9 12
Do you want to continue (y/n):y
Enter array: [1 2 3 4 5 6 7 8 1 2 3 1 2 3 ]Enter pattern: [1 6]The pattern is not found
Do you want to continue (y/n):y
Enter array: [1 2 3 4 5 6 7 8 1 2 3 1 2 3 ]Enter pattern: [8 1]The pattern is found 1 time(s) at the following positions8
Do you want to continue (y/n):n
Good Bye!
7/29/2019 GENN004_Fall2011_V1(1)
http://slidepdf.com/reader/full/genn004fall2011v11 8/8
Fall 20118 /8GENN004 – Final Exam