0% found this document useful (0 votes)
37 views3 pages

GENN004 Spring2012 Midterm1

This document contains a 10 question midterm exam for an Introduction to Computers and Engineering course. The questions cover various MATLAB programming concepts such as variables, loops, conditional statements, input/output, and arithmetic operations. Sample code snippets and their expected output are provided. The exam also includes a multiple choice question and a short programming problem to write a code that counts the number of land plots with an area greater than 1000 square meters based on user input dimensions.

Uploaded by

Bishoy Emile
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

GENN004 Spring2012 Midterm1

This document contains a 10 question midterm exam for an Introduction to Computers and Engineering course. The questions cover various MATLAB programming concepts such as variables, loops, conditional statements, input/output, and arithmetic operations. Sample code snippets and their expected output are provided. The exam also includes a multiple choice question and a short programming problem to write a code that counts the number of land plots with an area greater than 1000 square meters based on user input dimensions.

Uploaded by

Bishoy Emile
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

CHS Spring 2012 Introduction to Computers and (Engineering (GENN004 Cairo University

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(%10.2f,%.3f,y,x); 1 . 1 2 , 1

0 12 )

2) After executing the following scripts, the memory will contain the following value for Z ( y=2; k=5; Z = k+4*y/4*y+3; 3) Write the shown math equation using Matlab code.
Z = 3 x 8 xy 2x + 5 y

Z=(3*x^8-x*y)/(2*x+5*y) for1 x-y 2x

4) The following is a valid variable name (circle one):

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 two different variables. ( T ) 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? ( 5 for i=0:5: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 False b. ~(x && y) True 10) What should be the value of x and y so the following loop prints exactly 5 stars?(x=1 for i=x:4x:y fprintf(*); end
Page 1

, y= 17

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:1 x=( Enter num 1 ); y=( Enter num 2 ); x+y=z; printf(z=%f); endfor For i=5:-1:1 X=input(enter num 1); Y=input(enter num 2); Z=X+Y; Fprintf(z=%f,Z); End;

Question 3: [3 pt] What is the output of the following script? for i=3:-1:1 for j=1:3 fprintf('%5d',i+j); end fprintf('\n'); end 4 3 2 5 4 3 6 5 4

Question 4: [4 pt] Write a matlab program to count the number of lands that has an area greater than 1000 m 2. The program reads first a positive number N that represents the total number of lands the user would like to test. The program prints an error message if the entered number is not positive. Otherwise the program reads the length and the width of each land one at a time, calculate its area and count those that has an area greater than 1000 m2. Then the program prints to the screen, the number of large lands. The input and output of the program should be as shown below. Sample Inputs/Outputs: Enter N: 0 Error! Re-enter N: -1 Error! Re-enter N: 3 Enter length: 100 Enter height: 100 Enter length: 10 Enter height: 20 Enter length: 200 Enter height: 10 Num of large areas = 2
Page 2

CHS Spring 2012 Introduction to Computers and (Engineering (GENN004 Cairo University N=input(Enter N); While N<=0 N=input(Error!! Re-enter N:); End Count=0; For i=1:N L=input(Enter Length); W=input(Enter Width); A=L*W; If A>1000 Count=Count+1; end end fprintf(Number of large areas= %d, Count);

Midterm Exam

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

Page 3

You might also like