الشريحة ٢
Outlineالأجندة
- How computer programs work
- The evolution of programming language.
- Program translator
- SDLC(Software Development Life Cycle)
- What is C++? and Why?
- What are IDE?
- Getting start with C++
- Format a C++ program.
الشريحة ٣
How computer programs workكيف تعمل برامج الكمبيوتر
- Computers only understand machine code, which is a low-level language that consists of binary digits (0s and 1s).
- To bridge the gap between human and machine code, we use programming language.
- To program a computer, we need to write the instructions in a special language, which we call a programming language.
- We call the instructions we send to the computer code. We call each line of instruction a line of code.
- When we write code, we program the computer to do something. For this reason, we also call the code we write a computer program (or a program).
اختبر نفسك
What is the only language a computer understands directly?
What do we call each line of instruction sent to the computer?
الشريحة ٤
The Evolution of Programming Languagesتطور لغات البرمجة
- To build programs, people use languages that are like human language.
- The results are translated into machine code, which computers understand.
Programming languages fall into three broad categories:
- Machine languages
- Assembly languages
- Higher-level languages
الشريحة ٥
Machine, Assembly, and High-Level codeنفس العملية بالمستويات الثلاثة
Machine language instructions
0110 0011 0010 0001 0100 0011 0010 0010 0100 0011 0010 0011 0111 0011 0010 0100
Assembly language instructions
LDA X ADA Y ADA Z STA D
High Level language
D = X + Y + Z
الشريحة ٦
Machine Languagesلغة الآلة
- Machine languages (first-generation languages) are the most basic type of computer languages.
- Different types of hardware use different machine code.
- Every instruction and data should be written using 0’s and 1’s.
Advantages of Machine Language:
- Free High Speed
Disadvantages of Machine Language:
- Machine Dependent
- Complex Language Error
اختبر نفسك
Which type of language must be written entirely in 0s and 1s?
الشريحة ٧
Assembly Languagesلغة التجميع
- Assembly languages (second-generation languages) are only somewhat easier to work with than machine languages.
- Developers use cryptic English-like phrases to represent strings of numbers.
- The code is then translated into object code, using a translator called an assembler.
Advantages of Assembly Language:
- Easy to understand and use
- More control on Hardware
Disadvantages of Assembly Language:
- Machine Dependent
- Harder to Learn
- Slow Development Time
الشريحة ٨
High-level Languagesاللغات عالية المستوى
- High-level languages use true English-like phrasing, making them easier to use than previous languages.
Advantages:
- Readability
- Machine Independent
- Easy debugging
- Easier to maintain
- Easy Documentation
Disadvantages:
- Poor control on Hardware
اختبر نفسك
Which of these is an advantage of high-level languages?
الشريحة ٩
PROGRAM TRANSLATORSالمترجمات
الشريحة ١٠
Assemblerالمجمّع
- The Assembler is a Software that converts an assembly language code to machine code.
- It produces binary code in form of 0s and 1s.
الشريحة ١١
Compilerالمترجم
- A compiler is a program translator that translates a program written in a high-level language into a machine language program.
- During the translation process, the compiler reads the source program and checks for syntax errors.
- In case of any errors, the compiler will not create the object code until all the errors are rectified.
- Once the program has been compiled, the resulting code is saved separately and can be run on its own at any time.
- But, if the source code is modified then it is necessary to recompile the program again to reflect the changes.
اختبر نفسك
A compiler finds a syntax error in your program. What happens?
الشريحة ١٢
Interpreterالمفسّر
- Translates high-level language into machine language.
- Unlike compilers, it translates a statement in a program and executes immediately, i.e., before translating the next source language statement.
- When an error is encountered, the execution of the program is halted and an error message is displayed.
اختبر نفسك
Which translator executes each statement immediately, before translating the next one?
الشريحة ١٣
The Software Development Life Cycle (SDLC)دورة حياة تطوير البرمجيات
7 stages of the software development life cycle:
- Analysis
- Planning
- Design
- Development
- Testing
- Deployment
- Maintenance
اختبر نفسك
Which of these is NOT one of the seven SDLC stages?
الشريحة ١٤
Development Toolsأدوات التطوير
Some of the most common tools that programmers use to develop software:
- Integrated development environments (IDEs): IDEs are all-in-one tools that provide a complete environment for software development. They typically include a code editor, compiler or interpreter, debugger, and other tools such as project management and version control integration. Some popular IDEs include Visual Studio, IntelliJ IDEA, and Eclipse.
- Compilers and interpreters: Compilers and interpreters are used to translate source code into machine code that can be executed by a computer. Compilers are typically used for compiled languages like C and Java, while interpreters are typically used for interpreted languages like Python and JavaScript.
- Version control systems: Version control systems are used to track changes to source code over time. This allows programmers to revert to previous versions of their code if necessary, and to collaborate with other programmers on the same project.
- Debugging tools: Debugging tools help programmers to find and fix bugs in their code.
اختبر نفسك
What does an IDE typically include?
الشريحة ١٥
What is C++?ما هي لغة C++؟
- C is a programming language developed at AT&T’s Bell Laboratories of USA in 1972.
- It was designed and written by Dennis Ritchie.
- In the late seventies C began to replace the more familiar languages of that time like FORTRAN, etc.
- C is not as easy to understand as other languages; also, 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.
اختبر نفسك
Who developed C++, and when?
الشريحة ١٦
Why C++?لماذا C++؟
- 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 an object-oriented programming language that gives a clear structure to programs and allows code to be reused, lowering development costs.
- C++ is portable and can be used to develop applications that can be adapted to multiple platforms.
- C++ is fun and easy to learn!
اختبر نفسك
Why does C++ lower development costs?
الشريحة ١٧
Getting started with C++البدء مع C++
- Keywords are the words whose meaning has already been explained to the C++ compiler (or in a broad sense to the computer).
- There are only 32 keywords available in C++.
- A constant is an entity that doesn’t change, whereas, a variable is an entity that may change.
- We can store values in the computer memory. We call each storage location in the computer’s memory a variable.
Steps in learning English language:
Steps in learning C++ language:
Digits
Special symbols→Constants
Variables
Keywords→Instructions→Program
اختبر نفسك
How many keywords does C++ have, according to the lecture?
What is the difference between a constant and a variable?
الشريحة ١٨
Form of a C++ Programشكل برنامج C++
There are certain rules about the form of a C++ program that are applicable to all C++ programs. These are as under:
- Each instruction in a C++ program is written as a separate statement.
- The statements in a program must appear in the same order in which we wish them to be executed.
- Blank spaces may be inserted between two words to improve the readability of the statement.
- All statements should be in lowercase letters.
- C++ has no specific rules for the position at which a statement is to be written in each line. That’s why it is often called a free-form language.
- Every C++ statement must end with a semicolon ( ; ). Thus ; acts as a statement terminator.
اختبر نفسك
What ends every C++ statement?
Why is C++ called a free-form language?
الشريحة ١٩
Let's look at a simple application in C++تطبيق بسيط بلغة C++
#include <iostream>
using namespace std;
int main() {
// prints the string enclosed in double quotes
cout << "Hello World";
return 0;
}
الشريحة ٢٠
#include directiveالأمر #include
#include <iostream>is a header file library that lets us work with input and output objects, such ascout.
The general form:
#include <header_file>
اختبر نفسك
What does #include <iostream> give the program?
الشريحة ٢١
using namespace stdجملة using namespace std
using namespace std;means that we can use names for objects and variables from the standard library.
الشريحة ٢٢
How to use code comments //التعليقات في الكود
// this is a comment- Comments are used in a C++ program to clarify either the purpose of the program or the purpose of some statement. It is a good practice to begin a program with a comment indicating the purpose of the program, its author, and the date on which the program was written.
- Any number of comments can be written at any place in the program.
الشريحة ٢٣
main() functionدالة main
- In C++ programming language the
main()function serves a special purpose, it tells the compiler where the program starts. - The body of the main function surrounded by curly braces ( { } ).
return 0ends the main function.
اختبر نفسك
Which line tells the compiler where the program starts?
الشريحة ٢٤
Output using coutالطباعة باستخدام cout
- The only executable statement in the program is:
cout << “Hello World"; - which displays the enclosed text i.e.
Hello World
الشريحة ٢٥
Compilation and Executionالترجمة والتنفيذ
- To type your C++ program, you need another program called IDE.
- Once the program has been typed it needs to be converted to machine language instructions. To carry out this conversion, we need Compiler.
اختبر نفسك
Which two tools take a program from typed text to a running program?
جرّب الكود
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.
عدّل الكود وشغّله من هنا مباشرة عبر خدمة Wandbox المجانية (مترجم GCC 13). للبرامج القصيرة فقط، ويُرسل الكود إلى تلك الخدمة عند التشغيل.
The output appears here after you run the code.
Runs on the free Wandbox service (wandbox.org), GCC 13.2.0. No account needed.
ورقة التمارين ١
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.
التحميلات
The original filesالملفات الأصلية
الملفان الأصليان للمحاضرة وورقة التمارين كما وردا.