Download presentation
Presentation is loading. Please wait.
Published byCleopatra Sparks Modified over 9 years ago
1
Chapter 11 Getting ready to program Hardware Model Software Model Programming Languages Facts about C++ Program Development Process The Hello-world Program
2
Chapter 12 Stored-Program Computer Both programs and data are stored in main memory Secondary Storage Input Devices Output Devices CPU Main Memory
3
Chapter 13 Program & Data Program - a sequence of instructions specifying how the data is to be processed. Data - input to the program, either supplied during runtime or pre-stored in the computer Both program and pre-stored data are stored in the main memory
4
Chapter 14 Main Memory The place for storing data of all kinds Bit (Binary Digit, smallest unit) - stores either 0 or 1 Byte - consists of 8 bits Main memory a list of bytes, each associated with an address stores both the program and data e.g. 64K bytes of memory: 0 1 2 65535............
5
Chapter 15 CPU Acronym for … The “brain” of computer Consists of a processing unit (the ALU), a control unit (the CU) and a set of registers (a few high- speed memory units for temporary use) Fetch and execute instructions from the main memory until the computer is turned off ALU CU Register File CPU
6
Chapter 16 Software a collection of programs for a specific task e.g. operating system (OS), editor, compiler, game, database server Operating System Chief servant, managing tasks and resources allocates the computer’s resources to the different tasks that the computer must accomplish What are the most popular OS’s? e.g. DOS, Windows, UNIX, Solaris, Linux, etc.
7
Chapter 17 Editor Pascal Compiler C++ Compiler Games Web Browser System and Application Softwares Hardware-Software Hierarchy Operating System Hardware
8
Chapter 18 Hardware-Software Hierarchy
9
Chapter 19 Machine Languages A CPU only understands its own machine language => portability problem In Motorola 68000, the following 4 bytes is an instruction to move the value in register D3 to memory address 104. In Intel 80486, the same sequence of bytes represents different instructions Coding is tedious and error prone 192 49 104 0
10
Chapter 110 Assembly Languages Use English-like abbreviations e.g. the previous MC68000 machine instruction is written as: MOVE D3, 104 slightly easier for human to understand need an assembler to translate into machine instructions Different CPUs have different instruction sets e.g. MOVE D3, 104 is not a valid instruction in Intel 80486 since it doesn’t have register D3 => portability problem
11
Chapter 111 High-level Languages Close(r) to human language One single statement accomplishes substantial tasks Need a compiler/linker to translate into machine language More portable - the same program (more or less) works for different machines e.g. Fortran, COBOL, Pascal, Ada, Modula, C, C++, Lisp, Prolog, Java, Perl...
12
Chapter 112 Compiler & Linker Compiler translates a program in high-level language into an object program (or object code). The original program is called the source program/code. Linker combines the object code of a program with other pre-compiled object codes to generate an executable code which is in machine language linker compiler source code object code other object code executable code
13
Chapter 113 The C++ Program Language C developed by Dennis Ritchie in 1970’s originally for writing system programs such as OS (e.g. UNIX) and compilers “close to machine” C++ developed by Bjarne Stroustrup in 1980’s C enhanced with object-oriented features, for writing more complex programs “close to the problems to be solved”
14
Chapter 114 Standardization & Libraries ANSI/ISO Standard for C++: An important standard, most compilers follow Documents available in their web: webstore.ansi.org (Document No.: INCITS/ISO/IEC 14882-2003) C++ Standard Libraries Contains pre-written classes, objects & functions Greatly facilitates programming and performance Generally provided by compiler vendors Proprietary libraries provided by individual vendors
15
Chapter 115 Program Development Process (1) Specify the task Find an algorithm for its solution Code the algorithm in a programming language Prepare the source code (program) in a file, called source file Test the code Compile the source file to produce object code, stored in an object file Link up the object code with any library module and load the loader to produce the final executable file Run the executable file and debug any error
16
Chapter 116 Program Development Process (2) Problem definition Algorithm design Translating to C++ Testing
17
Chapter 117 Programming Environment (1) Editor Disk Preprocessor Disk Compiler Disk Linker Disk
18
Chapter 118 Programming Environment (2)............ Loader CPU Disk Main Memory
19
Chapter 119 Programming Errors Syntax errors: violation of the syntax detected during compilation Run-time errors: compilation successful but errors detected during run-time, e.g. division by zero Logic error: compilation and execution do not produce machine detectable errors but the answer is wrong may be due to wrong algorithm or wrong coding
20
Chapter 120 Your first C++ Program #include using namespace std; void main() { cout << "Hello, world!“ << endl; } include library use std namespace output statement
21
Chapter 121 Components of the Program “ #include …” - called include directives, tells the compiler to include the header of the library The line “ using namespace std; ” tells the compiler to include the std namespace The lines “ int main(){ ” and “ return 0; } ” tell the compiler where the main body of program starts and ends The line “ cout << …” is an executable statement (or simply statement). It causes “ Hello, world! ” to be printed on the screen.
22
Chapter 122 Library q Library is a collection of classes, objects and functions (see p14, more detail in Chapter 4, 5…) We can use the pre-written classes, objects and functions inside a library after including it using “ #include …” For example, cout and cin are objects inside the iostream library. So, we can use them after having the directive: “ #include ”
23
Chapter 123 Namespace // without “using namespace std;” #include void main (){ std::cout << "Hello world” << endl; } // with “using namespace std;” #include using namespace std; void main () { cout << "Hello world“ << endl; }
24
Chapter 124 Further Details C++ is case-sensitive: E.g. “ Main ” is different from “ main ”. Syntax of include directives: no space after no semi-colon at the end, each include directive must be on its own line Statements are ended with semicolons spacing is not important programmer can put in suitable spacing and indentation to increase readability
25
Chapter 125 Output statement: << - the output (or insertion) operator cout << “Hello…” - apply the output operator on the objects cout and “Hello…” The object cout is called standard output stream and is defined in endl – causes the cursor to move to the beginning of a new line
26
Chapter 126 Layout of a Simple C++ Program #include using namespace std; void main() { statement-1 statement-2 statement-3... statement-last }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.