C++ course

Introduction to C++

Lecture 1

Lecture 1 of the C++ course as a web page: the slides organized into sections, each with a short Arabic summary and a quick quiz, plus runnable code examples and the Sheet 1 exercises.

محاضرة 1 في مادة C++ على شكل صفحة تفاعلية: الشرح مقسّم أجزاء، وكل جزء معه ملخص وأسئلة قصيرة، وأمثلة يمكن تشغيلها مباشرة، وورقة التمارين الأولى.

Illustration of a laptop showing blocks of code, with curly braces beside it
Illustrative image.

Section 1

How computer programs work

الملخص بالعربيةالكمبيوتر لا يفهم إلا لغة الآلة (أصفار وواحدات)، ونستخدم لغات البرمجة لكتابة التعليمات، وكل سطر تعليمات يسمى سطر كود، ومجموعة التعليمات هي البرنامج.

Quick check - اختبر نفسك

What is the only language a computer understands directly?

What do we call each line of instruction sent to the computer?

Section 2

The evolution of programming languages

Programming languages fall into three broad categories.

Machine, assembly, and high-level languages compared
Machine languageAssembly languageHigh-level language
GenerationFirstSecondLater, English-like
Code looks likeBinary digits (0s and 1s)Cryptic English-like phrasesTrue English-like phrasing
Depends on the machineYes, machine dependentYes, machine dependentNo, machine independent
AdvantagesHigh speedEasier to understand and use; more control on hardwareReadability; easy debugging, maintenance, and documentation
DrawbacksComplex language, error proneHarder to learn; slow development timePoor control on hardware
الملخص بالعربيةلغات البرمجة ثلاثة أنواع: لغة الآلة (أصفار وواحدات، سريعة لكنها معقدة وتعتمد على الجهاز)، ولغة التجميع (عبارات قريبة من الإنجليزية تُترجم إلى لغة الآلة)، واللغات عالية المستوى (سهلة القراءة ومستقلة عن الجهاز).

Quick check - اختبر نفسك

Which type of language must be written entirely in 0s and 1s?

Which of these is an advantage of high-level languages?

Section 3

Program translators

الملخص بالعربيةالمترجمات ثلاثة: الـ Assembler يحوّل لغة التجميع إلى لغة آلة، والـ Compiler يترجم البرنامج كله دفعة واحدة ويحفظ الناتج ليعمل في أي وقت، والـ Interpreter يترجم وينفّذ سطراً بسطر ويتوقف عند أول خطأ.

Quick check - اختبر نفسك

A compiler finds a syntax error in your program. What happens?

Which translator executes each statement immediately, before translating the next one?

Section 4

The software development life cycle (SDLC)

The seven stages of the SDLC, in order:

  1. Analysis
  2. Planning
  3. Design
  4. Development
  5. Testing
  6. Deployment
  7. Maintenance

Common tools programmers use to develop software:

الملخص بالعربيةدورة حياة تطوير البرمجيات سبع مراحل: التحليل، التخطيط، التصميم، التطوير، الاختبار، النشر، الصيانة. ومن أدوات المبرمج: بيئات التطوير المتكاملة IDE، والمترجمات، وأنظمة التحكم في الإصدارات، وأدوات تتبع الأخطاء.

Quick check - اختبر نفسك

Which of these is NOT one of the seven SDLC stages?

What does an IDE typically include?

Section 5

What is C++? And why?

الملخص بالعربيةلغة C ظهرت عام 1972 على يد Dennis Ritchie في مختبرات Bell، ثم طوّر Bjarne Stroustrup لغة C++ في بداية الثمانينيات للتغلب على قصور C. لغة C++ من أشهر اللغات، كائنية التوجه، محمولة بين الأنظمة، وممتعة وسهلة التعلم.

Quick check - اختبر نفسك

Who developed C++, and when?

Why does C++ lower development costs?

Section 6

Getting started with C++

الملخص بالعربيةالكلمات المحجوزة (Keywords) معانيها معرّفة مسبقاً للمترجم، وعددها 32 كلمة. الثابت قيمة لا تتغير، أما المتغير فهو موقع تخزين في الذاكرة قد تتغير قيمته.

Quick check - اختبر نفسك

How many keywords does C++ have, according to the lecture?

What is the difference between a constant and a variable?

Section 7

The form of a C++ program

  1. Each instruction in a C++ program is written as a separate statement.
  2. Statements must appear in the same order in which we wish them to be executed.
  3. Blank spaces may be inserted between two words to improve readability.
  4. All statements should be in lowercase letters.
  5. C++ has no specific rules for the position of a statement in each line; that is why it is often called a free-form language.
  6. Every C++ statement must end with a semicolon (;), which acts as a statement terminator.
الملخص بالعربيةقواعد شكل برنامج C++: كل تعليمة جملة مستقلة، والجمل تظهر بترتيب تنفيذها، ويمكن إضافة مسافات للتوضيح، والجمل تُكتب بحروف صغيرة، ولا توجد قواعد لمكان الجملة في السطر (لغة حرة الشكل)، وكل جملة تنتهي بفاصلة منقوطة.

Quick check - اختبر نفسك

What ends every C++ statement?

Why is C++ called a free-form language?

Section 8

Your first C++ program

A simple application in C++:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World";
    return 0;
}
الملخص بالعربيةأول برنامج: ندرج مكتبة iostream للإدخال والإخراج، ونكتب using namespace std لاستخدام أسماء المكتبة القياسية، والتعليقات تبدأ بـ //، والتنفيذ يبدأ من الدالة main، وجملة cout تطبع النص على الشاشة.

Quick check - اختبر نفسك

What does #include <iostream> give the program?

Which line tells the compiler where the program starts?

Try it

Run the example yourself

Edit the code and run it here. It compiles and runs on Wandbox, a free online compiler service (GCC 13). Short programs only, and the code leaves this page to that service when you run it.

The output appears here after you run the code.

Runs on the free Wandbox service (wandbox.org), GCC 13.2.0. No account needed.

Section 9

From typing to running

  1. To type your C++ program, you need another program called an IDE.
  2. Once the program is typed, a compiler converts it to machine language instructions.
  3. Then comes compilation and execution, and the program runs.
الملخص بالعربيةلكتابة البرنامج تحتاج إلى بيئة تطوير IDE، وبعد كتابته يحوّله الـ Compiler إلى لغة الآلة، ثم تأتي خطوة الترجمة والتنفيذ فيعمل البرنامج.

Quick check - اختبر نفسك

Which two tools take a program from typed text to a running program?

Sheet 1

Exercises

Answer in your own words

1. Define the 7 stages of the SDLC.

2. Compare between compiler, interpreter, and assembler.

3. What is an IDE?

True or false

1. C++ programming language is an interpreted language.

2. The base for almost all popular programming languages is Fortran.

3. Comments in C++ can be executed by the compiler.

4. Each instruction in a C++ program is written as a separate statement.

5. Every C++ statement does not necessarily end with a semicolon (;).

6. In C programming language, main() tells the compiler where the program starts.

7. Cout is used to output text.

8. Machine language is machine dependent.

9. Assembly language is more difficult than machine language.

10. The assembler is a software that converts assembly language code to machine code.

Programming task

Write a C++ program to print your name, date of birth, and mobile number. Start from this template, replace the placeholder text, and run it here.

The output appears here after you run the code.

Runs on the free Wandbox service (wandbox.org), GCC 13.2.0. No account needed.

Downloads

The original files

The full lecture and the exercise sheet, as they were shared.

Download Lecture 1 (PDF) Download Sheet 1 (DOCX)