🎯 Objectives:
✓ Work with relational operators (==, !=, <, >, <=, >=)
✓ Use logical operators (&&, ||, !)
✓ Implement if, if-else, and if-else-if statements
✓ Work with relational operators (==, !=, <, >, <=, >=)
✓ Use logical operators (&&, ||, !)
✓ Implement if, if-else, and if-else-if statements
🎯 أهداف التعلم:
✓ التعامل مع المعاملات العلائقية
✓ استخدام المعاملات المنطقية
✓ تنفيذ جمل if و if-else و if-else-if
✓ التعامل مع المعاملات العلائقية
✓ استخدام المعاملات المنطقية
✓ تنفيذ جمل if و if-else و if-else-if
⚡ if statement
if (condition) { // executes if true }
🔄 if-else statement
if (condition) { // true block } else { // false block }
🔢 Relational Operatorsالمعاملات العلائقية
| Operator | Meaning (EN) | المعنى (AR) |
|---|---|---|
| > | greater than | أكبر من |
| < | less than | أصغر من |
| >= | greater or equal | أكبر أو يساوي |
| <= | less or equal | أصغر أو يساوي |
| == | equal to | يساوي |
| != | not equal | لا يساوي |
🧠 Logical Operatorsالمعاملات المنطقية
| Operator | Example | Description |
|---|---|---|
| && | (x>5) && (x<10) | Both true → true |
| || | (x<2) || (x>8) | At least one true → true |
| ! | !(x==5) | Negation (x not equal 5) |
📊 avg.cpp – Complete Program (Average & Pass/Fail)برنامج المعدل كاملاً
#include <iostream> #include <string> using namespace std; int main() { string full_name; double grade1, grade2, grade3, avg; cout << "Please enter your name: "; getline(cin, full_name); cout << "Enter the grade of the first course: "; cin >> grade1; cout << "Enter the grade of the second course: "; cin >> grade2; cout << "Enter the grade of the third course: "; cin >> grade3; avg = (grade1 + grade2 + grade3) / 3.0; cout << "Your average = " << avg << endl; if (avg >= 60) cout << full_name << " Congrats!.. You passed the semester!" << endl; else cout << full_name << " You failed the course, try harder next time!" << endl; return 0; }