Section 1
How computer programs work
- Computers only understand machine code, a low-level language of binary digits (0s and 1s).
- Programming languages bridge the gap between humans and machine code.
- The instructions we send to the computer are called code, and each line of instruction is a line of code.
- The code we write to make the computer do something is a computer program.
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 language | Assembly language | High-level language | |
|---|---|---|---|
| Generation | First | Second | Later, English-like |
| Code looks like | Binary digits (0s and 1s) | Cryptic English-like phrases | True English-like phrasing |
| Depends on the machine | Yes, machine dependent | Yes, machine dependent | No, machine independent |
| Advantages | High speed | Easier to understand and use; more control on hardware | Readability; easy debugging, maintenance, and documentation |
| Drawbacks | Complex language, error prone | Harder to learn; slow development time | Poor 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: software that converts assembly language code to machine code, producing binary code of 0s and 1s.
- Compiler: translates a whole high-level program into machine language. It checks the source for syntax errors and creates no object code until every error is fixed. The compiled code is saved and can run on its own at any time; after any change you must recompile.
- Interpreter: also translates a high-level language into machine language, but it translates one statement and executes it immediately, before translating the next. When it hits an error, execution halts and an error message is displayed.
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:
- Analysis
- Planning
- Design
- Development
- Testing
- Deployment
- Maintenance
Common tools programmers use to develop software:
- Integrated development environments (IDEs): all-in-one tools with a code editor, compiler or interpreter, debugger, and tools such as project management and version control integration. Popular IDEs include Visual Studio, IntelliJ IDEA, and Eclipse.
- Compilers and interpreters: translate source code into machine code. Compilers suit compiled languages like C and Java; interpreters suit interpreted languages like Python and JavaScript.
- Version control systems: track changes to source code over time, so programmers can revert to previous versions and collaborate.
- Debugging tools: help programmers find and fix bugs in their code.
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 is a programming language developed at AT&T's Bell Laboratories in the USA in 1972, designed and written by Dennis Ritchie.
- In the late seventies C began to replace the more familiar languages of that time, like FORTRAN.
- C is not as easy to understand as other languages, and it does not have as many automatic checks as some other high-level languages.
- To overcome these and other shortcomings of C, Bjarne Stroustrup of AT&T Bell Laboratories developed C++ in the early 1980s.
- C++ is one of the world's most popular programming languages.
- C++ can be found in today's operating systems, graphical user interfaces, and embedded systems.
- C++ is object-oriented: it gives programs a clear structure and allows code to be reused, lowering development costs.
- C++ is portable, so applications can be adapted to multiple platforms. And it is fun and easy to learn.
Quick check - اختبر نفسك
Who developed C++, and when?
Why does C++ lower development costs?
Section 6
Getting started with C++
- Keywords are words whose meaning has already been explained to the C++ compiler. There are only 32 keywords in C++.
- A constant is an entity that does not change.
- A variable is an entity that may change. Values are stored in the computer memory, and each storage location is a variable.
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
- Each instruction in a C++ program is written as a separate statement.
- Statements must appear in the same order in which we wish them to be executed.
- Blank spaces may be inserted between two words to improve readability.
- All statements should be in lowercase letters.
- 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.
- Every C++ statement must end with a semicolon (;), which acts as a statement terminator.
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;
}
#include <iostream>: a header file library that lets us work with input and output objects, such ascout.using namespace std;: lets us use names for objects and variables from the standard library.- Comments start with
//and clarify the purpose of the program or of a statement. They are for the reader, and any number of them can appear anywhere. main()tells the compiler where the program starts. Its body sits between curly braces{ }, andreturn 0ends it.cout << "Hello World";is the only executable statement here; it displays the text Hello World.
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
- To type your C++ program, you need another program called an IDE.
- Once the program is typed, a compiler converts it to machine language instructions.
- Then comes compilation and execution, and the program runs.
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.
Analysis, planning, design, development, testing, deployment, maintenance.
2. Compare between compiler, interpreter, and assembler.
| Assembler | Compiler | Interpreter | |
|---|---|---|---|
| Translates | Assembly language to machine code | A whole high-level program to machine language | A high-level program to machine language |
| How it works | Produces binary code of 0s and 1s | Checks the whole source for syntax errors, then saves the compiled code to run any time | Translates one statement and executes it immediately, before the next |
| On errors | Not covered in the lecture | No object code until all errors are fixed | Execution halts and an error message is shown |
3. What is an IDE?
An integrated development environment: an all-in-one tool that provides a complete environment for software development, typically a code editor, compiler or interpreter, debugger, and tools such as project management and version control integration. Examples: Visual Studio, IntelliJ IDEA, Eclipse.
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.