computer engineering 1 nd semester dr. rabie a. ramadan 2
TRANSCRIPT
![Page 1: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/1.jpg)
Computer Engineering 1nd Semester
Dr. Rabie A. Ramadan
http://rabieramadan.org
2
![Page 2: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/2.jpg)
2
Basics of C++ Environment
Phases of C++ Programs • Edit
• Preprocess
• Compile
• Link
• Load
• Execute
Loader
PrimaryMemory
Program is created inthe editor and storedon disk.
Preprocessor programprocesses the code.
Loader puts programin memory.
CPU takes eachinstruction andexecutes it, possiblystoring new datavalues as the programexecutes.
CompilerCompiler createsobject code and storesit on disk.
Linker links the objectcode with the libraries,creates a.out andstores it on disk
Editor
Preprocessor
Linker
CPU
PrimaryMemory
.
.
.
.
.
.
.
.
.
.
.
.
Disk
Disk
Disk
Disk
Disk
![Page 3: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/3.jpg)
3
Programming environment
MSVC (windows) GCC (Linux, Unix) --------------------------------- Many other compilers are available: Ex.
• Borland c++
• Eclips
What is IDE
• integrated development environment : is a software application that provides comprehensive facilities to computer programmers for software development
![Page 4: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/4.jpg)
4
Using MSVC
![Page 5: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/5.jpg)
5
![Page 6: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/6.jpg)
6
![Page 7: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/7.jpg)
7
![Page 8: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/8.jpg)
8
![Page 9: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/9.jpg)
9
![Page 10: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/10.jpg)
10
![Page 11: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/11.jpg)
11
![Page 12: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/12.jpg)
12
![Page 13: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/13.jpg)
13
![Page 14: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/14.jpg)
14
![Page 15: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/15.jpg)
15
![Page 16: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/16.jpg)
16
![Page 17: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/17.jpg)
17
Linux & Unix
gcc command , and g ++ is the C++ compiler, while cc and CC are the Sun C and C++ It works on both Linux & Unix GCC step by step
• 1. Write your program on one of the text editors example ( vi or emacs )
• 2. Save your file as name.cpp where name is the name of your file
• 3. Use one of the following ways to compile your program.
![Page 18: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/18.jpg)
18
Compile then Build
g++ -c hello.cpp // compile g++ hello.o -o hello // build
![Page 19: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/19.jpg)
19
The simple way
The standard way to compile this program is with the command
g++ hello.cpp -o hello This command compiles hello.cpp into an
executable program named "hello" that you run by typing 'hello' at the command line.
It does nothing more than print the word "hello" on the screen
![Page 20: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/20.jpg)
20
Compiling a program with multiplesource files
If the source code is in several files, say
"file1.cpp" and "file2.", then they can be compiled into an executable program named "myprog" using the following command:
g++ file1.C file2.C -o myprog
![Page 21: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/21.jpg)
21
Compile then Build multiple files
g++ -c file1.cpp
g++ -c file2.cpp
g++ file1.o file2.o -o myprog
![Page 22: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/22.jpg)
22
Basics of a Typical C++ Environment
Input/output• cin
• Standard input stream
• Normally keyboard
• cout• Standard output stream
• Normally computer screen
• cerr• Standard error stream
• Display error messages
![Page 23: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/23.jpg)
23
Ways to format the program
![Page 24: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/24.jpg)
24
Ways to format the program
![Page 25: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/25.jpg)
25
Variables and Data Types
A place in Memory To hold an information that a user use.
Deceleration
SpaceOccupied VariableName;
![Page 26: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/26.jpg)
26
C++’ Names
The name of a variable: • Starts with an underscore “_” or a letter, lowercase or uppercase, e.g.
_Students, pRice
• Can include letters, underscore, or digits. Examples are: keyboard, total_grade, _Score_Side1
• Cannot include special characters such as !, %, ], or $
• Cannot include an empty space
• Cannot be any of the reserved words
• Should not be longer than 32 characters (although allowed)
![Page 27: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/27.jpg)
27
Reserved Words
![Page 28: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/28.jpg)
28
Variables and Their Data Types
The amount of memory space necessary to store a variable is also referred to as a data type.
![Page 29: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/29.jpg)
29
![Page 30: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/30.jpg)
30
Variables and Their Data Types
char 8 bits
short int A group of 16 contiguous bitsࡀĀ
![Page 31: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/31.jpg)
31
Example
![Page 32: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/32.jpg)
32
Practice -- what is the o/p
![Page 33: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/33.jpg)
33
Practice -- what is the o/p
![Page 34: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/34.jpg)
34
O/P
![Page 35: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/35.jpg)
35
Representing a Double-Word
Double-word combines 4 bytes, or 8 nibbles, or 32 bits. The bits, counted from right to left, start at 0 and end at 31.
![Page 36: Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2](https://reader035.vdocuments.site/reader035/viewer/2022062718/56649eb75503460f94bc10af/html5/thumbnails/36.jpg)
36
What are constants?
const PI = 3.14;
#define PI 3.14