This action might not be possible to undo. Are you sure you want to continue?

BooksAudiobooksComicsSheet Music### Categories

### Categories

### Categories

Editors' Picks Books

Hand-picked favorites from

our editors

our editors

Editors' Picks Audiobooks

Hand-picked favorites from

our editors

our editors

Editors' Picks Comics

Hand-picked favorites from

our editors

our editors

Editors' Picks Sheet Music

Hand-picked favorites from

our editors

our editors

Top Books

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Audiobooks

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Comics

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Sheet Music

What's trending, bestsellers,

award-winners & more

award-winners & more

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

Midterm Exam

Time Allowed: 60 minutes Date: 11 April 2012 Page 1 of 3 Maximum Grade: 20 Points

Name:

I.D.:

Group:

Question 1: [10 pts] 1) What is the output of the following code segment? x=123.21; y=1.1252; fprintf(‘%.3f,%-10.2f’,y,x); 1 . 1 2 5 , 1 2 3 . 2 1 2) After executing the following scripts, the memory will contain the following value for Z ( y=2; k=5; Z = k+4*k/4*y+3; 3) Write the shown math equation using Matlab code. xy − 3 x8 Z=(x*y-3*x^8)/(2*x)+5*y Z= + 5y 2x 4) The following is a valid variable name (circle one): 2for x-y x2x 18 )

5) True or False a. The statement x1 == x2 makes the value of variable x2 equal to the value of variable x1 ( F ) b. MATLAB considers capital X and small x as the same variable. ( F ) 6) Determine if the following condition true or false. Show your work. floor(10.8)>=abs(ceil(-10.8)) || rem(3,5) == fix(3.99) 10>=10 True || 3==3 True => the condition is True 7) How many X is printed when the following loop is executed? ( 6 for i=0:4:20 fprintf(‘X’); end )

8) What would appear on the screen after the execution of the following script: i = 1 ; 1 2 3 for x = 1:3 i = i + x ; fprintf(‘%d‘, x) ; end 9) If x is true and y is false, then which of the following expressions is true and which is false? a. ~x || ~y True b. (~x && y) False 10) What should be the value of x and y so the following loop prints exactly 5 stars?(x= 1 , y= 13 for i=x:3x:y fprintf(‘*’); end

Page 1

)

i+j). end Question 3: [3 pt] What is the output of the following script? for i=1:3 for j=3:-1:1 fprintf('%5d'. the number of speedy cars. Then the program prints to the screen. The program reads first a positive number N that represents the total number of cars the user would like to test. Sample Inputs/Outputs: Enter N: 0 Error! Re-enter N: -1 Error! Re-enter N: 3 Enter distance (km): 120 Enter time (hr): 1 Enter distance (km): 10 Enter time (hr): 1 Enter distance (km): 120 Enter time (hr): 0.CHS – Spring 2012 Introduction to Computers and (Engineering (GENN004 Cairo University Midterm Exam Time Allowed: 60 minutes Date: 11 April 2012 Page 2 of 3 Maximum Grade: 20 Points Question 2: [3 pt] Find and correct all the syntax errors in the following script: Corrected Script for i=5:2:1 x=( Enter num ‘1’ ). x+y==z. The input and output of the program should be as shown below.Z). Z=X+Y. Fprintf(‘z=%f’. endfor For i=5:-2:1 X=input(‘Enter num 1’). end fprintf('\n'). calculate its speed and count those that has a speed greater than 100 km/hr. end 4 5 6 3 4 5 2 3 4 Question 4: [4 pt] Write a matlab program to count the number of cars driving at a speed greater than 100 km/hr.8 Num of speedy cars = 2 Page 2 . printf(‘z=%f’). The program prints an error message if the entered number is not positive. Y=input(‘Enter num 2’). Otherwise the program reads the travel distance and the time of travel of each car one at a time. y=( Enter num ‘2’ ).

For i=1:N D=input(‘Enter Distance (Km)’).CHS – Spring 2012 Introduction to Computers and (Engineering (GENN004 Cairo University N=input(‘Enter N’). Midterm Exam Time Allowed: 60 minutes Date: 11 April 2012 Page 3 of 3 Maximum Grade: 20 Points Page 3 . T=input(‘Enter Time (hr)’). end end fprintf(‘Num of Speedy Cars= %d’). While N<=0 N=input(‘Error!! Re-enter N:’).Count. If S>100 Count=Count+1. S=D/T. End Count=0.

ujhi

ujhi

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue listening from where you left off, or restart the preview.

scribd