الشرح التفصيلي لجميع شرائح المحاضرة (Slide-by-Slide) مدعوم بشرح الأكواد سطراً بسطر والتريكات الهامة
1. Which OOP principle is mainly responsible for hiding the internal state (data) and requiring all interaction to be performed through an object's methods?
2. In C++, if no access specifier (public, private, protected) is declared at the beginning of a class, the members are by default:
1. What access specifier should you use in a base class if you want the data to be hidden from the outside world, but still accessible to derived (child) classes?
2. What is the correct syntax in C++ to make a class 'Dog' inherit publicly from a class 'Animal'?
1. What keyword in C++ is used in a base class to allow a function to be overridden in a derived class, enabling Polymorphism?
2. If you want to reuse existing code to build a new class with additional features, which OOP principle are you applying?
private عشان نخفي الداتا، و public للدوال اللي بتتعامل معاها.private مخفي عن أي حد بره الكلاس (حتى أبناءه). لكن الـ protected مخفي عن العالم الخارجي بس متاح لأي كلاس بيورث منه (Child Class). دي نقطة بتيجي 100% في الامتحان!virtual في الكلاس الأب.Question: Briefly define the four main principles of Object-Oriented Programming (OOP). Give a short real-world analogy for each.
Q1:
Q2:
Q1: Write a setter function called setName that takes a string parameter and assigns it to a private member called name.
Q2: Write a getter function called getAge that returns the value of a private integer member called age.
Q3: Write a setter function with validation: setGrade accepts a float, but only assigns it to member grade if the value is between 0 and 4.
a) What is the output?
b) What will happen if we call acc.setBalance(-500);?
c) Why is balance declared as private?