0% found this document useful (0 votes)
14 views12 pages

2 Biginning C++ Programing

This document provides an overview of the key phases in C++ programming: 1) The edit phase where code is written in a text editor and saved with a .cpp extension. 2) The preprocessing phase where other files and libraries are included. 3) The compilation phase where code is converted to object code. 4) The linking phase where object code is linked with standard library functions to create an executable. 5) The execution phase where the program runs instruction by instruction. The document then demonstrates a simple C++ "Hello World" program and explains some of its components like comments, headers, namespaces, functions, and output statements.

Uploaded by

rouh304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views12 pages

2 Biginning C++ Programing

This document provides an overview of the key phases in C++ programming: 1) The edit phase where code is written in a text editor and saved with a .cpp extension. 2) The preprocessing phase where other files and libraries are included. 3) The compilation phase where code is converted to object code. 4) The linking phase where object code is linked with standard library functions to create an executable. 5) The execution phase where the program runs instruction by instruction. The document then demonstrates a simple C++ "Hello World" program and explains some of its components like comments, headers, namespaces, functions, and output statements.

Uploaded by

rouh304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Beginning of C++

programing

By Najibullah Rahmani
Programing
• A program is a set of instructions in proper sequence, that causes a computer to
perform a particular task.
• When learning to program in any programming languages, its best just to learn
the “rules of the game.”

• Modern programs are projects composed of many of individual program modules


that have to be linked together in order to be run. In fact most developer systems
have their own integrated development environment (ide) and programs are
developed in phases withen the ide.
C++ program phases
• …in the C++ programing environment

• Edit – in the text editior. Save with .cpp extension


• Preprocess – e.g., text replacement, including other files from the library with the
file to be compiled
• Compile – to object code
• Link – links the object code with the code for the standard library functions
referred to in the program. This produces an executable image (with no missing
pieces). During build process
• Execute – ine instruction at a time
C++ programing
Every programming language has facilities to : In C++

Read data from some input device cin >>

Write output information onto an output device cout <<

Perform arithmetic operations +-*/

Perform relational operations < == >

Perform logical operations ! && ||

Branch to a non-sequential instruction (w/wo structure) While

Store (and retrieve) data values to (and from ) memory =


Some parts of the program
• This is the program you just ran in your ide:

// hello.cpp
// A First program in c++
#include <iostream>
using namespace std;

Int main ()
{
cout << “Hello, I am Rahmani\n”;
return 0; // indicates that the program is ended successfully
}
…continue
• Comments – a type of program documentation
// indicates that the remainder of the line is a comment

/* comments can also look like this */


/* also
like
this
*/
…continue
#include <iostream> a preprocessor directive

• Tells the pre-processor to include in the program the content of the I/O stream
header file called iostream.h. this allows us to use standard stream input and
output objects like cout (displays to the screen )

• As you can see we need to also code the using namespace std; statement for
now, let’s just say that this is so that we don’t have to use ugly prefixes on cout,
like std::cout.
…continue
Int main () – main function header

Every C++ program has at least one function, called main. And there is only one
main program execution begins with the first statement in main

{ brackets to denote the body of the function }


; statement terminator
• Every C++ statement must end with a semicolon

<< stream insertion operator

• Expression to the right of the operator is inserted (sent ) to the cout object
(the display screen or console window )
\n newline escape sequence
• The backslash is an escape character. The character following it takes
on a different meaning e.g:
• \t = tab
• \a – alert; ring bell
• \\ - prints a backslash
• \” – prints a double quotation mark
• And …etc

Return – exits from the function


• In this case control over execution is transferred back to the operating system
A simple C++ program
• The best approach in learning programming for the first time is to treat it like a
game and. As anyone knows, when you learn a game don’t try to understand it
just yet – simply learn the “the rule of the game: at first. When you have a few
simple programs under your hand, you will be understand a bit about why the
code is the way it is.
#include <iostream > Output
using namespace std; // need this to drop std:: first Arithmetic program
int main ()
{ 9
cout << “first Arithmetic program\n\n”;
cout << (12 + 5 + 10 ) / 3 ;
return 0;
} // end main
?
Any question

You might also like