Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

SJES 2271/ SJEM 2231

9/11/2013

What is programming?

SJEM 2231
Structured Programming
LECTURE NOTES (WEEK 1)
BY
DR NOOR FADIYA MOHD NOOR

 process of designing, writing, testing,


debugging and maintaining the source code
of computer programs
 written in one or more programming
languages
 to create a set of instructions for computers
to perform specific operations
 requires expertise i.e application knowledge,
specialized algorithms and formal logic

What is programming language?

What is syntax?

 designed to communicate instructions to a


computer

 set of rules that defines the combinations of

 to create programms that control a machine


and to express specific algorithms
 mostly describes computation as sequences
of commands
 usually split into two components of syntax
(form) and semantics (meaning)

DR NOOR FADIYA MOHD NOOR, UM

symbols that are considered to be a correctly


structured document or fragment in that
language
 Generally distinguished into three levels:
a) Words the lexical level, determining how
characters form tokens;
b) Phrases the grammar level, narrowly
speaking, determining how tokens form phrases;
c)Context determining what objects or
variables names refer to, if types are valid, etc.

SJES 2271/ SJEM 2231

9/11/2013

What is semantic?

What is C programming?

 mathematical study of the meaning


of programming languages

 developed by Dennis Ritchie

 describes the processes a computer follows


when executing a program in that specific
language
 helps to write compilers, better understand
what a program is doing and to prove the
consequence of a statement

in the early 1970s at Bell Labs


 designed to map efficiently to
typical machine instructions
 development in other
programming languages ie.
Java, JavaScript, Limbo, LPC,
Perl, PHP, Python, Unix's C
Shell and C++

What is C++ programming?

What is a computer program?

 an improved version of C programming


language

 a list of instructions that tells a computer to


do things

 added with object orientation by Bjarne


Stroustrup in 1980s

 need an editor to make changes and saved


into memory

 has large number of operators

 need a compiler to translate instructions into


computer readable form

 has no command to perform input or output


 a compiled language

DR NOOR FADIYA MOHD NOOR, UM

 need to be run to generate result via output


device

SJES 2271/ SJEM 2231

Designing A Program

9/11/2013

C++ Editor/Compiler

1. Define the problem


2. Design the program output

 Instructions in C++ is called as source code

3. Break the problem into logical steps

i.e. Lab1.cpp
 A compiled file has similar name with source
code but with .exe extension i.e. Lab1.exe

4. Write the program


5. Compile the program
6. Test the program

How we generate a C++ program?


1st Stage: Compiling
1. Each source file is compiled individually
2. The compiler generates each intermediate
file known as object file

Starting A C++ Program


1. Open

Microsoft
Visual C++

2nd Stage: Execution


1. The object files are linked together to
generate a C++ program.

DR NOOR FADIYA MOHD NOOR, UM

SJES 2271/ SJEM 2231

9/11/2013

Starting A C++ Program

Starting A C++ Program

2. In the start-

3. Select

up screen
go to File
> New >
Project."

Win32
Console
Application.
4. Name your

project and
save it i.e
trial

Starting A C++ Program

Starting A C++ Program

5. Select

empty
project

DR NOOR FADIYA MOHD NOOR, UM

SJES 2271/ SJEM 2231

Starting A C++ Program

9/11/2013

Starting A C++ Program

6. Open the

workspace

Starting A C++ Program

Starting A C++ Program

7. Add a

8. Save the file

source
code, go to
Project >
Add To
Project >
New

DR NOOR FADIYA MOHD NOOR, UM

as i.e.
Lab1.cpp
and open it

SJES 2271/ SJEM 2231

9/11/2013

Starting A C++ Program

Starting A C++ Program

9. Write a

10. Compile the

simple
program

program.

Starting A C++ Program

Starting A C++ Program

11. Click ! to

And the result


is printed on
the screen

run the
program.
Select Yes
to build the
program

DR NOOR FADIYA MOHD NOOR, UM

SJES 2271/ SJEM 2231

9/11/2013

A Program Structure

A Program Structure

// my first C++ program

comment

// my first C++ program

#include <iostream>
using namespace std;

declaration

int main ()
{ cout << I am a C++ beginner!;
return 0; }

execution

All texts beginning with 2 slash signs // are


considered as comments and would not affect
the program execution.
Comments can be inserted as:
 line comment (//my first C++ program)
 block comment (/* my first C++ program */)

A Program Structure

A Program Structure

#include <iostream>

using namespace std;

All texts beginning with # are directive for the


compiler preprocessor.
In this example it tells the preprocessor to
include a standard input-output library file
iostream so that the command cin and
cout will be valid

To declare all C++ elements within a namespace


called as std

DR NOOR FADIYA MOHD NOOR, UM

SJES 2271/ SJEM 2231

9/11/2013

A Program Structure

A Program Structure

int main ()

{ cout << I am a C++ beginner!;

Corresponds to the beginning of the main


function which serves the body of execution.
The word int means the execution only
involve integer value.
main () is a standard function declaration

{ indicates the starting point of the main


function
cout << I am a C++ beginner!; is a statement
that tells the preprocessor to print the output
I am a C++ beginner!
on the screen.

A Program Structure
return 0; }
This return statement causes the main function
to be ended.
A return code of 0 indicates that the program
is working without errors.
} indicates the ending point of the main
function.

DR NOOR FADIYA MOHD NOOR, UM

You might also like