حل اسئلة امتحان اساسيات البرمجة قسم الحاسوب الجامعة المستنصرية نموذج رقم 1

codinglabsolution

نموذج رقم 1


تمر امتحان اساسيات البرمجة في قسم الحاسوب بالجامعة المستنصرية بقسمين: القسم النظري والقسم العملي. يتضمن القسم النظري عددًا من الأسئلة التي تستند إلى المفاهيم الأساسية في البرمجة، بينما يتضمن القسم العملي أسئلة تتطلب تطبيق المفاهيم النظرية في حل مشكلات برمجية.

القسم النظري

في القسم النظري، يتم تقديم الأسئلة بشكل متنوع، حيث يتضمن السؤال الأول مجموعة من الفراغات مع اختيار الإجابة الصحيحة، بينما يتضمن السؤال الثاني والثالث عدة فروع يتطلب من الطلاب تحليل الموضوع وتقديم الإجابة المناسبة.

القسم العملي

بالنسبة للقسم العملي، يتضمن سؤالين يتطلب في العادة كتابة برنامج أو حل مشكلة برمجية باستخدام لغة البرمجة المحددة في المنهج الدراسي. 



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?

int x=4 , y=2 , z;

z=x+y;

Console.WriteLine("x={1} y= {0} z={2}",x,y,z);

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 ---------- :

int num;

if (num % 2 == 0)

if (num < 0)

Console.WriteLine("num " + num);


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)

if (x > 5)

if (y > 5)

Console.Write ("first \t");

else

Console.Write("second \t ");

Console.WriteLine("end");

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//

<pre class="sq-code">

using System;

class FindZValue
{
    static void Main(string[] args)
    {
        int x, y, i;

        // Get input values from the user
        Console.Write("Enter the value of x: ");
        x = int.Parse(Console.ReadLine());

        Console.Write("Enter the value of y: ");
        y = int.Parse(Console.ReadLine());

        Console.Write("Enter the value of i (1, 2, 3, or 4): ");
        i = int.Parse(Console.ReadLine());

        double z; // Use double for potentially floating-point results

        switch (i)
        {
            case 1:
                z = 2 * x * y + x;
                break;
            case 2:
                z = 3 * x * y - x;
                break;
            case 3:
                // Check for division by zero
                if (x == 0)
                {
                    Console.WriteLine("Error: Division by zero is not allowed.");
                    return; // Exit the program if division by zero
                }
                z = (double)4 * x * y / x; // Cast to double for clarity
                break;
            case 4:
                z = 5 * x * y * x;
                break;
            default:
                Console.WriteLine("Invalid value for i. Please enter 1, 2, 3, or 4.");
                break;
        }

        Console.WriteLine("The value of z is: {0}", z);
    }
}

</pre>

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

using System;

class RectangleArea
{
    static void Main(string[] args)
    {
        double length, width, area;

        // Get input for length and width
        Console.Write("Enter the length of the rectangle: ");
        length = double.Parse(Console.ReadLine());

        Console.Write("Enter the width of the rectangle: ");
        width = double.Parse(Console.ReadLine());

        // Calculate area
        area = length * width;

        // Check if area is greater than 50
        if (area > 50)
        {
            Console.WriteLine("The area of the rectangle is greater than 50.");
        }
        else
        {
            Console.WriteLine("The area of the rectangle is not greater than 50.");
        }
    }
}


Q3/ (Answer only two) (7 Marks)

Q) Write C# program to find the value of z using the formula: using if-else
Q) Write C# program to find the value of z using the formula: using do-while

Sol//

using System;

public class FindZValue
{
    public static void Main(string[] args)
    {
        int x, y, i;
        double z; // Use double for floating-point calculations

        Console.Write("Enter the value of x: ");
        x = int.Parse(Console.ReadLine());

        Console.Write("Enter the value of y: ");
        y = int.Parse(Console.ReadLine());

        Console.Write("Enter the value of i (1, 2, or 3): ");
        i = int.Parse(Console.ReadLine());

        if (i == 1)
        {
            z = Math.Sqrt(Math.Pow(x, 2) * Math.Pow(y, 2) + x * y + 5);
        }
        else if (i == 2)
        {
            z = Math.Abs(3 * Math.Pow(x, 2) - 2 * Math.Pow(y, 2) - 5);
        }
        else if (i == 3)
        {
            if (x == 0)
            {
                Console.WriteLine("Error: Division by zero is not allowed.");
                return;
            }
            z = 4.0 * x * y / x; // Cast x to double for division accuracy
        }
        else
        {
            Console.WriteLine("Invalid value for i. Please enter 1, 2, or 3.");
            return;
        }

        Console.WriteLine("The value of z is: " + z);
    }
}

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:

int num1 = 52;
int num2 = -115;
double num3 = 45.506;
char character = 'z';
double num4 = 1.4;
string message = "hello";


(الجزء العملي) 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//

using System;

