0% found this document useful (0 votes)
38 views

1 Introduction To Programming

C++ is a computer programming language that can be used to write programs to instruct a computer to perform tasks. Programs written in C++ are first compiled from human-readable source code into machine-readable object code. The compiler translates the high-level C++ code into low-level machine language code that the computer can understand. C++ programs have structures like preprocessor directives, header files, main functions, and statements. They can perform tasks like outputting text to the screen using escape sequences and comments.

Uploaded by

MishaalKhan
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

1 Introduction To Programming

C++ is a computer programming language that can be used to write programs to instruct a computer to perform tasks. Programs written in C++ are first compiled from human-readable source code into machine-readable object code. The compiler translates the high-level C++ code into low-level machine language code that the computer can understand. C++ programs have structures like preprocessor directives, header files, main functions, and statements. They can perform tasks like outputting text to the screen using escape sequences and comments.

Uploaded by

MishaalKhan
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Introduction to programming

C++
What is a computer language?

•  A computer language is a means of communication used to


communicate between people and computer.
• Like natural languages, computer languages have a vocabulary and
grammar rules of their own.
• The grammer rules of computer language are called syntax rules.
• Computer being a machine is only receptive to exact vocabulary used
correctly as per syntax rules of the language being used.
 
What Computer Programs do?

• A computer cant do anything at its own, it is instructed to do a desired job.


• A computer program is a sequence of instructions written in a language that
can be understood by the computer, to perform a specific task.
Classification of computer languages

• High level language:


User language, consists of english words and familiar mathmatical
symbols.
• Low level language:
The only language computer can understand also called the machine
language.
consists of binary 1s and 0s only.
What is a compiler?

• Since a computer hardware can only understand machine language, there


is a need to convert instructions of a program written in high level language
to machine instructions.
• Also, as mentioned before that computer is only receptive to correct
vocabulary and syntax, there is a need of a program that points out
mistakes made by user.
• A compiler is a translating program that performs the above mentioned
tasks.
• A program written by a programmer in high level language is called a
source program or source file.
• After the program is corrected for mistakes and converted to machine
language by the compiler, it is referred to as object program or object file.
The object program consists only of machine language instructions.

Hi level language Machine language


program/ input program/ output
Compiler
A simple C++ program

#include<iostream.h>
#include<conio.h>
Void main(void)
{
Cout<<“hello world”;
Getch();
}
Structure of a c++ program

• A C++ program consists of 3 main parts:


1. preprocessor directives:
(i.e #include in the previous example)
it consists of instructions for the compiler, compiler adds special instructions
from these directives in to the program at the time of compilation.
The main() function
C++ statements
• Header files:
(i.e iostream.h and conio.h in the previous example)
Contains definitions of library functions/objects. A single header file may
contain a large no. of built in library functions.
• Main() function: indicates beginning of C++ program. Statements within this
function are main body of C++ program.
• C++ Statements: Written inside curly braces { }.
Each statement ends with a semicolon called statement terminator.

Example #02
#include<iostream.h>
#include<conio.h>
void main(void)
{
cout<<“ C++ is a powerful programming language”;
cout<<“UNIX operating system is written in C++”;
cout<<“please pay great attention to learn the language”;
getch();
}
• Use of endl manipulator and clrscr() function.
Example #03
#include<iostream.h>
#include<conio.h>
void main(void)
{
cout<<“ C++ is a powerful programming language”<<endl;
cout<<“UNIX operating system is written in C++”<<endl;
cout<<“please pay great attention to learn the language”<<endl;
getch();
}
• Using three “put to” or insertion operators.
Example #04
#include<iostream.h>
#include<conio.h>
void main(void)
{
cout<<“ I “<<“LOVE”<<“ PAKISTAN ”;
getch();
}
Use of Escape Sequence

• Special non printing characters used to control printing on the screen.


• An escape sequence is a combination of backslash “\” and a code character
the backslash is called control character.
• Some important escape sequences are:
\n new line, moves the printing to the beginning of next line
\t tab, moves printing one tab forward

– Use of Comments

You might also like