אתם מתרגלים שאלה מתוך מה"ט מבני נתונים ותכנות מונחה עצמים — הנדסאי תוכנהמבחן 2021 · קיץ מועד ב · שאלה 11כל שאלות המבחן ←
תכנות מונחה עצמים›תרשימי UML

csharp

class A { private static int countA = 0; protected int n;

public A(int n1)
{
    this.n = n1;
    A.countA++;
    Console.WriteLine(A.countA + " " + this.n);
}

public int GetN()
{
    return this.n;
}

public virtual void DoIt()
{
    for (int i = 0; i < this.n; i++)
        Console.Write(i + ",");
    Console.WriteLine();
}

public virtual void Print()
{
    Console.WriteLine(this.n);
}

}

class B : A { private static int countB = 0;

public B(int n2) : base(n2)
{
    B.countB++;
    Console.WriteLine(B.countB + " " + n2);
}

public override void DoIt()
{
    Console.WriteLine("B Does It!");
}

}

class C : B { private static int countC = 0; private A a;

public C(int n1, int n2) : base(n1)
{
    this.a = new A(n2);
    countC++;
    Console.WriteLine("C is " + (a.GetN() + this.n));
}

public override void Print()
{
    base.Print();
    this.a.Print();
}

}

class Test { private A[] arr;

public Test()
{
    arr = new A[3];
    arr[0] = new A(4);
    arr[1] = new B(2);
    arr[2] = new C(1, 6);
}

public void TestIt()
{
    for (int i = 0; i < arr.Length; i++)
    {
        arr[i].DoIt();
        arr[i].Print();
    }
}

}

סעיף א

בנו תרשים מחלקות UML (הכולל קשרים) עבור ארבע המחלקות המוצגות בשאלה. על התרשים לכלול את שמות המחלקות ואת הקשרים ביניהן.

סעיף ב

לפניכם קטע קוד: public static void Main(string[] args) { Test test = new Test(); test.TestIt(); } עבור קטע קוד זה בצעו והציגו את פלט הקטע (חובה להציג מעקב).

שאלות ותגובות על השאלה

🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות

שאלו כאן — ותקבלו מענה מוסמך.

🎓 מרצה לתכנות עונה כאן — תקבלו מענה מקצועי