class SwapOddDivisibleByFive
{
    static void Main(string[] args)
    {
        int a, b;

        // Get input for a and b
        Console.Write("Enter the first number (a): ");
        a = int.Parse(Console.ReadLine());

        Console.Write("Enter the second number (b): ");
        b = int.Parse(Console.ReadLine());

        // Check if both a and b are odd and a is divisible by 5
        if (a % 2 != 0 && b % 2 != 0 && a % 5 == 0)
        {
            // Swap a and b
            int temp = a;
            a = b;
            b = temp;

            Console.WriteLine("After swapping (both odd, a divisible by 5):");
            Console.WriteLine($"a = {a}");
            Console.WriteLine($"b = {b}");
        }
        else
        {
            Console.WriteLine("Numbers not swapped (conditions not met).");
            Console.WriteLine($"Original a = {a}");
            Console.WriteLine($"Original b = {b}");
        }
    }
}

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//

using System;

class StudentResult
{
    static void Main(string[] args)
    {
        string name, gender;
        double score1, score2, score3, average;

        // Get student information
        Console.Write("Enter student's name: ");
        name = Console.ReadLine();

        Console.Write("Enter student's gender (M/F): ");
        gender = Console.ReadLine().ToUpper(); // Convert input to uppercase for easier comparison

        // Get scores
        Console.Write("Enter score 1: ");
        score1 = double.Parse(Console.ReadLine());

        Console.Write("Enter score 2: ");
        score2 = double.Parse(Console.ReadLine());

        Console.Write("Enter score 3: ");
        score3 = double.Parse(Console.ReadLine());

        // Calculate average
        average = (score1 + score2 + score3) / 3;

        // Determine and print result
        string result = average > 50 ? "pass" : "failed";
        Console.WriteLine($"{name} ({gender}) - Average: {average:F2} - Result: {result}");
    }
}


خاتمة:

يمثل امتحان اساسيات البرمجة في قسم الحاسوب بالجامعة المستنصرية فرصة لتقييم فهم الطلاب للمفاهيم البرمجية الأساسية وقدرتهم على تطبيقها عمليًا. يتيح الامتحان أيضًا للطلاب فرصة لإظهار مهاراتهم في التحليل والتفكير الإبداعي في مواجهة المشكلات البرمجية.


الأسئلة الشائعة


ما هي المواضيع المشمولة في الامتحان؟
يغطي الامتحان مجموعة من المفاهيم الأساسية في البرمجة، بما في ذلك أنواع البيانات، وهياكل التحكم، والدوال، والمصفوفات، والصفوف.
كيف يتم تنظيم الامتحان؟
يتم تقسيم الامتحان إلى قسمين: النظري والعملي. يتكون القسم النظري عادة من أسئلة الاختيار من متعدد وأسئلة الإجابة القصيرة، بينما يتضمن القسم العملي تمارين البرمجة أو مهام حل المشكلات.
كيف يجب عليّ أن أستعد للامتحان؟
للتحضير للامتحان، قم بمراجعة المحاضرات، والكتب الدراسية، وحل المشكلات البرمجية التمرينية. من الضروري فهم المفاهيم الأساسية بشكل جيد والقدرة على تطبيقها في سياقات مختلفة.
هل هناك أسئلة تجريبية متاحة؟
نعم، قد يتم توفير أسئلة تجريبية أو امتحانات تجريبية من قبل المحاضرين أو المتوفرة في الكتب الدراسية. بالإضافة إلى ذلك، تقدم الموارد عبر الإنترنت ومنصات البرمجة مشكلات تمرينية وتحديات برمجية تتعلق بالمفاهيم البرمجية الأساسية.
ما هي اللغات البرمجية المستخدمة في الامتحان؟
قد يتم إجراء الامتحان باستخدام لغة برمجة محددة تم تدريسها في المقرر الدراسي، مثل لغات C، C++، Java، أو Python. من الضروري أن تكون على دراية ببناء اللغة وميزاتها.
كيف يتم تقييم الامتحان؟
تختلف معايير التقييم اعتمادًا على المحاضر ومتطلبات الامتحان المحددة. عادةً ما تُمنح الدرجات استنادًا إلى الصحة والاكتمال والكفاءة والالتزام بمعايير البرمجة.
ما هي الموارد المتاحة للمساعدة الإضافية أو التوضيح؟
يمكن للطلاب أيضًا طلب المساعدة الإضافية أو التوضيح من المحاضرين أثناء وجودهم في القاعات. يمكنهم طرح الأسئلة والاستفسارات خلال فترة الامتحان والحصول على التوجيه اللازم لحل المشكلات أو الاستفسارات التي قد تطرأ.
ماذا يجب عليّ فعله إذا واجهت صعوبات خلال الامتحان؟
إذا واجهت صعوبات خلال الامتحان، فعليك البقاء هادئًا ومركزًا. حاول فهم المشكلة بعناية وتقسيمها إلى خطوات أصغر، واستخدم استراتيجيات حل المشكلات لإيجاد حل. إذا كنت ما زلت عالقًا، فلا تتردد في طلب المساعدة من المحاضر أو مشرف الامتحان.

إرسال تعليق

ملفات تعريف الارتباط
نستخدم ملفات تعريف الارتباط (Cookies) لفهم كيفية استخدامك لموقعنا وتحسين تجربتك في المحتوى والإعلانات. باستمرارك في تصفح الموقع، فإنك توافق على استخدامنا لملفات تعريف الارتباط وفقًا لسياسة الخصوصية لدينا.
أُووبس!
يبدو أن هناك خطأ ما في اتصالك بالإنترنت. يرجى الاتصال بالإنترنت وبدء التصفح مرة أخرى.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.