Download presentation
Presentation is loading. Please wait.
Published byAlaina Harrell Modified over 9 years ago
1
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming in C++ 7.0 1 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
2
2
3
Explain the history of c++ 1 C++ program structure 2 C++ programming development process 3 Develop C++ program 4 3 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
4
C++ Programming language was derived from a C language. C++ combines traditional C programming with OOP capability. A C++ was developed by BJARNE STROUSTRUP at Bell Labs in the early 1980s. In C++, ++ is an operator that increments a variable by 1, therefore, the C language is incremented to its next level with C++. 4 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
5
// my first program in C++ #include using namespace std; int main () { cout << "Hello World!"; return 0; } comment Preprocessor Directives Main function braces output Return statement Header file 5 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
6
1) Design 2) Writing Code 3) Compiling 4) Linking 5) Debugging 6 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
7
1) Design Decide what you need the program to do. Try to break the problem down into functional blocks; pieces that you can turn into functions or classes in a programming language. First there is a basic investigation process, where you try to figure out what needs to be done and how, in theory, it could be done. Secondly you determine the functional blocks of the system and define their interfaces. Thirdly you design the details for each functional block. 7 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
8
2) Writing Code Write source code which contains text in the programming language you are using. 8 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
9
3) Compiling Take the source code and compile it into object code. Object code is a translation of the instructions you wrote in the programming language into the native language of the computer (basically lots of numbers, also called machine language). Each source file is translated into one object file. 9 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
10
4) Linking Link all the object code files for the program together to create an executable. An executable is a file in the native language of the computer arranged so that it can be read from a disk into the computer's memory and executed (or run) from start to finish. If you are using libraries you may have to include those libraries, which are sets of object files archived together for easy access. 10 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
11
5) Debugging Almost no programs run perfectly, or even well, the first time they are run. You will have to find out what is wrong with a program and probably go back to the source code to fix the problem. This process is called debugging, and for some programs it never seems to end. Debugging should include testing, which means component testing (each functional block alone), integration testing (combinations of functional blocks and their interfaces) and system testing (the whole system). After all that the program is finished. Except, of course, that you will always find some new feature you want to implement, or piece of code you want to tweak. At that point you go back to step one and design your modifications, and start into the cycle again. 11 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
12
12
13
Describe the compiling process of a program 1 Explain the types of error 2 13 © 2010/2011 | PN NORHASLIZA BT MUHAMAD NOR
14
1.Syntax Checking: ▫ Once the code is updated based on the preprocessing, the code can be checked for valid syntax. This includes things like checking for semi-colons, matching braces, every "begin" has an "end", etc. This doesn't mean the code is correct, but it does determine whether the code can be turned into machine code as written. 2.Converting To Assembly: ▫ This step doesn't exist for all languages/compilers. Java, obviously, doesn't use this step. Some compilers may go straight to machine code. 14 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
15
3.Converting to Machine Code: ▫ What counts as machine code varies somewhat. Java goes to byte code (.class files). GCC creates object files. This step creates a file that is PART of the final program. 4.Linking Machine Code Into An Executable: ▫ Frequently, functions that are used by a program are defined in separate files. Delphi uses components that are in a variety of different files (especially commercially sold components). C/C++ use a variety of libraries. Java often merges.class files into a.jar file. At this step, many linkers will do final checks to make sure all the required pieces, functions, components, etc have been accounted for. 15 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
16
ERRORS Syntax /Compile Time Run TimeLogical 16 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
17
a. Syntax / Compile Time Error Compilation error refers to a state when a compiler fails to compile a piece of computer program source code, either due to errors from the compiler itself, or syntax errors in the code. A compilation error message often helps programmers debugging the source code for possible syntax errors. 17 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
18
Syntax errors - Errors in spelling and grammar. ▫ You can use the compiler or interpreter to uncover syntax errors. ▫ You must have a good working knowledge of error messages to discover the cause of the error. 18 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
19
b. Run Time Error Run time error - refers to the period while a computer program is actually executed ("run") in a computer, from beginning to termination. It may also mean the program's running time, the duration of that period. Run time errors can be caused by attempting to do impossible arithmetic operations such as calculate with non-numeric data or divide by zero. Run time errors can be caused by attempting to do impossible arithmetic operations such as calculate with non-numeric data or divide by zero. 19 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
20
c. Logical Error Logical errors - Errors that indicate the logic used when coding the program failed to solve the problem. ▫ You do not get error messages with logic errors. ▫ Your only clue to the existence of logic errors is the production of wrong solutions. 20 © 2011/2012 | PN NORHASLIZA BT MUHAMAD NOR
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.