Q1/ Choose the most suitable answer: (16 Marks)
1- Which of the following statement is correct?
a- char x='s' b- char x="s"; c- char x= s; d- char x='s';
2- What is the size of double?
a- 8 bytes b- 4 bytes c- 32 bytes d- 16 bytes
3- What is the output after the following sequence of statements is executed?
a- x=6 y = 2 z= 4 b- x=2 y = 6 z= 4 c- x=4 y= 2 z= 6 d- x=2 y= 4 z= 6
4- Which of the following is Not relational operators in C#.NET?
a- >= b- <= c- < >= d- *
5- The following code is used to print the ---------- :
a- Even positive number b- Even negative number c- Odd positive number
d- Odd negative number e- None of the answers.
6- What is the output after the following sequence of statements is executed?
(Assume that : x = 9 , y= 2)
a- first b- first end c- second end d- second
7- The following box denotes?
a) Decision
b) Initiation
c) Initialization
d) I/O
8- The default case is required in the --------------- structure.
a- switch b- if – else c- for statement d- while statement
Q2/ (Answer only one) (7 Marks)
A) Write a C# program to find the value of z using switch statement :
z = {
2xy + x if i= 1
3xy − x if i= 2
4xy/x if i= 3
5xy ∗ x if i= 4
}
Sol//
B) Draw a flowchart and write C# program to calculate area for rectangle and test if the area is greater than 50 or not?
Sol//
Flowchart for Rectangle Area Calculation
+--------------------+
| Start |
+--------------------+
|
V
+--------------------+
| Enter length (L) |
+--------------------+
|
V
+--------------------+
| Enter width (W) |
+--------------------+
|
V
+--------------------+
| Area = L * W |
+--------------------+
|
V
+--------------------+
| Area > 50? (Yes/No) |
+--------------------+
| Yes
V |
+--------------------+
| Print "Area > 50" |
+--------------------+
| No
V |
+--------------------+
| Print "Area <= 50" |
+--------------------+
|
V
+--------------------+
| End |
+--------------------+
C# Program for Rectangle Area Calculation
Q3/ (Answer only two) (7 Marks)
Sol//
B) Draw a flowchart to read two numbers x and y , and swap the two numbers if x divided by 4 .
Sol//
+----------------+
| Start |
+----------------+
v
+----------------+
| Read number x |
+----------------+
v
+----------------+
| Read number y |
+----------------+
v
+----------------+ +-----------------------+
| Is x divisible | | Yes (Swap) |
| by 4 (x % 4==0)? | ----> | Swap temporary = x; |
+----------------+ | x = y; |
v | y = temporary; |
+----------------+ +-----------------------+
v v
+----------------+ +----------------+
| No | ----> | Print x and y |
+----------------+ | (unchanged) |
v +----------------+
+----------------+ | End |
| Print x and y | v
+----------------+ +----------------+
C) Declare several variables by selecting for each one of them the most appropriate of the types: 52, -115, 45.506, ‘z’, 1.4, “hello”
Sol//
1. 52: `int` (integer)
2. -115: `int` (integer)
3. 45.506: `double` (floating-point number)
4. 'z': `char` (character)
5. 1.4: `double` (floating-point number)
6. "hello": `string` (sequence of characters)
So, the declaration for these variables would be:
(الجزء العملي) Practical
Note: Answer only one question (12 Marks)
Q1/ Write a C# program to read two integer numbers (a, b) and swap the two numbers if a and b are odd and a is divided by 5.
Sol//
Q2 / Write a C# program to read the student’s name, gender, three scores and find the average of the scores then print “pass” when the average is greater than 50, otherwise print “failed”.
Sol//
Q1/ Choose the most suitable answer:
1-This Flowchart represents the flow control of ------- statement:
a- do-While b- while c- for d- if e- if – else
2- Choose a correct C# for loop sysntax :
a- for(declaration; incrementoperation ; condition) { //statements }
b- for(initialization , condition , incrementoperation , ) { //statements }
c- for(initialization ; condition ; incrementoperation ) { //statements }
d- for(initialization ; incrementoperation ; condition) { //statements }
3- Which loop is guaranteed to execute at least one time.
a- for b- do while c- while d- None of the above
Q2\ What is the output after the following sequence of statements is executed?
I'd be glad to explain the output of the given C# code:
int z = 9;
do {
Console.Write(z + "\t ");
Console.WriteLine(2 * z);
z = z - 2;
} while (z >= 0);
Output:
9 18
7 14
5 10
3 6
1 2
B) Write C# program to find the average of set numbers ended by number divided by 3?
Sol//
قوانين المصفوفة المربعة
main diagonal ( i == j)
triangle upper main diagonal ( i < j)
triangle lower main diagonal. ( i> j )
secondary diagonal. ( i+j == GetLength(0) -1)
ex ( i+ j == 2)
elements on main diagonal a[i,i]
elements on secondary diagonal. a[ i, GetLength(0) -1-i]
a[i,2-i]
ex1 : Write a C# program to read and print an array of two dimension [3X3] of integer numbers and print and sum of the elements on triangle upper main diagonal .
ننتبه على صيغة السؤال هنا طباعة العناصر فوق القطرية مع ايجاد حاصل جمع هذه العناصر
Sol//
Ex2 : Write a C# program to read and print an array of two dimension [3X3] of integer numbers and print the elements of row1?
ننتبه على صيغة السؤال هنا طباعة عناصر السطر الأول بالمصفوفة
Sol//
Group A
Q1) Choose the correct answer :
1-What is the output after the following sequence of statements is executed?
double z ;
A- x= 2 y = 15 z= 7.5
B- x=2 y = 15 z= 7
C- x=15 y= 2 z= 7
D- x=15 y= 2 z= 7.5
2- What is the size of short type ?
A- 2 bytes B- 4 bytes C - 8 bytes D- 16 bytes
3- Secondary storage is usually volatile, which means that it is erased when the machine is powered off.
A- TRUE B- FALSE
4-The following box denotes?
A- Input/Output B- start / end C- Decision D- Process
5- What is the output after the following sequence of statements is executed?
A- z= 11 B- z= 12 C- z= 10 D- z= 13
6-What is the output of the following codes :
A- y= -5 B- y= -4 C- y= -4.5 D- y= 4
7- Example of valid identifier is :
A- Sum 2 B- Sum-2 C- 2Sum D- Sum2
Q2\ Answer the following: A\ Write algorithm and draw a flowchart to read the student’s name and three scores and find the average of the scores then print “pass” when the average is greater than 50, otherwise print “failed”.
Sol//
Algorithm : find average
Input : name , three score
Output : find average and print pass or failed
Step1 : start
Step2 : read name , degree1 , degree2, degree3
Step3 : average = (degree1+degree2+ degree3)/3
Step 4: print name and average
Step5 : if average >= 50 print “pass” Else print “failed”
Step 6: end
B\ write C# program to find z of the following :
Sol//
Q3\Answer the following :
A\ Write the following equation in C# language and indicate the order of evaluation of the operators in the C# statement .
1. Input unit.
2. Output unit.
3. Memory unit.
4. Central processing unit (CPU). The CPU serves as the “administrative” section of the computer. This is the computer’s coordinator, responsible for supervising the operation of the other sections. The CPU has two components:
Control Unit: extracts instructions from memory and decodes and executes them
Arithmetic Logic Unit (ALU): handles arithmetic and logical operations
5. Secondary storage unit.
Group B
Q1) Choose the correct answer :
1-What is the output of the following codes :
double y = Math.Floor( -2.6 );
A- y= -3 B- y= -2 C- y= 3 D- y= -2.5
2- Example of valid identifier is :
A- Area 2 B- 2Area C- Area2 D- Area-2
3- Which of the following statement is correct?
A- string a="Ahmed " B- string a="Ahmed " ; C- string a=Ahmed ; D- string a= 'Ahmed ';
4-The following box denotes?
A- Decision B- start / end C- Process D- Input/Output
5-What is the output after the following sequence of statements is executed?
A- x= 8 y = 3 z= 5 B- x=5 y = 3 z= 8 C- x=8 y= 5 z= 3 D- x=3 y= 8 z= 5
6- What is the size of float type ?
A- 2 bytes B- 4 bytes C - 8 bytes D- 16 bytes
7- What is the output after the following sequence of statements is executed?
A- z= 10 B- z= 12 C- z= 6 D- z= 4
Q2\ Answer the following :
A\ Write algorithm and draw a flowchart to read two numbers x and y, and swap the two numbers if
x +y is even number ?
Algorithm : swap two number if x+y is even number
Input : two number x and y
Output : print x and y after swap
Step1 : start
Step2 : read x , y
Step3 : if x+y mod 2 equal 0 then t= x ; x=y ; y = t; (swap two number )
Step 4 : print x , y
Step 5: end
B\ Write C# program to find z of the following :
Sol//
Q3\ Answer the following :
A\ Write the following equation in C# language and indicate the order of evaluation of the operators in the C# statement .
B\ List the levels of programming Languages ?
Sol//
1. Machine languages
2. Assembly languages
3. High-level languages