Вы находитесь на странице: 1из 2

Good Luck, Professor M.

Moness Page 1 of 2

MINIA UNIVERSITY Faculty of Engineering
Mechatronics Program CSEn124 Comp. Programming (2)
Final Exam, May 2014 Time allowed: 3Hrs.
Attempt the following questions (Max. Degree 60)
QUESTION (I): (12 points)

Mark the following statements as true or false.
(1.1) A C++ identifier can start with a digit.
(1.2) The operands of the modulus operator must be integers.
(1.3) If a = 4; and b = 3;, then after the statement a = b; the value of b is still 3 .
(1.4) In the statement cin >> y ; y can only be an int or a double variable.
(1.5) Suppose x = 5. After the statement y = x++; executes, y is 5 and x is 6.
(1.6) Suppose a = 5. After the statement ++a; executes, the value of a is still 5
because the value of the expression is not saved in another variable.
(1.7)The extraction operator >> skips all leading whitespace characters when
searching for the next data in the input stream.
(1.8)The function ignore is used to skip certain input in a line.
(1.9)Every if statement must have a corresponding else.
(1.10)The expression in the if statement:
if (score = 30)
grade = 'A';
always evaluates to true.
(1.11)It is possible that the body of a while loop may not execute at all.
(1.12) In C++, both ! and != are logical operators.

QUESTION (II) : (10 points)
Write a C++ program to compute the nth Fibonacci number from the
following relations:
f(1) = 1 , f(2) = 1 and f(n) = f(n-1) + f(n-2) , n >2 .

Good Luck, Professor M. Moness Page 2 of 2

QUESTION (III) : (11 points)
Evaluate the following expressions:
a. (2 + 4) % 6 b. (2*5) % 3 c. (6*2/4) % 1.5
d. 5 + 6 = = 3 + 7 e. (2 * 6 4 >= 9 1 f. 6.6 / 3 < 3 1.2
g. (2 *3.5) % 2 h. ((2 *3.5) *2) *3 i. static_cast<double>(2 + 3)
j. static_cast<double>((2/3) k. static_cast<int>(3.5) / 2

QUESTION (IV) : (12 points)
Write a C++ Program to compute the approximate value of using n terms
of the infinite series:

+

QUESTION (V): (10 points)
Write C++ statements that output Male if the gender is 'M', Female if the
gender is 'F', and invalid gender otherwise.

QUESTION (VI) : (12 points)
What are the outputs for alpha = 0, 1, 2, 3, 4, 5, 6 and 7?
# include <iostream>
using namespace std;
int main ()
{
int alpha,alphaOld;
cout<<"Please enter alpha :"; cin >> alpha; cout<<endl;
alphaOld = alpha;
switch (alpha % 7)
{
case 0: alpha--; break;
case 1: case 2: alpha = alpha * 2; break;
case 3: break;
case 4:
alpha = alpha - 5;
case 5: alpha++; break;
default: alpha = alpha / 3;
}
cout<<"Orignal_alpha % 7 (case) = " <<alphaOld%7<<endl;
cout<<"New alpha = "<<alpha<<endl;
return 0 ;
}

Вам также может понравиться