GENN004_Spring2012_Midterm2

download GENN004_Spring2012_Midterm2

of 3

Transcript of GENN004_Spring2012_Midterm2

  • 7/28/2019 GENN004_Spring2012_Midterm2

    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. Which one is an illegal variable name?

    c. dog

    d. under2dog

    a. underdog

    b. dog-1

    2. The single most important objective of this course is to learn

    c. MATLAB

    d. programming concepts

    a. solve engineering problems

    b. to be in class on time

    3. Write the following equation in one Matlab code statement:

    )52)(3(8

    2

    yxxyxZ += Z=sqrt((3*x^8-x*y)*(2*x+5*y)^2)

    4. The MATLAB output from the last MATLAB statement would be

    abc = 6;

    for i=1:2:4

    abc = abc +6;

    end

    abc =18

    5. The values that the loop variable "i" takes are

    for i = 0:0.6:3.2 0,0.6,1.2,1.8,2.4,3

    6. Evaluate the following MATLAB expressions

    b. 3 ^ 2 ^ 2=81a. 2 + ceil(6 / 9 + 3 * 2) / 2 3=2.5

    7. What is the value of h in the following cases:

    a. T = 50 h = 0 if T < 30

    h = 2*T + 1;

    b. T = 0 h = 1 elseif T < 10

    h = T 2;

    else

    h = 0;

    end

    8. What would appear on the screen after the execution of the following script:

    m=123.21;

    n=1.1252;

    fprintf('m:%8.2f:%.3f',n,m);m : 1 . 1 3 : 1 2 3 . 2 1 0

    9. Determine if the following conditions are true or false. (Show your work.)

    X= 10; y=0;

    a. X >= yTrue

    b. X == yfalse

    Page 1

  • 7/28/2019 GENN004_Spring2012_Midterm2

    2/3

    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:

    yourSelection = 11;while urSelection ~= s

    fprintf('\tI: To input a grade\n');

    fprintf('\ts: To stop\n');

    urSelection = input('Enter your choice:');

    ifurSelection == (I)

    urGrade = ('Enter your grade: ');

    maxGrade = ('Enter the maximum grade: ');

    fprintf('Your grade is %.2f ',urGrade);

    fprintf('out of %.2f = ',maxGrade);

    fprintf('%.2f%%%\n\n',urGrade/maxGrade%100 );

    end

    end

    Corrected ScripturSelection = 11;while urSelection ~= s

    fprintf('\tI: To input a grade\n');

    fprintf('\ts: To stop\n');

    urSelection = input('Enter your choice:',s);

    if urSelection == I

    urGrade = input('Enter your grade: ');

    maxGrade = input('Enter the maximum grade:

    ');

    fprintf('Your grade is %.2f ',urGrade);

    fprintf('out of %.2f = ',maxGrade);

    fprintf('%.2f%%\n\n',urGrade/maxGrade*100 );end

    end

    Question 3: [3 pt]

    What is the output of the following script?

    sum1 = 0;

    fori = 1:1:2

    forj = 1:2:2

    sum1 = sum1 + i*j;

    endend

    fprintf('sum1 = %d', sum1)

    Script Output

    Sum1=3

    Question 4: [4 pt]

    Write a script that reads positive numbers from the user, and then prints the total number of entered

    odd numbers and the sum of all entered odd numbers in the exact format as shown below in the

    example. Your script should end when

    the user enters a negative number.Sample Inputs/Outputs:

    Input :Please enter a number: 90

    Please enter a number: 13

    Please enter a number: 11

    Please enter a number: -10Output :

    Number of entered odd numbers is 2

    Sum of all entered odd numbers is 24

    End Of The Program!

    Sum=0;

    Page 2

  • 7/28/2019 GENN004_Spring2012_Midterm2

    3/3

    CHS Spring 2012

    Introduction to Computers and

    Engineering (GENN004(

    Cairo University Midterm Exam

    Time Allowed: 60 minutes

    Date: 11 April 2012

    Page 3 of 3

    Maximum Grade: 20 Points

    Count=0;

    N=input(please enter a number);

    While N>0If rem(N,2)==1

    Count=Count+1;

    Sum=Sum+N;

    End

    N=input(please enter a number);

    End

    Fprintf(Number of entered odd numbers is %d\n Sum of all entered odd numbers is %d \n

    End of program, Count, Sum);

    Page 3