Chapter 3: Introduction to C++ Programming PDF

Summary

This document is an introduction to C++ programming. The document covers basic C++ syntax, including input, output, new lines, and comments. Readers can learn how to execute C++ programs and understand the basic components of its programming language. Keywords include C++ programming, coding and computer science.

Full Transcript

TST1024 Chapter 3: Introduction to C++ Programming The Lecturer Dr Nur Ilyana Dr Nur Amlya Dr Muhammad KSF 1 KSF 2 Nuruddin KSF 3 2 ...

TST1024 Chapter 3: Introduction to C++ Programming The Lecturer Dr Nur Ilyana Dr Nur Amlya Dr Muhammad KSF 1 KSF 2 Nuruddin KSF 3 2 Learning Objective 1. Describe the properties of C+ 2. Describe the structure of simple C++ program 3. Edit, compile and run the C++ program 4. Use template for simple C++ program 3 Introduction of C++ The C++ language is an object-oriented programming language and is a combination of both low-level and high-level language – a Middle- Level Language. C provides a comprehensive set of features for handling a wide variety of applications, such as systems development and scientific computation. C++ is an “extension” of the C language, in that most C programs are also C++ programs. 4 History of C++ C++ was developed by Bjarne Stroustrup at AT&T Bell Labs in the 1980s. Overcame several shortcomings of C. Incorporated object-oriented programming. C remains a subset of C++. As early as 1989, an American National Standards Institute (ANSI) Committee was founded to standardize the C++ programming language. The aim was to have as many compiler vendors, and software developers as possible agree on a unified language description to avoid confusion caused by various dialects. 5 Charateristic of C++ The characteristics of C++ including universally usable modular programs, efficient, close to the machine programming, portable programs for various platforms. C++ also supports: Procedural programming: writing sequence instructions Object Oriented programming: data classes, inheritance, polymorphism. Generic programming: template code, creation functions, code flexibility. Best use case of C++: game dev, real-time system, large scale simulation (Moon landing) 6 FEATURES OF C++ Platform Compile Simple Portability dependent based Object Syntax Case oriented based Powerful sensitive Language language Use of Pointer 7 Execute a C++ Programming To processing the C++ program comprising in six steps activity: Execute a C++ Programming BUILD To build the program, three process is identified in sequence of process which can be categorized such as IDE, Pre-processor, Compilation and Linker. EDITOR/IDE The program needs to write in C++, which uses the IDE environment. The extension of this C++ file is.cpp for writing source code and header files (.h). PRE-PROCESSOR The source codes are preprocessed based on the identification of the preprocessor directives. The preprocessor directives are beginning with hash symbol (#) for instance #include and #define where manipulation including files, replaced symbol is constructed first before the compilation. Execute a C++ Programming COMPILER Compiler will compile the program, checks the errors and generates the object file (this object file contains assembly code). LINKER Link the compiled object codes with other object codes and the library object codes (.lib,.a) to makes the executable file (.exe). The linker which helps to link object modules of a program into a single object file. Execute a C++ Programming EXECUTION The object file is converted into an executable file with the extension (.exe). In execution steps, it is comprising in two parts, loader, and CPU. LOADER The executable program must next be loaded into main memory for execution that accomplish by the Loader to perform this task. CENTRAL PROCESSING UNIT (CPU) The CPU conduct this task, which is provide run the executable code, with the input to produce the desired output. Watch the video: Installation of C++ Link for installer DEV C++: https://sourceforge.net/projects/orwelldevcpp/ Link for installer Code::Block: https://www.codeblocks.org/downloads/binaries In C++, the basic syntax requires running the program including the #directive, namespace standard library and main function. In this main function, the program is executed using main function with the sequential steps action. There are syntax including omitting namespace, output, input, new lines, comments. Basic Syntax of C++ Ignoring of the namespace The namespace can be used to call standard library. However, it can be ignored by state each statement in the C++ code using statement (std::). C++ Output ▪ To display an output on the screen (terminal), cout