Introduction to Programming: Program Development Process, Language Types, and C++ Basics, Lecture notes of Computer Programming

A comprehensive introduction to the program development process, exploring different types of programming languages, including low-level and high-level languages. It delves into the structure of c++ programs, covering preprocessor directives, the main() function, and c++ statements. The document also explains essential concepts like data types, tokens, and the use of the 'cout' object for output. It concludes with practical exercises to reinforce understanding.

Typology: Lecture notes

2022/2023

Uploaded on 03/05/2025

asmat-ullah-1
asmat-ullah-1 🇵🇰

4 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Program Development Process &
Language Types
Dr. Fakhre Alam
Khan
MED UET Peshawar
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Introduction to Programming: Program Development Process, Language Types, and C++ Basics and more Lecture notes Computer Programming in PDF only on Docsity!

Program Development Process &

Language Types

Dr. Fakhre Alam

Khan

MED UET Peshawar

Program Development Process

A programmer has to go through the following stages to develop a

computer program.

1) Defining and Analyzing Problem

2) Designing the Algorithm.

3) Coding or Writing the Program

4) Testing Program

5) Final Documentation

Programing Languages

1. Low level

Machine language

Assembly language

2. High level

Procedural language (FORTRAN, COBOL, C etc)

Object oriented programming (JAVA, C++ etc)

Non-Procedural language (RPG, SQL etc)

Types of Codes

There are two types of codes that are as follows:

Source Code :

A program written in a high-level language is called source code. Source code is

also called source program.

Computer cannot understand the statements of high-level language.

The source code cannot be executed by computer directly.

It is converted into object code and then executed.

Object Code :

A program in machine language is called object code.

It is also called object program or machine code. Computer understands object

code directly.

Language Processor

1) Compiler :

A compiler is a program that converts the instruction of a high level

language into machine language as a whole.

A program written in high-level language is called source program.

Compiler converts source program into machine code known as object

program.

Compiler

Source Program Object Program

Language Processor

2) Interpreter :

An interpreter is a program that converts one statement of a program at one time.

It executes this statement before translating the next statement of the source

program.

If there is an error in the statements, the interpreter stops working and displays an

errors message.

The advantage of interpreters over compilers is that an error is found

immediately.

Relationship of Object Program, Source Program and Compiler

A source program is written by a programmer in a programming

language such as C.

This program is not in a form that a computer can understand.

A compiler translates that source program into the object program that

the computer can understand and execute.

Basic Structure of C ++ Program

The format of writing program in C++ is called its structure.

▪The basic structure of C++ program is very flexible.

▪It increases the power of language.

▪It consists of the following parts:

  1. Preprocessor directive

  2. Main() function

  3. Program body (C++ statements)

Basic Structure of C ++ Program

The following preprocessor directive is used in C++ to include header files in the

program:

Include Preprocessor

Include preprocessor directive is used to include header files in the program.

The syntax of using this directive is as

follows: #include <iostream.h>

▪The above statement tells the compiler to include the file iostream.h in source

program before compiling it.

Basic Structure of C ++ Program

Header Files

▪Header files are collection of standard library functions to perform different tasks.

▪ There are many header files for different purposes.

▪Each header files contains different types of predefined functions.

▪ Many header files can be included in one program.

▪The header file must be included in the program before calling any of its functions in the

program.

▪ The extension of a header file is .h.

▪The include preprocessor directive is used to include header files in programs.

▪ These files are provided by C++ compiler system.

▪The header files are normally stored in INCLUDE subdirectory.

▪ The name of header file is written in angle brackets.

Basic Structure of C ++ Program

2) Main() function

▪The main() function is the starting point of a C++ program.

▪When the program is run, the control enters main() function and

starts executing its statements.

▪Each program must contain main() function. If a program does not

contain main function , it can be compiled but cannot be executed.

▪Any number of statements can be written in the body of the main()

function.

Basic Structure of C ++ Program

Syntax

void main()

body of main function

Basic Structure of C ++ Program

#include

using namespace std;

int main()

{

cout<< "Welcome to UET";

}

Example

The following example explains the basic structure of C++ program:

Program body

(C++ statements)

In the above example,

The first line is preprocessor directive to include a header file iostream.

The using namespace std; line tells the compiler to expect stuff from the C++ Standard Library to be used in this file.

Without this line, each keyword from the library would have to be preceded with a std:: , to denote its scope. For

instance, without that line, each reference to cout would have to be written as std::cout. The using statement is added to

make the code look more clean.

The third line is main function where the execution of program starts.

Statement terminator

Preprocessor directive

Main function

Basic Structure of C ++ Program

Using 'cout'

▪The cout object is used to print a message on the screen.

▪The message may consist of strings and values.

A string is a set of characters.

▪The cout object is used with the insertion operator <<.

▪Anything written after the insertion operator is displayed on the

screen.

cout << Message